instruction stringlengths 71 71.9k |
|---|
I have code that take in a URL (via URL or String) and returns the status code. I am new to web development, so it is very possible that I may be taking a poor approach at this. One thing I don't like about my code is the need for the InetSocketAddress to be hardcoded, but I have not been able to find a way around th... |
AllPermutedPacks<Pack<Types...>>::type is to be the pack of packs consisting of all permutations of Types.... For example, AllPermutedPacks<Pack<int, char, double>>::type is to be:
Pack<Pack<int, char, double>, Pack<int, double, char>, Pack<char, int, double>, Pack<char, double, int>, Pack<double, int, char>, Pack<dou... |
I have decided to make small ObjectPool class for internal use. What do you think about it ?
template<class T>
class ObjectPool
{
public:
inline T& getObject();
inline void releaseObject(T& obj);
private:
std::stack<std::reference_wrapper<T>> mFree;
std::vector<T> mPool;
};
template<class T>
void Objec... |
What I'm trying to do is to change the background color when a link is clicked (in this case a list item). When it is no longer clicked, it should revert back to its normal color.
I was able to get this to work via the jQuery addClass and removeClass methods, but this seems to be hardcoding it.
jsFiddle
$(document).rea... |
Does this look good for combining/retrieving two 32 bit integers (a type and an index) into/from an unsigned 64 bit integer (a unique ID)?
The point is to hide in the API the composition of the unique ID and allow its calculation to change later without changing the API (e.g. possibility to change later to consecutive ... |
Below is the problem:
Show that both summation and product are instances of a more general function, called accumulate, with the following signature:
def accumulate(combiner, start, n, term):
"""Return the result of combining the first n terms in a sequence."""
"*** YOUR CODE HERE ***"
Accumulate takes as arg... |
I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ArrayList. The for loops do exactly the same thing except they each use a different list, so I was wondering if there was a way to just use one for loop (or any other way) that does the work but ... |
I have just typed out very long code in Excel that just repeats itself 17 times, but each time with different cell references. Is there a more concise way of writing my code, perhaps by using another column of cells?
The code that is repeated is:
=IF(OR(ISBLANK(X2),ISBLANK(Y2)),0,X2/VLOOKUP(YEAR(Y2),$EU$3:$FH$57,14,FAL... |
I mainly develop in PHP and every now and again I have to do stuff in JavaScript which I'm not really comfortable, so I would like a review of how I can improve my code and knowledge. This script takes data coming from JSON, does some basic checking on the data fro format and things like that and then displays the data... |
Is there any way to improve this kind of code? I have converted this from production code for privacy reasons, so there might be some mistakes.
public class AddNewUserDto
{
public bool IsAdmin { get; set; }
public bool IsRead { get; set; }
public bool IsWrite { get; set; }
public string[] GetRolesByD... |
My special case: home project, automatic downloader for podcasts.
Overall algorithm is:
Download a list of available podcasts
hash the podcasts
load metadata + hash of downloaded podcasts from sqlite db
Algorithm this questions is about - throw out all already downloaded.
Download new podcasts
save metadata to sqlite... |
I am reading the "Clean Code" book and trying refactoring my source code according to the principles "single level of abstraction"/"separation of concerns".
How would you refactor the following code? I am interested in the details like:
How would you separate the abstraction levels?
How many classes would you create?
... |
I have two tables (parent-child model): Loans & Transactions.
Each Loan row has multiple Transaction rows.
I want to select all rows from Loans together with most recent row from Transactions.
Here is my select to achieve this.
SELECT
L.*, T.*
FROM Loans L
CROSS APPLY
(
SELECT TOP 1 * FROM Transactions AS T
... |
I tried to make this clone of
brick_breaker on my own
in one day. The source code and assets .
However I have some concerns about the code so far:
It uses simple edge detection code (as if ball goes out of screen <600 or <462).
It uses built-in collision detection from pygame.
Simple array for appending blocks.
impor... |
I am a beginner in JavaScript and starting to understand jQuery. I've written a toolbar that uses jQuery. I've also put comments based on what I understand of how the code works, though through the help of the book, it helps. But I would really appreciate if someone can review the code as well as the comments, so that ... |
I'm learning C with K&R 2nd Ed. I've just completed the exercise 1-20 and I would know if my code is correct (i.e. answering the question) and if my style is not too bad. Or just some feebacks to improve myself!
K&R Exercise 1-20 p.34
Write a program detab that replaces tabs in the input with the proper number * of b... |
I'm still in the process of learning Python and am doing some of the Project Euler problems.
I have made a factorisation algorithm that works; however, it runs really slowly, and I'm not too well-versed on coding for performance. If someone could give me some pointers on how to improve the algorithm's efficiency it wou... |
While doing a little project involving sniffing packets, I found myself programming a cross platform network to host byte order and host to network byte order, this is my first time developing a project using networking.
ntboc.h
#ifndef NTBOC_H_INCLUDED
#define NTBOC_H_INCLUDED
#define LITTLE_EDIAN 1
#define BIG_ED... |
I'm implementing a live search in a Chrome app (no cross-browser magic required), and have separated the search functionality out into its own module. I want the user to be able to enter multiple search terms by pressing the / key. Eventually I'll style it so it looks like a single text box, but when the user presses t... |
I'm working on a Python application where I read and extract data from an HTML file. The data is stored in a list, and the number of items in a list is, on average, 50,000+.
The items from the list are added to a database. I cannot allow duplicate datetime values in one of the columns, and so, I have to check if a spe... |
Here is the story.
We have the BankTerminalSettings class.
It has many properties:
public class BankTerminalSettings {
public bool IsEnabled { get; set; }
public string IPAddress {get; set;}
public ushort TcpPort {get; set; }
public List<string> Zombies {get; set;}
//and many other properties
}
A... |
I have encountered the following problem that I found very interesting to solve:
Given an array of positive integers {a1, a2, ..., an} you are required
to partition the array into 3 blocks/partitions such that the maximum
of sums of integers in each partition is the minimum it can be.
Restriction: you cannot alt... |
The objective is to remove extra spaces from the below string:
" Today it is going to rain. "
so it looks like below
"Today it is going to rain."
Please determine if the code will perform well and if there is a better solution (NO REGEX or LAMBDA).
static string CompactStringPerfect()
{
strin... |
I've started to write a Generalized Suffix Tree implementation. The overall code is still in an experimental state, though I think it's mature enough to ask for a little review.
I'd like to know how I can make it better, especially on the use of the standard library, the consistency of the code and the design.
A quick ... |
I'm investigating using prototypes in JavaScript to simulate using 'base classes' which can be 'extended'. I've created an example where dialogBox is my 'base' and welcomeMessage is the 'extension'.
// OBJECT CONSTRUCTORS
var dialogBox = function(xPosition, yPosition, width, height){
this.x = xPosition;
this.y... |
I am currently working on a crash log sender. As the application crashes, the FindLogFiles() will search for the different crash logs we are maintaining. It will then process these files, check their size and send them to the server in fused, or split chunks of max 500k bytes (receive limit per file from the server we ... |
How should this code be improved? For instance:
How could it be shorter, clearer, deal with memory better, use a plugin/library, better prepared for web input?
I can break up and clarify the regex or jump calculation, but what is the simplest way?
Why don't I see setTimeout cleared in if blocks more or default return ... |
Everything you need to do OOP in one neat little package without having to do all the work by hand. Almost like C++.
Here is how you would use it:
var A = Object.extend("A",
{"static" :
{"counter_start" : 5 // all static propertiers and methods should
// be initialized
... |
This challenge took me awhile to figure out, and it's characterized as "easy," so I'm sorta wondering what I missed.
Problem Statement
You are given a list of N people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-pers... |
I have created a Tetris AI which can play Tetris on its own given a set of rules. It places the next piece in every possible way on the board, and calculates which position that gives the fewest "holes" on the playfield.
The playfield is represented by an int[] array, where every bit represents a position in a row, an... |
I'm learning Angular and I don't like my current approach. The current controller uses first Geolocation service and when getLocation() is resolved, then the Pagination service is invoked with the location param. Is it any better solution to provide one service that query server with location? Can I integrate the Pagin... |
The code contains an AI function, that searches breadth-first all possible moves and get the score of their grids, a depth of 6 is used which makes at most \$4+4^2+...+4^6\$ computed grids. The highest scores (and their associated moves) are kept for each level of depth, the most redundant one is chosen.
This function ... |
I recently have been working on a project to simulate segmentation in memory. I wanted to create everything from scratch; not use pre-built data structures.
I create a memory object that allows for "segment" nodes and "hole" nodes.
A segment is: Any location in the memory object that is occupied by data.
A hole is: Any... |
I have the following functions:
function getExample($id, $otherid) {
global $db;
$query = 'SELECT * FROM examples WHERE id = :id AND otherid= :otherid';
try {
$statement = $db->prepare($query);
$statement->bindValue(':id', $id);
$stat... |
Use case: We have a simple two tables plus a link table setup using some modern RDBMS.
For example:
Hospital table (id, name, ...)
Physician table (id, name, ...)
Visiting_Privilege table (hospital_id, physician_id, ...)
Our goal is to find records that are "missing" (absent) from the link table.
Using our example: L... |
I have written a SQL query against the Stack Exchange Data Explorer that identifies answered questions with a positive score for which all the answers have a negative score (this was an answer to this Meta Stack Exchange post, though the code in that post is different from what I've posted below).
It's a fairly straig... |
I wrote up a quick API to help me save time while writing applications that require either a delay or frame rate. It should require me to implement a void run() method, which may or may not be annotated with the @Loop I created. If it doesn't contain the annotation, it will simply call the run() method once. If it is a... |
I have here a class which represents a directed acyclic graph (Graph) and a vertex in the graph (Vertex). The vertices are stored in an adjacency list. It has the ability to find a vertex's indegree, and to find a topological sort order. The graph does not own the vertices.
I'm particularly interested in comments regar... |
I'm using JQVMap, and I have my code to where depending on what state you click, it'll reveal info about that state within a single div below the map. However, I feel there's a simplified, more efficient way to set up this code so there's not a lot of repeat, especially once I start adding more states. Is there?
switch... |
This is the first coding class I've taken and I'm not getting much feedback from the instructor. The function of this program is to take two roman numeral inputs, convert them to arabic, add them together, then convert the sum to roman numerals. I wanted to see if any of you code ninjas could give me some feedback on t... |
Here's Problem 5 - Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
How can I improve this code? How to make it faster? Is there a better/faste... |
Please check if this date filtering function is inefficient code. It seems so to me, but I can't figure out the other way around it.
function makeTime () {
/////////////////////////////////
//Create a filtered Time/////////
var timesStamp = new Date();
var time = timesStamp.toLocaleTimeString();
var... |
I have a function to handle image uploads. Originally, it contained a goto:
restartA:
$name = $this->random_name() . $ext;
if(file_exists($this->img_path . $name)){
unset($name);
goto restartA;
}
It seems pretty clear to me what the code does, and I think anyone who reads it would immediately understand what... |
I've just started delving into JavaFX, and the following is essentially my "Hello World". Although it's simple, I question the code formatting and wonder if I'm breaking any conventions, especially if explicitly concerning the library.
I also find myself concerned with what best promotes readability. Unfamiliarity brou... |
I have an app that user submit the log in form , when it sent the data to server app create a connection for its account.
In this connection i have an integer field named as state.
the state value is : 1 for connecting, 2 for connected and 0 for failed.
I show a dialog to user display Connecting ... and then check the... |
I am currently writing a TcpListener class where it begins a new socket and adds a new Session. I have classes called Session and SessionManager.
Session is where I establish a new SESSION, a new instance of the class. I have a new session for each player entering and connecting to a socket
SessionManager is where I ke... |
Control like if..else and while
If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the \$n\$th repeated application of \$f\$, which is defined to be the function whose value at \$x\$ is \$f(f(...(f(x))...))\$. For example, if \$f\$ adds 1 to its argument, then the \$n\$th repeated appli... |
Having contributed to this Community Wiki on StackOverflow regarding validating user input, I thought I'd finally sit down and write something more robust to do these kinds of tasks. I wanted something that would allow detailed configuration of the acceptable inputs, but without a huge list of arguments or spaghetti of... |
My code is for a 10-faced dice-rolling game. There are 2 players who start off with 50 points, then they both roll a dice and get a random score between 1-10. The player with the highest roll gets the difference between the rolls deducted from their score (50 points), but the loser gets the difference between the rolls... |
I have made this small text-based RPG in C++ which is based around one quest. I did this to practice what I have learnt so far. How could I improve it? Be as picky as you'd like.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void riverstead();
void aragornHouse();
void stage1();
void ... |
The purpose of this code is to track player development on a Multi-User Dungeon I play. It allows saving multiple characters to the same database. It allows for updates on level, hour, tier, morts, months, years, weeks, and days.
Are there any improvements that could be made? Assume that any "missing" functions are fun... |
what could I do to make this code more beautiful?
exports.index = function (req, res, next) {
Booking.aggregate(
[{
'$group': {
'_id': '$booking.date',
'name': {
'$first': '$booking.name'
},
'participants': {
... |
I am trying to implement a Trie class in Java which just supports insertion and searching operation up until now. I think it works perfectly on the several examples I have tried but I am not able to come up with a tricky test case to check if it functions perfectly or not. Can you take a look at my implementation and s... |
I am writing an encryption program that will encrypt the message "STOP POLLUTION" with the encryption function f(p) = (3p + 7) mod 26 where p is given letter.
Here is my code for doing so (tested it works):
static final int SPACE = -33;
static int[] convert(String s) {
char[] array = s.toCharArray();
... |
I wrote a RomanNumeral class in C#. Please pull it to pieces:
class RomanNumeral
{
public RomanNumeral(string num)
{
AsRoman = num;
AsArabic = RomanNumeralToArabic(num);
if (AsArabic == -1)
{
throw new ArgumentException();
}
}
public RomanNumeral(in... |
Is this correct MYSQLI implementation?
IS it safe from injection?
IS the object cleanup done properly?
<?php
include_once '../../securelogin/db_connect.php';
include_once '../../securelogin/functions.php';
sec_session_start();
if (login_check($mysqli) == true)
{
$con = new mysqli("localhost", "username", "passwo... |
I recently started learning Java for a class and my teacher gave us an assignment in which we had to write up code which would print out the Pascal's triangle to an amount of rows decided by the user, and use recursion to do so. I believe that I'm done with the assignment, but wanted to know, for myself, as to how I co... |
I haven't done anything similar so I got nothing to go on. The point was to load everything from the file and I thought a struct would be a good choice to be the handler to store the information.
The loading part is, however, not really something that is to my satisfaction as I find it very primitive and illusive. I tr... |
I wrote this function that recursively traverses a given directory resolves
the relative file-names to absolute file-names and yields the resolved file-name if it matches a given pattern. You can specify a callback function as well.
The first issue I have with this function is that it is a bit hard to comprehend, I thi... |
I have a vote and a comment table. Now I want to display all comments and order them by votes-sum. Sum because some votes can have a higher value than others.
Therefore I want to display if the user has voted already on a comment. So I need to get that value too.
This is my actual query:
SELECT *, SUM(v.`value`) as vot... |
I'm wondering what can be done to optimize the following. I've tried to note the points at which most of the overhead is occurring. The main two points I see are
The call to DiffDays from within the LINQ query.
The ordering by DateTime LastOnline before putting results in memory.
Right now, with only 2000 rows, I'... |
With the ANTLR-powered parser, I was able to reimplement all code inspections from the last release build, and the rest of the inspections on the road map are now implementable.
Code inspections and quick-fixes are nice, but we want our Rubberduck even smarter than that. So I wrote one of the coolest things I've ever ... |
I need to parse the following input string into a hash table with the following format:
Input:
'1001=23;1001B=5;1002=0;1003=5;'
Output:
=> {'1001'=>23,'1001B'=>5,'1002'=>0,'1003'=>5}
My solution:
def parser input
output = {}
input.split(';').map {|ar| ar.split('=')}.each {|id, c| output[id]=c.to_i}
output
end
p... |
I need to create a database which stores details products, Manufactures,Suppliers. So initially I divided Products into categories and subcategories.
These are the tables I created.
Manufacturer, Category, Sub_Category, Products,
ProductSpecs, ProductAvailability, Supplier
Manufacturer table contains Brand Details (... |
def line_to(x: 0, y: 0, rect: nil)
unless rect.nil?
x, y, width, height = rect.x, rect.y, rect.width, rect.height
end
`#{@context}.lineTo(#{x}, #{y})`
end
def fill_rect(x: 0, y: 0, width: 0, height: 0, rect: nil)
unless rect.nil?
x, y, width, height = rect.x, rect.y, rect.width, rect.height
end
`... |
I want to find the lowest hop count from source to destination.
The challenge, in summary:
The first line contains the number of test cases T, 1 ≤ T ≤ 100000.
The next T lines each contains three integers A, B, and M. 1 ≤ A ≤ B ≤ 1012. 1 ≤ M ≤ 1012.
For each test case, print the number of multiples of M that are i... |
I've got an Excel file from which I have to read out data to an object to serialize. So far I came up with this solution, and I'm curious if there are any clearer solutions.
public myClassFromXsd excelToMyClassFromXsd(String excelFile)
{
Excel.Application excelApp = new Excel.Application(); ... |
I've decided to learn some more Haskell writing a Sudoku validator, the function checkSudoku outputs True if the Sudoku is valid and False if it is not. I did not write the checkSquares function because it would have been too hard. I am looking for any tip about Haskell and functional programming.
Some specific questi... |
Take a look at the following function:
std::vector<double> get_data(
std::vector<double> const &data,
double const t,
double const x)
{
std::vector<double> result(data.size(), 0.0);
double const
A = func(t, x),
B = func2(t, x);
std::transform(std::begin(data) + 1, std::end(data... |
I'm wondering how this code could be improved. I especially don't like the use of mutable Buffer but not sure what the best way to get it out cleanly.
def find(service: Service): Traversable[Long] = {
def loop(lastId: Option[Long])
(acc: mutable.Buffer[Long])
(quota: Int): Traversable[... |
I'm currently developing a new version of ExpressGenGen Using TDD. While I'm rewriting the new version of my Code Generator Generator.
I'm using its old version to generate code to be used by the new version.
This is how I'm creating new classes: when a new class is created,
it will generate a .cpp and .h file and the... |
I'm busy rewriting some from my spaghetti code into OOP classes. I'm still learning OOP and very new to the concept. From help from this answer from @EliasVanOotegemto on a previous question I've asked I have written the following class which sets up conditionals according to 4 values passed to it by a user and checkin... |
I'm currently enjoying this exercise I'm working on for fun: I wish to write optimized code for the searching of particular strings per line in a (very large) file, counting how many exist, and producing a text file with a count of said strings.
The data format is actually very consistent, so when I do my indexof() o... |
Challenge:
Print set intersections.
Specifications:
Your program should accept as its first argument a path to a filename.
Each line in the file is a test case.
Each test case contain two semicolon delimited sorted lists of numbers in ascending order, whose numbers are separated by a comma.
Print out the ascen... |
After a few pages reading Learning Python Hard Way, I've decided to try to make a simple cm-to-inch calculator. I am very excited about this achievement, and I want someone to check my code. It works well, but i just need someone to confirm everything is written well.
# cm to inch calculator
inch = 2.54 #centimeters
c... |
This is my first test at making a key event dispatcher. Some of the code is unnecessary if one is interested in separating lower and upper cases, however I want to treat them as the same. Hence my wonderfully named method keyToLowerCaseIfUpperCase(char c). I also want to lock the key if it has been pressed untill it is... |
I've started a little challenge on a website, and the first one was about counting different DNA letters. I've done it, but I found my method very brutal. I have a little experience, and I know that hard-coded information is not good. Any way to improve this code?
chaine = "AAAACCCGGT"
nA = 0
nT = 0
nG = 0
nC = 0
for... |
This produces recursive directory listings(it's intended to do other things, so there will be something else instead of echo, but it isn't important), yet it isn't very intuitive. How can I improve it?
#! /bin/bash
deploy ()
{
for file in $(ls $1); do
if [ ! -d "$2$file" ]; then
echo ${2}${file}... |
I'm not sure if anyone else has ever heard of Factman, or even where the name comes from, but my AP Computer Science teacher calls this project Factman, so that's what I'm going with.
Naming aside, the game is simple. Players take turns choosing from a list of numbers. They get the number added to their score, but th... |
One of the inspections we wanted to implement in Rubberduck for the next release, is one that finds all unassigned variables in a VBA project.
Implementing this inspection has been ...complicated (it's the most complex inspection in the Rubberduck code base so far). Here's the code:
public class VariableNotAssignedIns... |
I want to amalgamate these two functions into one, Any ideas?
function toggleVisibility() {
document.getElementById('regStart').style.visibility = 'hidden';
document.getElementById('regPage').style.visibility = 'visible';
document.getElementById('facebook').src = "/images/js project/Faceboo... |
This is a sequel to my previous question: Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R
I am trying to implement the Sieve of Sundaram in various languages to solve Project Euler Problem #7.
I have written a solution in Haskell (to which I am still very new, but eager to learn) base... |
For my second project in CS2, I was given the following assignment:
Implement a new ADT called a bag with receipts.
The specification for the class of bag with receipts differs from a
typical bag in the text in the following ways:
The add() operation will return a unique integer receipt for each object inserted ... |
What could I improve in the following code? The goal is to test a function againts a table of input parameters and compare to some expected results with some tolerance (as there are random variables involved in the computations).
This is how I am doing it right now. Note that I cannot use any C++11 features.
void test(... |
I'm building an application that implements the A* algorithm to calculate a route between two rooms. I am trying to create a graph which the algorithm can operate on and I am not sure if this is the right way to do it.
Here's what I've done so far:
Vect2.java:
package myalgorithm;
public class Vect2 {
private int... |
Given a Dialogue Script for SDT (NSFW! Google at own risk), parse said dialogue script for validation with checkers. A dialogue script consists of a set of lines.
There's a special line, initial_settings, formatted like such:
initial_settings:{"variable1":numericvalue,"variable2":"stringvalue"}
The rest of the lines f... |
I have a model with a hierarchical structure like this:
Batch (root)
Groups (List of groups owned by the Batch)
Groupnames (Nameing of the Group in different Languages)
Tags (List of Tags owned by the Group)
Tagnames (Nameing of the Tag in different Languages)
Logs (List of L... |
I'm attempting to create a replacement shell for /bin/bash, that only permits commands defined by a read only config file. These commands will be run by absolute paths, and take no arguments. I'm not an experienced C programmer, so I kindly ask for your comments and feedback. I'm especially concerned with buffer overfl... |
In general, in Prestashop there are no functions to really have the final category (i.e. the one with highest level_depth) of a product based on id_product, so I extended the Product class and added this simple static method:
public static function get_product_category($id_product, $id_lang = null){
$lang = (!isset... |
I have only been coding C# for a short time and I can't say I'm an expert but I am rather enjoying it. I wondered if you could see any way I could improve my code.
using System;
using System.Net;
using System.Net.Sockets;
namespace Reality.Network
{
/// <summary>
/// Callback to be invoked upon accepting a new... |
I have this very simple method:
private boolean isTheParticipantTalking(ParticipantID participantId){
if(mCurrentParticipant != null) {
return participantId.equals(mCurrentParticipant.getId());
}
return false; // no one is talking
}
I receive a warning stating that I can simplify the code in the fo... |
This program takes an arbitrary array of strings and group anagrams into arrays and return them in a array. Any string without any anagrams is still put in an array.
This code works perfectly and I would appreciate any comments on making this more efficient in terms of computation time.
import java.util.Arrays;
import ... |
This one is, or rather, should be, fairly simple. I have a list of tuples of XY positions, and am trying to pull out angles relative to the origin from it. However, unlike atan2 / friends, I want it to be continuous, in other words not wrapping. I know (and am assuming) that the differences between successive XY coordi... |
Can someone review my timer class that runs some code every second, please? The void it's calling (runCode) is just a void with some code in it.
using Reality.Game.Sessions;
using System;
using System.Threading;
namespace Reality.Game.Misc
{
public static class UserTimer
{
public static void Initialize... |
I am trying to get familiar with OOP JavaScript, in particular working with the prototype pattern and would love some pointers/suggestions on how to improve my code.
I think I have understood the basics well, and have been able create class instances successfully.
I am however, a little unsure on how to work with event... |
Does this make sense? How would you achieve the same thing, with cleaner code?
function retrieveBatch(offset){
var opts = {}
opts.limit = 100
if(offset) opts.offset = offset
return new Promise(function(resolve, reject) {
chargebee.subscription
.list(opts)
.request(function(err, value){
if(err)... |
I have a private function in PHP that takes a given URL string and just leave the Alpha or numeric and certain punctuation left. I need the stripping of string due to having it match against ElasticSearch and ElasticSearch doesn't take it too kindly for special characters when it comes to exact match.
The following fun... |
I have a simple web page where the user enters the name and rank of a soldier and hits submit. If the input is invalid, an appropriate error message gets displayed. Otherwise, it adds the soldier to a database and adds it to a list of current Soldiers via AJAX request.
//Find elements on page
var rankField = $("input[n... |
I am learning C++ and SFML so I want to know if I am laying my code out neatly and if my code is efficient. I know this is not a full game yet but I want to know if I am on the right tracks.
#include <SFML/Graphics.hpp>
#include "ResourcePath.hpp"
#include <iostream>
class Paddel {
int speed = 3;
sf::Vector2f... |
I am writing this smart pointer as a learning exercise. Any feedback would be most appreciated.
Any flaws? Have I missed any test cases?
smart_pointer.hpp:
#ifndef SMARTPOINTER_HPP_
#define SMARTPOINTER_HPP_
#include <iostream>
template<typename T>
class sp {
public:
sp(T* ptr) : ptr_(ptr), ref_cnt_(new unsigned(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.