instruction
stringlengths
71
71.9k
I have a observer pattern implemented and I'm using two base classes called Subject and Observer. - The Subject class is an abstract class that has methods to insert the observers. And the Observer is just an interface. What I want is to provide a safer interface to classes that inherit to access the vector of observer...
I have this function that I hope to be a good alternative to the recursive (thus performance expensive) approach. #define _free_all(node, yes_no) \ do { \ Tree *__i; for (__i = node; __i; __i = __i->yes_no); \ free(; node != __i; __i = __i->parent) { \ free(__i->value); \ ...
I created a function to do that, and I want to know if there is a problem I'm overlooking about it .. void replaceStr(buffer, haystack, needle, rep) char *buffer, *needle, *rep; const char *haystack; { if (!buffer || !haystack || !needle || !rep) return; size_t rep_length = strlen(rep); lon...
What I can do to make this code more efficient? It is supposed to be like one of those slot machines where you gamble on it and stuff (like at a casino). #include <iostream> #include <conio.h> #include <string> #include <ctime> #include <iomanip> using namespace std; int main() { srand(time(0)); int slo...
I coded a JApplet game that allows the user to play a game that displays a sequence of 4 numbers that must then be input into a JTextField and if correct, displays a new sequence with one extra number, and continues on until the sequence is gotten wrong. It also allows the user to choose from one of 4 difficulty levels...
This was largely an exercise in making my code more Pythonic, especially in catching errors and doing things the right way. I opted to make the PageNotFound exception part of the class so that users could simply from ratebeer import RateBeer and not have to worry about anything else. If you prefer, the code is on Gith...
I want every piece of feedback that is possible as I am new to Java. I've coded some C# before but not much. I want to be sure that I am following the guidelines of how to write and name Java programs. Hit me as hard as you can. I wrote this code for testing other functions I am writing, to track what is going on and w...
I wrote a Chrome browser extension to hide Top Content posts from Quora, which bother users following too few topics. A user's feed in Quora.com starts as a list of posts relevant to the user, including a set of "Top Content" posts. As the user scrolls down the page, it loads more posts for them to view. My extension...
I have a small piece of code, and the problem is that I don't know how to organize it. There are tons of tutorials about JS code organization but I feel that those are for large scale apps. Also, I'm not sure if having the setInterval function where it is now is a big no no, can you come up with some critique/ideas? YU...
I'm working on a light, custom CMS for my site and I am trying to use Ajax calls for most of the server-side interaction. I am still pretty new to web development, so if I am breaking any conventions please let me know. I'm building it within Codeigniter (PHP framework). Right now I have all of my Ajax functions in one...
I wrote a simple program using int[] and ArrayList<Integer> which aims to get a random permutation output between 1 to 10, where each number will not be repeated in each line of output (each line of output will have number 1 until 10 in a different order). Both classes work nicely with the desire output. Is there any o...
I am still learning Laravel and I am in the process of creating a small shopping website. On the left hand side there are a series of filters that appear depending on what products have come back from the search, to allow the user to filter their search further. For example, if none of the products searched for return ...
Based on my initial implementation found here and the suggested improvements in answers and comments, I've refactored the code. The main changes are: Removed redundant buffering. Simplified constructors by implementing a CsvWriterSettings class. Refactored CsvWriter<T>.WriteLine(T value) to make it more readable with ...
I've got this method and I realize that an instance of HttpClass is going to be created for each call to it. While working seemingly OK, I'm considering moving it out and placing it as a private property accessible to each call to the method. There might be other methods making use of it in the future as well. I have n...
Please have a through look my custom implementation of generic repository pattern and suggest anything I may be lacking. I am using a generic interface with 6 methods I'll be using a repository class for each entity type (e.g UserRepository, ProductRepository, StoreRepository) which are not only going to implement the...
I am trying to learn some generic programming with Java: import java.util.ArrayList; import java.util.HashSet; import java.util.Set; /** * Created by PACKAGE_NAME on 15/11/14. */ public class PrintMatrix { public static <T> void printma(ArrayList<ArrayList<T>> matrix) { ArrayList<Integer> sizes = new Arr...
Here's a Python implementation of the Sieve of Eratosthenes: def return_primes(upto=100): primes = [] sieve = set() for i in range(2, upto+1): if i not in sieve: primes.append(i) sieve.update(range(i, upto+1, i)) return primes I use the above function in the below algori...
from bs4 import BeautifulSoup import csv import re import sys import os import urllib2 import html5lib from numpy import genfromtxt import time tropelist = [] numoftropes = 0 start = time.time() #compare the tropelist to the master tropelist and return a 1 dimensional binary array def binarizer(tropelist): master...
I have a function that produce an array with values that are Gaussian (normal) distribution. If you plot the values on a graph, it would look something like this: Is there any way to improve on the code? private static IComparable[] NonUniformDistributionsGaussian(int startNumber,int arraySize) { IComparab...
Another exercise of Java generics: import java.util.Collection; /** * Created by IDEA on 16/11/14. */ public class Size { public static <T, I extends Iterable<T>> int size(I data) { final int size; if (data instanceof Collection) { size = ((Collection<T>) data).size(); } else ...
Version 2 of A Java class for calculating size of iterable/array import java.util.Collection; /** * Created by IDEA on 16/11/14. */ public class Size { public static int size(Iterable<?> data) { if (data instanceof Collection) { return ((Collection<?>) data).size(); } int coun...
My multithreaded version of code works slowly than singlethreaded. Can you help me to understand why? #include <iostream> #include <vector> #include <getopt.h> #include <stdlib.h> #include <cmath> #include <pthread.h> #include <unistd.h> #include <time.h> std::vector<std::vector<double> > phi, I; std::vector<int> cond...
A dosage file (used in computational genetics) is formatted like this: // ID TAG geno1 geno2 geno3 ... 1->76016 DOSE 1.871 1.832 1.897 1.995 1.884 1.856 1.405 1.853 1.998 1.885 1.390 1.971 1.890 1.699 2->76018 DOSE 1.877 1.832 1.897 1.995 1.884 1.856 1.405 1.853 1.998 1.885 1.390 1.971 1.890 1.699 3->76063 DOSE 1....
I was wondering if someone could point me in the right direction for cleaning up this code. WordPress uses shortcodes in the form [shortcode] to add extended functionality to posts and pages. What I am trying to do is to return a string with all of the 'stray' brackets, ones not being used by any of shortcodes, as htm...
The goal is to find \$f(n,r)\mod(m)\$ for the given values of \$n\$, \$r\$, \$m\$, where \$m\$ is a prime number. $$f(n,r) = \dfrac{F(n)}{F(n-r) \cdot F(r)}$$ where $$F(n) = 1^1 \cdot 2^2 \cdot 3^3 \cdot \ldots \cdot n^n$$ Here is the Python code snippet I've written: n_r = n - r num = 1 den = 1 if ...
This code is from my Kohana project. How can I make it more beautiful? Should I use try-catch instead? How could I avoid writing exit() twice? public function action_index() { $id = $this->request->query('id'); if (!empty($id)) { $ticket = ORM::factory('ticket') ->where('id', '=', $id) ...
After my first exercise here is another. Again, this is exactly that: Exercise, which means that the output doesn't necessarily need to be beautifully formatted, etc. I probably have some variable naming issues around and also more general issues. # coding=utf-8 """Basic usage: $ python xggt.py 3343 77 (1, -12, 521) 6...
Problem statement: Design a system for the following scenario: An item list contains item code, name, rate, and quantity for several items. Whenever a new item is added in the list uniqueness of item code is to be checked. Register a new product with its price. Time to time rate of the items may change. Whenever an i...
This is my RubyWarrior solution. I think RubyWarrior is well known to Ruby coders. I am starting to learn Ruby and I would appreciate some help from you to improve the organization or the mistakes that I could have. I don't need another example as the Internet is full of them, but what I need is some advice that I can...
Please review my code for 'JWT' authentication. Are there any security issues? Where should I store the secret's key, DB or InMemory? What's a good 'JWT' Lifetime? Should I send the 'JWT' in Header for every request? What should be done when a 'JWT' Expires? Token Manager using System; using System.Security.Cryptogra...
A practice interview question: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. void SetZeroOnMatrix(int **matrix, int M, int N) { bool *rowZeros = new bool[M]; bool *colZeros = new bool[N]; // Find the 0's for(int i=0; i<M; i++) { f...
I have a safe with a manual combination lock that I periodically change the combination to. I like to use a combination that's easy for me to remember, so I thought I'd write a quick Clojure program to make it easier to pick a new combination. Note: When I say "combination" in this write-up it means the numbers used to...
I'm using the function countLikes() to fetch URLs' Likes count from the Facebook API. // Link.php class Link { private $url; public function __construct($url){ $this->url = new Url($url); } public function getUrl(){ return $this->url(); } public function countLikes() { global $config; $call = $con...
I'm getting more and more into programming js in a functional manner which makes heavy use of multiple returns via tuples (especially useful with recursion). Also, a pattern that I use often is creating simple temporary values for projections _.chain(arr) .filter(...) .map(function(x){ return [x.foo, get...
I'm a JavaScript rookie, but I wrote a JavaScript function as part of a Chrome extension that will activate the tab to the left of the currently active tab. The function is pretty ugly, but I couldn't figure out another way to write it. The logic is pretty simple, but I ran into problems setting variables throughout th...
Is this a good way to get all sublists of a sequence/list that have a given length? An inefficient way to do it would be something like f n = (filter (\x -> (length x) > n)) . (take n) . tails This just takes the n first elements of each tail of the original list. I think it should be slow because of the length check ...
I wrote this Python script to rename specified files to "titlecase", for example: hello.txt to Hello.txt hello there.txt to Hello There.txt path/to/file.txt to path/to/File.txt The main script: #!/usr/bin/env python import os import re import argparse re_junk = re.compile(r'[._-]') re_spaces = re.compile(r'\s\s+') ...
I have simple hierarchy which looks [a little bit] like the Optional<?> from Guava: public abstract class Result<T> { public static <ResultType> Result<ResultType> get(ResultType result) { return new PresentResult(result); } public static Result<?> absent(Throwable exception) { return new ...
Version 2 of A Java class for reading MaCH dosage files import java.io.*; import java.util.ArrayList; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; /** * Created by vu.co.kaiyin.ReadMachDosage on 15/11/14. */ public class Dosage { final String filename; final Pattern splitPattern; ...
I have been solving the following problem: Given n numbers find out the least k numbers from them. For example, if there are 8 numbers like 5,6,3,4,7,8,9,-1. For k = 3 the result will be -1,3,4. I implemented it in the following way: make heap with first k numbers traverse the rest k-n numbers if heapMax > any of t...
I created this basic content management system to teach object oriented PHP to beginners. However, I am concerned that it violates SOLID principles in App.php and Router.php. Here's the project on GitHub App.php: <?php /** * The class that starts our application. * * Works as dependency injector. * TODO Have to che...
I have some framework in PHP/MySQL for developing web services. Finally my code works on two servers - production and developer. My idea is to create one code without differences, which will work different on both servers, depend of config. I created table [ini], with two rows of data, where I can specifically change s...
I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step. public static IEnumerable<double> InclusiveRange(double start, double end, double step = 1) { while (start <= end) { yield return start...
Looking at this Typeclassopedia exercise, I typed out foldTree on the following type: data ITree a = Leaf (Int -> a) | Node [ITree a] And my implementation of Functor: instance Functor (ITree) where fmap = iTreeMap iTreeMap :: (a -> b) -> ITree a -> ITree b iTreeMap f (Leaf x) = Leaf $ fmap f x iTreeMap f (No...
I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API requests. I want to test that this works properly by checking the headers in my mock requests to GitHub's API. I'm using HTTPretty to mock HTTP requests. GitHub def test_authentication...
Code: import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * Created by IDEA on 16/11/14. */ public class TestStream { private final static Pattern pa...
I was wondering if anyone could provide some feedback on my solution to Conway's game of life. I tried to solve it without using objects. It returns a dictionary of living points on a grid and points that were alive at some point. I'm wondering if there is a better way to check the surrounding points or if storing the ...
How idiomatic is my code? var Clock = function(hour, minute) { this.hour = hour || 0; this.minute = minute || 0; this.plus = function(minutes) { computed_minutes = this.minute + minutes if (computed_minutes > 60) { this.minute = computed_minutes % 60 this.hour += computed_minutes / 60 } ...
I stumbled upon a question on SO asking how to split a comma-separated string into individual values. Since it's been a while since I've had any good reason to write C I'd like to ask for some feedback. #include <stdio.h> #include <string.h> int main (int argc, const char * argv[]) { const char str[] ="coma sepa...
Part 1 is here. I wrote a Java implementation of the Karp-Rabin semi-numerical string matching algorithm. I incorporated the suggestions of @fge and @maaartinus from the other question into my new code: the match method now returns a boolean so you can write if (KarpRabin.match(pattern, text)), and I changed the underl...
I have some code to translate some color names, and this is what I did, quick and dirty. But I'm guessing there might be some function to replace arrays with arrays maybe, like in PHP, where you can have str_replace($array_of_colors, $replace_array_of_colors, $colors);. var color = colors[c].replace(/sort/i, "Black"); ...
I have click event handlers for two buttons. The code is working well, but I want to apply the DRY principle. How should I rewrite the following code in the button_click event handler so that I don't have to repeat in all my 10 buttons? private void CreateWindows(UserControl ux, Form rpt, object sender, ItemClickEventA...
The following code reads a .txt file that contain only numbers. Read the first one, create a dynamic array and put the other numbers on it, made some procedures and in the end write a file with the int total. I want to know if there is a way to run the code faster (the maximum procedure time should be 1s) if I had a .t...
This is how I include a page depending by name. Example URL: http://www.page.com/index.php?page=admin where admin.inc.php lays inside /modules/ directory. The files are located in a directory I specified. The included files should not render when connected to them directly. Are there ANY issues with the code? Are ...
I have written code for a binary index tree. My problem is that there are many functions based on the binary index tree the function stores the sum of element within a given range of binary index tree. My task is to compute the sum of all the functions with provide range. This example will clarify: My array elements: A...
This class reads a delimited text file into String arrays on demand. Delimiter can be any regex. Features include: Read a single column Read a range of columns Read arbitrary columns by providing an array of indices, e.g. for columns 1, 3, 5, use new int[]{1, 3, 5} import java.io.IOException; import java.nio.charset...
I am decoding GS1 barcodes and need to match up application identifiers with relevant data about them. 00 SSCC (Serial Shipping Container Code) N2+N18 FALSE SSCC 01 Global Trade Item Number (GTIN) N2+N14 FALSE GTIN 02 GTIN of Contained Trade Items N2+N14 FALSE CONTENT 10 Bat...
This question is the follow up of the question: UIntArray class in PHP @Brythan provided a really nice review and I have improved my class. I have addressed almost all the issues he pointed out (the only one I didn't do anything was about the UIntArray::pop() function, that was intentional) and still made some improvem...
I'm quite happy with my code so far but I often make efficiency errors that I don't see when writing code. Have I missed anything? #include <stdio.h> #include <unistd.h> int main () { char end = 'N'; int credit = 5, bet = 0, userInput = 0, cont = 0, victory; do{ while (cont == 0){ // Introduction of credit sys...
As a Rags-to-Riches re-implementation of the Karp-Rabin question here, from @tsleyson, I thought it would be interesting to understand the algorithm better, and to use bitwise-shifting instead of prime multiplication, to compute the rolling hash. Karp-Rabin is a text-search algorithm that computes a rolling hash of the...
I have a webpage that shows shorthand code on the left, and its long form on the right. When you hover over code on the left (signified with a space-separated array in the data-from attribute), it uses jQuery to highlight corresponding code on the right (signified with a space-separated array in the data-to attribute),...
I'm just curious is there an easier way to handle console colors rather than just doing something like the code below. The problem is the code bloat I'm experiencing when writing a theming system for my console application. It contains almost 200 lines of code, just to handle the chat theme system. Is there a way to m...
I'm developing a room booking system using PHP for a school project. I'm trying to create a variable name by concatenating values from two arrays together. here are the two arrays: $day = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri'); $B = array('P1B', 'P2B', 'P3B', 'P4B', 'P5B', 'P6B'); and then here is the code I'm curr...
I wrote a program that copies a directory from a source to a destination, similar to the cp utility. For this, I used the essential functions: open(), write(), mkdir(), readdir(). This is the source code (ignore the main() function, this is not the final form): #include <dirent.h> #include <errno.h> #include <stdio.h>...
I have a multidimensional array with associative values... I want to add some information to multiple arrays at the same time. Doing $array1=$array2=array(... seems to work but I'm worried that it's too easy. Will any array get extra data or have data overwritten by doing this? What kind of unexpected behavior might I ...
I am just trying to apply a "mean filter" with C#. The working code below gets window size (3,5,7,9,...) from textBoxWinSize and applies the mean filter. I am new and I want your comments and suggestions about my code so I can improve myself. Can I make it faster? How? Is there any unnecessary or absurd part in the cod...
I'm trying to calculate a problem which requires sum of digits in \$a^b\$, where \$0 \le a \le 9\$ and \$0 \le b \le 4000\$. I have seen various other posts similar to this, but I haven't acquired best way. I have created this: #include<stdio.h> int main() { int digits[4000]={0} ; long long int test,a,b,temp,ne...
consecutive_find() is a function that returns the beginning of a range that contains strictly N consecutive elements. It was part of a SO question that I answered. Currently this function runs in \$O(n)\$ time. I wanted to know if there are any pitfalls with this function and if it can be improved at all. For example, ...
My problem is quite similar to the question found here, except I am attempting to answer the question in Python. Given an array of N counters, all initialized to 0, and an array A representing a series of operations, find the final state of the counters. Each entry in A should be interpreted as follows: If 1 ≤ A[k...
def draw_dashed_line(surf, color, start_pos, end_pos, width=1, dash_length=10): x1, y1 = start_pos x2, y2 = end_pos dl = dash_length if (x1 == x2): ycoords = [y for y in range(y1, y2, dl if y1 < y2 else -dl)] xcoords = [x1] * len(ycoords) elif (y1 == y2): xcoords = [x for x ...
Here is my code which tests whether a given string has unique characters. The function is_unique which does a linear search for each character in the string is \$O(n^2)\$ (if I am right). Is there any more efficient way of doing the same with more efficient DS that takes less time (or space)? I know with some library f...
After the tips from my previous review. I have come up with these changes: Separation of Concerns Use Delegates I'm asking you guys if this looks good. Other then separate out the FileButton_Click(), WriteResultsToFile(), and PromtSaveAsFileName() functions to another class would you recommend any other things to imp...
I have an abstract Connection class which looks like this: abstract class Connection { /** * @var mixed $instance Represents the instance of the connection */ protected $instance = null; /** * @return mixed */ public function getInstance() { if (!$this->isInitialized()) { ...
I want my method to use a finally block so I can be ure that my EF entity is disposed after usage, even if an exception is thrown, but I would also like to not handle exceptions in that method. The current code works but is it possible to omit the catch{} block? Would an exception from the try{} block be re-thrown or ...
I think there is more that is needed here. Can someone please comment on it? What I need is to add some common functions to check if an element exists. // Common functions $(document).ready(function() { /* Function for creating different styling checkbox, radio input, and select */ // Create pretty ch...
I was writing an application with a few Monads in a transformer stack. The top level application state resides in a TVar, and various components of the application operate on parts of it. I wrote a helper function to extract those parts: hoistStateWithLens :: S.MonadState outerState m => Simple L...
Problem Statement: A method called insertEnd() exists, but it runs in linear time, because every time it is called, it walks down the list to find the end. Without changing the meaning of this method or any other, modify the representation of a SList and whatever methods are necessary to make insertEnd() run in const...
I'm sorting with respect to Width and Length. However, Width has the significance precedence, so Length is only vital if Width is exactly equal (both are integers). The comparison method I've implemented as shown below. Is this a neat trick with doubling the most significant value's comparer or is there a better way? ...
This is part of a series of algorithmic lessons and tests by Codility. For copyright reasons, I cannot reproduce the question, which asks to compute the number of distinct absolute values in a given sorted array. The question requires a response in \$O(n)\$ time complexity. My response (below) was detected as \$O(n*log...
I have a class which provides various methods for retrieving information from a VMware vSphere environment. Over the time my class got extended and became large, so I thought I should spend some time to re-design it. Currently I am thinking of re-designing a bit in that class and move/group related methods into separa...
private void checkIfAllowed(String someString, STATUS status){ boolean validStatus = false; if(some condition){ validStatus = true; } if (!validStatus) { throw new RuntimeException("Some message"); } } private void callingMethod(){ ... checkIfAllowed("test", "PENDING"); ... } Or private boolean checkIf...
I had a requirement to restrict my web site's users to just one open tab in the browser. I am aware that this is not the best thing to do in terms of general user experience guidelines, but it's an internal application that doesn't play well with such a scenario so I had to do it. The following is what I came up with: ...
I have very little experience in programming with C++ and the following small "program" is the 2nd one I have ever written in that language. I am most interested in comments regarding naming conventions and the way the code is modularized. Also, can you tell whether the code sticks to idiomatic use of the language? Her...
I'm playing around with prototypes, constructor functions and javascript - I'm not really a Javascript developer but am interested in this. Am I on the right track with this code? I'm looking for a code review from a JS developer. I know the codes a bit funky. I created an example of it working here. function modal( ...
The ElectricalEngine class responds to the horsepower message. Because efficiency is calculated in percent a programmer can mistakenly initialize it with an integer instead of a float. class ElectricalEngine attr_reader :volts, :current, :efficiency def initialize(volts, current, efficiency) @volts, @current, ...
I am currenly contributing to a Chat-Bot to be used across the whole SE-Network's chat which is implemented in Java 8. This bot is supposed to have commands. These commands again are supposed to be as flexible as possible, and based on chat messages. To allow easy and extensible implementation of arbitrary commands I h...
I have been using aws-sdk gem with Rails, for uploading and downloading objects. I believe it's working fine. Demo code: begin s3 = AWS::S3.new bucket = s3.buckets[ENV['BUCKET_NAME']] bucket.objects.create(fname, data) object = bucket.objects[fname] exported_url = object.url_for(:get, {expires: 3.weeks, ...
I made a little JavaScript app here that let people generate bitmap for generating characters. Currently it generate code of a dictionary. But I want to also generate a example that let them play like the Arduino samples, use it as starting point or use it as-is. This is the code I wrote to enable someone to use 7-segm...
Design a Tips class that calculates the gratuity on a restaurant meal. Its only class member variable, taxRate, should be set by a one-parameter constructor to whatever rate is passed to it when a Tips object is created. If no argument is passed, a default tax rate of .065 should be used. The class should have j...
This function takes a numeric vector and returns "con" if it's continous and "bin" if it's binary. It does not take the multinomial case into account, i.e. if a variable y has three possible values 0, 1, 2, it's treated like a continuous variable. Code: checkBinaryTrait = function(v, naVal="NA") { if(!is.numeric(v...
Sometimes when I write a Python 3.x script with too many nested loops and some big values it just takes too long to give the answer. How can I optimize my code so that it runs faster, or where should I optimize? def isprime(n): '''check if integer n is a prime''' # make sure n is a positive integer n = abs(...
I've written a date parser that parses different types of dates using Parsec. Credit for the original problem goes to here. The following formats are as such: yyyy-mm-dd mm/dd/yy mm#yy#dd dd*mm*yyyy (month word) dd, yy (month word) dd, yyyy (month word) can be: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Note if i...
I am trying to learn C#. Please tell me if the following code respects coding standards and naming conventions because I want to write beautiful code. The purpose of this program was to help me understand different concepts that I've learned in the last few days but I was having difficulties thoroughly understanding th...
I have an array like Original = {1, 2, 3, 6, 7, 8, 9, 10, 12}. After removing some elements like Delete = {6, 7} from it, I want to get n sequential numbers which are not in the array, like IDs = {4, 5, 6, 7, 11, 13, 14, ..., n}. After getting the numbers I want the original array to be changed to the updated array. pu...
I have finished writing my nice and little text editor in Python with Tkinter. I tried to achieve the best user experience that I could. I want this code to be 2/3 compatible, I tested it in both versions but if you could test it out again in the 2 versions too it would very knd of you. I did not use a class on purpo...
Recently I wrote some code to take two arrays of data and create a title. Each array could have 0-n elements. However, the multiple if statements seem messy to me. Is there a nicer way to do this? Perhaps one that harnesses the power of jQuery better? var campaign_names = data["campaign_names"]; var list_names = data["...
I'm learning Clojure and have written a small function to calculate change. I don't like few things about the code and would primarily like to replace recursive call with something more idiomatic. Could you please comment on the code and suggest a better (more Clojure-like) way of implementing it? (def in-bank #{1 2 5 ...
This is part of a bigger project I'm doing to get better at JavaScript. It's basically the beginnings of a combat log parser for World of Warcraft. It looks a bit messy right now and I could really use some feedback at this point since I'm not really sure if I'm moving in the right direction here. The code doesn't fee...
I did some guesswork tweaking and let the heap reach a maximum of ~450 megabytes (was originally using invokeAll). The program just finished in 6.3 minutes. I've been advised to use ctrl + break to obtain a thread dump, but I am not experienced enough to use these results effectively yet. Finally, running the profiler ...
Is there a way to write this simpler? if(criteria.SortBy =="name") { if (criteria.SortDirection == "ascending") { physicians.Sort((x, y) => string.Compare(x.Name, y.Name)); } else { physicians.Sort((x, y) => string.Compare(y.Name,x.Name )); } } if (criteria.SortBy == "birth") {...