instruction
stringlengths
71
71.9k
// Check horizontals for (int y = 0; y < sGridHeight; y++) { Shape* groupShape = nullptr; int groupSize = 0; for (int x = 0; x < sGridWidth; x++) { GridItem* gridItem = GetItem(x, y); Shape* shape = gridItem->GetShape(); if (shape == groupShape) { groupSize++;...
Summary: I need to hide several (pre-determined) divs based on a child element's ID. Caviats: I can't alter the HTML directly in any way (by modifying the literal .html file). The IDs of the child elements for which the parents are to be hidden are known and not likely to change often (or even at all). I can't add CS...
I've wrote some simple code to load a JSON file from the Twitter Streaming API, parse the data, and create relationships between users based on who mentions or retweets who. My ultimate goal is to have a file that I can load into a network analysis program to analyze. I wrote the code to first look for a retweet, and ...
I am using Merton default model with complex iterative approach. I have already prepared my R codes but as I am quite new in R, they seem very inefficient, in sense that they runs almost 7 hours. My main problem is my for loop part. I kindly ask you review my R codes and give any corrections which could make my R code ...
I am working on a class for encryption to use on my site. I have read through many examples of these functions and would just like to clarify a few points I have read and check if this code is worthy. It is for storing sensitive information in a database. I am aware that making this method secure does not mean that the...
I have created a function which returns the number that corresponds to the given row and column from the pascal triangle. I have used the formula for this: n! / r! * (r-n)! The code: def pascal(c: Int, r: Int): Int = { def factorial(number: Int): Int = { def loop(adder: Int, num: Int): Int = { if(...
I'm having trouble testing some code. It's laid out in such a way that the business logic relies on the persistence layer. Some classes require that an object be saved to a database. Some classes re-read the object they were working to get the "original" version of it. All of this tends to happen in what's been labeled...
I've made a prime number generator (for Project Euler). It uses Euler's Sieve (a modified Sieve of Eratosthenes), with a mod 30 step. I'd like to reduce the memory consumption to 4/15 what it currently is by keeping a boolean array only for the possibly prime remainders of 30. I can't get it to work and also fear th...
I have trouble with for loop, my code runs very slowly. The thing I want to do is to use function from apply family to make my codes run faster (instead of using for loopand while). Here is an example and my loop: require(data.table) require(zoo) K<-seq(1,1000, by=1) b<-c(rep(2,250), rep(3, 250), rep(4, 250), rep(5,25...
I need feedback on this code regarding security issues. <?php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['message']; //Validate fir...
I've made a prime number generator (for Project Euler). It uses Euler's Sieve (a modified Sieve of Eratosthenes), with a mod 30 step. I'd like to reduce the memory consumption to 4/15 what it currently is by keeping a boolean array only for the possibly prime remainders of 30. I can't get it to work and also fear th...
When I had to create a fixed header on scroll, I found a few examples on Stack Overflow but they were terrible in the sense that they relied on a fixed page height. Have a look at what I created which does not rely on a wrapper around the header and the content. Default On Scroll Demo on CodePen. HTML <header> <d...
I took a little time and wrote the following code to produce enigma encryption. I don't normally write code in C so I would like to get feedback on the way it has been structured and any issues a more experienced C programmer might spot in the way I used structs, command line parsing, and the indexing around the stri...
Quite sometime back I had written an Android application which simulates the path of a pendulum. You can also have look at the complete discussion in my technical blog here. Please review it and provide me with your valuable comments. package com.somitsolutions.android.pendulamsimulation; import android.app.Activity;...
I am checking for particular keywords in a string, and then changing the foreground and background colors of substrings based on the keywords. Following is the snippet for checking the background code: if(string.contains("[30;42m") || string.contains("[31;42m") || string.contains("[32;42m") || string.contains("[33;...
I've written some code today to be able to dynamically execute prepared statements/parameterized queries. I need a fresh pair of eyes to look through my code for eventual performance gains that can be made. I've tested the code on up to 20 parameters without problems. For formatting I use this: {0:i}, with position of ...
I've tried to create application with MVC N-layer pattern. I asked my buddy for a shot review, and he said, "You should separate logic from controller". But my controller only work as a ViewModel creator. I'm sure I must not create ViewModel from BusinessLayer. I need to pass data in DTO like I did here. But what abou...
In my program I call "granularity" the "minimum step" for a number. For example, if granularity == 4 then I only work with numbers "0, 4, 8, 12 etc" (so normal integer has granularity == 1). I need a function to round an integer number to a certain granularity. So for example, if granularity == 3, I want this map: // I...
I am fetching data from the database using Entity Framework and Linq queries. I am wondering about the performance of getting data. I just want to check whether or not a well exists in the database. The database table has 15 columns and the number of rows are unknown. internal static bool WellExists(string name, Databa...
I am implementing a thread like the following. Is my implementation correct? It works well, but I need a check. myList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { // TODO Auto-generate...
I have an Entity Framework working with a SQL database. A Web Forms application is currently communicating directly with the Entity Framework model from code behind. I have been tasked with creating a 'middle layer' Business Logic Layer to sit between the UI and DAL (EF). I have come up with the below for the Person en...
I just solved Project Euler 38 and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to optimize the numbers I'm checking would be appreciated. from timeit import default_timer as timer def create_pandigital_m...
I am new to Python as well as threading and had to build an inline script routine for the use within a Open Sesame Experiment. The Routine should open a program, play tones and catch reaction times. It runs OK so far, but I would be glad for pointing out mistakes and any best practice that I did not follow as I want to...
In a module of a win forms application I have a hierarchy of classes like BaseRecovery, LoanRecovery and FineRecovery. Both LoanRecovery and FineRecovery inherits from BaseRecovery. All these models have one view called RecoveryForm where you can enter/view loans and fines of employees. and I'm planing to use single Pr...
I started to learn Rust last night. Given its parallelization capabilities, I thought a good starting point would be porting my C++ AI for 2048 to Rust. This is the function implementing the shift of one line (from high to low indices) of the 2048 board, ported verbatim from C++. It is supposed to shift the numbers in...
I want to know the best way (best performance and reaction time) to insert all rows of an SQL table into a Google BigQuery table. Actually, I am looping over a query result and insert the rows one by one into the BigQuery table. The query GetShippingList returns all TShipping_ID of the table Shipping which has only one...
I'm currently working on a wind farm design software and basically I have to analyze the incidence of certain wind turbines on other downwind, in order to calculate the velocity drop in the wind once the downstream turbine "sees" the flow. I have sorted out most of the code and it works, yet this particular piece of it...
This is a class for storing memory on the stack when possible or in std::vector when it grows too much. Note: Using std::vector with custom stack allocator would be arguably better but I did not want to depend on 3rd party allocators (and could not find one for C++11 that compiles cleanly). #include <array> #include <v...
I call several WebServices which return each a different exception type: try { //calling first WS1 here } catch (my.package1.FaultWS_Exception e) { StringBuilder sb = getMessageFromException(e); log(sb); } try { //calling first WS2 here } catch (my.package2.FaultWS_Exception e) { StringBu...
I was having a hard time finding out how to make this any faster. I broke down the code that I am playing with into more methods than necessary to try and see where things could increase. Can anyone think of any good ideas? I am not opposed to using different data structures. The main idea is receiving an Activity wi...
I have a 'speed problem' with a program im currently developing. I already have encountered the methods which costs some time. public void ConvertDataFrameToValueFields() { List<byte[]> items = new List<byte[]>() { new byte[2], new byte[2], new byte[2], new byte[2] }; items[0][0] = this.DataBytes[0...
I have the following code I would like reviewed. I was recently tasked with sorting products coming from SOLR. The sorting is not by description or by the product number but rather by the below criteria. Normally I use linq to use grouping and sorting, but in this case I have existing (older code) and my approach was t...
I wrote this script to backup some important files. It backs up the files to a local folder as well as to an external hard drive. It creates a new subdirectory which has its name constructed with the current date and time. Works perfectly, but I'm just wondering if there are any Python best-practices I'm missing or ...
After reading the SFML Game Development book, I decided to put what was learned to the test by creating a simple Breakout clone. I have posted the source code to GitHub: https://github.com/andrewd440/breakoutsfml I wanted to see if I could get any sort of feedback on the general code structure that I used or any progra...
I have a PRNG-Class called Generator. Now, after creating a new instance of it: var g:Generator = new Generator(); Custom function: set_seed() - Please review this approach. I call g.set_seed(); which has the following logic: public function set_seed(s:Number = 0):void { seed = (s > 0) ? s : new Date().getTime()...
Given a string find the number of meaningful words which could be formed from the string for eg. programmerit forms: pro+gram+merit program+merit programmer+it pro+grammer+it Looking for code review optimizations and best practices. Also hoping for suggestions for complexity better than \$O(n^2)\$, where n is the n...
I have an imperative programming background and I've decided to study functional programming by applying it to problems found on sites such as Project Euler and Rosalind. My language of choice is Scheme (I use CHICKEN). As can be seen, I'm only starting out. This is about the 3rd problem found on Rosalind, that goes li...
I'm wondering how I could compose this program better allow it to grow more functionality without constant refactoring. This is my code sample for Hacker School, so I'm less married to the results but instead am looking to further my understanding of Clojure and functional programming. Basically, my battle simulator ne...
I'm sure that among you (users of codereview) there are many who are interested in Codeforces problemset. I tried to solve 427B: Prison Transfer tasks but have Wrong Answer judjment at 4th test. Maybe you've already solve the problem or is interested in solving? Can you find error in my code please? PrisonTransfer.java...
Please critique my solutions to these simple exercises. I have no programming experience, so the more anal you are, the more I'll learn. I'm teaching myself, this is not for school: Write a function translate() that will translate a text into "rövarspråket". That is, double every consonant and place an occurrence ...
I created this testimonial section as a prototype. HTML <div class="testimonials"> <blockquote> <p>This was pretty good.</p> <cite> <span class="author">– Bobby,</span> Jersey City, NJ </cite> </blockquote> <blockquote> <p>This is pizza is the most bearable thing I ever had in Joisey. But...
I have recently started working on a server software in Java and wanted to add a configuration option to the program. I have gone through a few revisions of this class because I never liked what I came up with. I finally made something that I'm somewhat happy about and it works better than past versions. I'm just cu...
I have written this Sudoku Generator. How good/bad is this? How can I improve this? import java.util.Random; public class SudokuUtility { static final int max = 8; static final int min = 0; static final int digitMax = 9; static final int digitMin = 1; static final int easyMin = 36; static fi...
Given below is code which I wrote to provide an easy access to Facebook graph API. import simplejson as json import urllib class Facebook (): def __init__ (self, access_token): self.access_token = access_token self.id = None self.name = None def user_information (self, fbuser = "me"): """ retu...
I am very (very) new to programming, and today I (semi-)successfully wrote my first program that performs very basic things. My hope is that I can receive some constructive criticism around how I structured it all and if I am doing things in the most efficient and proper way possible for what I am trying to achieve. #i...
I've implemented a (version of) Merge Sort algorithm in Python. My goal here is two-fold: Improve understanding of Merge Sort and recursion in a language agnostic way. Improve understanding of Python conventions and idioms. The implementation recursively splits the given sequence into left and right sequences and the...
I have a multi-module Android project built by Gradle with the new Android-plugin 0.10+. All modules are mainly configured from the root project. I've enable the new code coverage feature. The major problem is that only some modules contain test code and when I enable code coverage on modules that don't contain test co...
Am I on the right lines for connecting to my Database? If not could somebody help me improve it or point me in the right direction? Index.php: use Acme\Foo\Database\Connector; use Acme\Foo\Database\MySQLConnector; $obj = new Connector(new MySQLConnector); echo $obj->db->connect(); DatabaseInterface.php: interface Dat...
I have a PRNG-Algorithm: /** * Generates an integer. Min: 0 | Max: total - 1 * @param total The number of possibilities. * @return The generated number.*/ public function generate_normal(total:int):int { _seed = (_seed * MULTIPLIER) % MODULUS; return (_seed * total / MODULUS); } The constants are defined as...
My little program I'm working on generates charts (GUI) and (on another tab) lists the values my chart is fed from. 2011.01.01 0:00:00 456 2011.01.02 0:00:00 45 2011.01.03 0:00:00 46 2011.01.04 0:00:00 6 2011.01.05 0:00:00 1500 ... When I click on the "Generate Chart" button, after the chart genera...
class InvitationConfirmationValidator < ActiveModel::Validator def validate(record) invitation = Invitation.find_by_url_suffix(record.id) if invitation if invitation.materialized? record.erros.clear record.errors[:base] << "Invitation already materialized" end else record...
I was asked to provide some example code for a job interview and didn't have anything to offer, so wrote the following function. A barcode generator may seem a bit basic, but there's some logic behind the choice: It's something I recently needed, so not entirely contrived. It's simple enough to do in one function, so ...
I just finished Project Euler 39: If p is the perimeter of a right angle triangle with integral length sides, {a, b, c} … For which value of p ≤ 1000, is the number of solutions maximised? I'm pretty satisfied with my solution. I derive the formula for the hypotenuse as follows: $$\begin{align} a + b + c &= p \tag{De...
I've been teaching myself programming in Python for about three months now using How To Think Like a Computer Scientist and a bit of the internet with the intention of being able to create video games someday (nothing huge, but something/stuff worth playing). What I'm looking for is an assessment on how I'm doing and i...
Is this a good approach of designing a class or is there some other way that I am not aware of? Student.h specification file #ifndef STUDENT_H #define STUDENT_H #include <string> using namespace std; class Student { private: int ID; string name; double GPA; char gender; public...
I did this project last year, under some interesting constraints: it's a thin webserver which lives in a Raspberry Pi, which is networked to an embedded system in an industrial sign which is running a proprietary and heavily modified version of *nix. I didn't touch the embedded system in the sign at all. The whole thi...
How can I improve my code below for the following question? While it works, I am not satisfied with how it looks; I was hoping I can somehow keep it recursive, and have the ans filled up inside the function, and reduce the number of return statements that I have. Treat this like an interview problem. Worst case: \$O(...
This is a follow-up post I have taken some of the suggestions there and have made some changes from my side too. I think it looks better, but please look at it and lemme know if you think any more changes needs to be done. It follows PEP8 standards. __author = "Pranav Raj" __email = "pranav09032@hotmail.com" import si...
I'm writing three functions which iterate over lists, I want do this recursively, but I think this code is not as efficient as it could be. def flatten(lst): if type(lst)==int: return [lst] elif lst==[]: return lst else: return sum([flatten(sub) for sub in lst], []) def size(lst): ...
I'm trying to make a program that will shutdown my computer after a certain time that I will input via GUI. I'm wondering if I did it the correct way. Also, will this slow down my computer while it waits to shut off? Do you see anything wrong with the code? import java.io.IOException; import java.util.Timer; import jav...
Some telephone operators have submitted their price lists including price per minute for different phone number prefixes. Some test data, 2 price lists, look like this: Operator A: 1 0.9 268 5.1 46 0.17 4620 0.0 468 0.15 4631 0.15 4673 0.9 46732 1.1 Operator B: 1 0.92 44 0.5 46 0.2 467 1...
I'm writing a Python script to randomly generate C functions. This is my first time using classes in Python and I'm basically doing my best to pretend I'm using Java. I'm looking for a review of my OOP, Python style, and in general whether or not I'm doing things in the "Pythonic" way, whatever that means. import rando...
I'm unsure about how to simplify this method properly. The method is basically responsible to allocate data. The response object is a collection of objects. Each object contains an attribute called order and i have to distinguish between visible and invisible elements. Visible elements are represented by positive integ...
I wanted to get some feedback on this JS I am working on. It works wonderfully on my desktop, but on my and my friends' laptops (especially Safari) it is very slow. I need some pointers on improving the efficiency so it works nicely across browsers/computers. http://www.dapper-apps.com // If jQuery was not loaded, offl...
This code's sole purpose is to create a very random password, using letters and numbers. I think that it fulfills its purpose, but I wonder, could it be done better? I'm not talking about efficiency, but security. In your eyes, how secure is this method for generating passwords, and if it is barely secure at all, what...
Here is a class vector in python 3, for n-dimmensional vectors. Please suggest ways to improve the code as well as fix bugs and errors. The only rule is not using: numpy, sympy, scipy and so on. Only math, cmath, Rational, Decimal, ... Python 3 default packages.. This code is only for learning to make classes with pyth...
I'm trying to learn proper C++ and algorithms at the same time. I particularly feel weird about my iterators usage in merge function. Is this a good way to handle it? I've modeled the signature after the STL std::merge method in <algorithm>. I've tagged it as C++11 as well, because ideally I would've liked to make use...
I want to improve this code to make it look more professional, be loaded quicker and make it cross-browser compatible. Do note that it is not a finished site. I want to know the best practice for doing certain things before I proceed any further. HTML: <!DOCTYPE html> <html> <head> <title></title> <link rel="style...
The function below simple allows a logged in user to "star" another user for convenience when trying to find the that user another time. At the moment the function works as it should, it inserts the user giving the star and the user receiving the star into a database table, then grabs the first name and email from the ...
I've made a simple drawer using CSS3 and jQuery that works with hover and click. It seems to be working fine but surely there's a simpler way of writing the code. Fiddle: http://jsfiddle.net/73MpU/ $("#bottom-page").click(function () { $("#top-page").addClass("push"); }); $("#bottom-page").mouseover(function () { ...
I'm currently working on a PHP component: "Filesystem handler". I've run into a problem where I want to call one exact method in both dynamic and static ways. I've ended up with this solution. Could you please give me a feedback ? I want to know, if there is a better or a simpler way to achieve the same result. <?php ...
I wrote a Ruby gem to analyse strings for word length, word density, and a few more hand methods... The Counter class accepts a filter (String). The class will remove any words from the original string that you include in the filter. Spec: it "removes words passed in the filter" do counter = Counter.new("That was...
I have the following Prolog code which samples n items from a list without replacement: samp(0,_,Sample,Sample). samp(N,Domain0, Sample0, Sample):- N >= 0, length(Domain0,L), RandomNumber is random(L), nth0(RandomNumber, Domain0, X), delete(Domain0,X,Domain1), append(Sample0,[X],Sample1), N1...
Can you suggest ways of making this more efficient? I don't want to repeat this example for all of my tags that need a class added, if there is a better way. $("#menu").find("div:nth-child(2), div:nth-child(3), div:nth-child(4), div:nth-child(5), div:nth-child(6), div:nth-child(7)").addClass("menuDivs");
I did this code over one day as a part of a job application, where they wanted me to make a minimal webcrawler in any language. The purpose was to crawl a site, find all of the URLs on that page, and crawl on to other pages. The code had to be able to resume operation if shut down (that's why I saved the lists to text ...
I'm looking to get some feedback on this program I wrote - ways I could make it simpler or best practices methods. Chapter 7: Let's write a program which asks us to type in as many words as we want (one word per line, continuing until we just press Enter on an empty line), and which then repeats the words back to us i...
Please review and suggest improvements for my isPrefixOf implementation. isPrefixOf' :: (Eq a) => [a] -> [a] -> Bool isPrefixOf' [] _ = False isPrefixOf' _ [] = False isPrefixOf' (x:xs) (y:ys) | null xs && x == y = True | x == y = isPrefixOf' xs ys | otherwise = False Also, I wrote isSuffixOf...
Learn You a Haskell mentions the partition function: partition takes a list and a predicate and returns a pair of lists. The first list in the result contains all the elements that satisfy the predicate, the second contains all the ones that don't. How's my implementation? I'd prefer to avoid the ++ function, but...
For a form I got the markup below, it belongs to an input category and as there can be more than one insertion at it I includded an Añadir button (Add). I give id="posgrado1" to first div and using Java Script I increment the id's to posgrado2, posgrado3, ... posgrado#n <div class="form-group" id="posgrado1"> <lab...
I just have a small question. The code I wrote works well for the problem. But is it the best way, or can we make it better? struct node * swapAdjacent(struct node * list) { struct node * temp,*curr,*nextNode; temp = list; curr = temp->next; if(curr == NULL) return temp; nextNode = curr->next; ...
I wanted to play with value types for Simon's challenge; I came up with this quick-and-dirty, basic implementation of a card-fighting game: I started with a value type to hold assets - I'd reuse that type for player status, card cost and card effects: public struct Assets { private readonly int _warriors; priva...
I have following stored procedure in a C# win forms application which calculates employee earnings based on attendance as follows. Note that a shift is 12 hours and employees mark attendance for in and out of each shifts. Also salary period is from beginning to end of a month (1st to 28st / 30th / 31st). Related table...
In a C# win forms payroll application I need to calculate employee salary based on their attendance. I've written a stored procedure which calculates earnings of all employees from the data available in attendance table. So when the application calls the SP the data will be shown on a data grid view and then immediatel...
I have a need to process URIs in one of my applications, sometimes from const char[] literals. My API: namespace net { class uri { ... }; // contains decomposed URI (path, parameters, etc) uri parse_uri(const std::string& uri_str); // parse string and return uri instance } // within global namespace (this is ...
The code is implemented to perform HTTP get with HTTP proxy. Future object is adopted to avoid blocking in current thread. I'm not quite sure about the usage of HTTP connection pooling manager and the way using Future obj to avoid blocking looks ugly. Can somebody review this? import java.io.BufferedReader; import ja...
I used Nokogiri and a piece of ActiveSupport to parse an xml file from a given URL, format the data properly and return a JSON string. The script works as expected, so I'm only wondering if there are ways to make the code better from architecture/naming perspectives. #!/usr/bin/env ruby $:.unshift File.dirname(__FILE_...
I would like to find out if following usage of an AtomicBoolean as a flag variable is correct and good for a multi-threaded application. It is expected that data is going to be loaded only once and when the application is at very low load. It is also expected that the list of SomeObjects is going to be read quite frequ...
Is it a bad idea to use the notfound callback like this? If so, why not? (bad scope/closure? I'm a noob node.js dev.) Is it a bad idea to use the saveCallback callback like this? I have a feeling it's dangerous, but I don't want to declare saveCallback before queryCallback as save happens after query. create: functio...
I'm facing the issue of how to reconstruct data across a network in Java. As part of my Component based game engine (read about it here, I have to encode components as XML on the server, send it to the client, and then reconstruct the appropriate component with all the data included in the XML. For example: package.T...
I am currently making a very big blogging system for my Website where I want really neat code! So, I was wondering: is this method safe/does it have any problems with security? Yes, I'll be encrypting the password anyway. I also want to know if there is a better way to achieve the same idea. Also any tips on implementi...
I have 4 variables - say A, B, C and D Each variable can have 4 values - say 1, 2, 3 and 4 I need to generate all possible combinations of values Example of Expected Output: A B C D --------- 1 1 1 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 2 1 1 1 2 2 1 1 2 3 . . . 4 4 4 1 4 4 4 2 4 4 4 3 4 4 4 4 I have wrote follo...
The setup of Backbone: 1 Collection, 3 Models, 1 View for the collection, 1 View per Model. HTML: <div id="showit"></div> Template: <script id="item-template" type="text/x-handlebars-template"> <a class="item" href="#">{{book.name}}</a> <br/> <span>Liked :{{book.likes}}</span><br/> </script> Backbone JS...
I want to implement a predicate of the form: zipwithindex(?List1, ?List2) which is true when the elements of List2 are the same as in List1 but are paired with the index of the element. This is what I have: zipwithindex([],I,S,S). zipwithindex([H|T],I,S0,S):- append(S0,[H/I],S1), I1 is I+1, zipwithindex(T,I1,S1...
I'm learning Entity Framework and I'm wondering if this code is the proper way of doing this. Basically this is my attempt at refactoring a very long controller in ASP.Net MVC 4. I'm using Entity Framework 5 as well. What I did was I separated out some code into a more common method (buildUpdatedAnswerDetailRecord). ...
This is a continuation of the last thread. I wanted to add a thread-safety and I was considering AwaitableCriticalSection and Task+Mutex. I ended up with mutex; it can be a bit slower but it would allow different files to be stored independently. public static async Task<T> ReadJson<T>(String fileName) { if (Strin...
I have a Cache Helper Class. using System; using System.Web; public static class CacheHelper { /// <summary> /// Insert value into the cache using /// appropriate name/value pairs /// </summary> /// <typeparam name="T">Type of cached item</typeparam> /// <param name="o">Item to be cached</param...
I just finished Project Euler 40 with a brute force method. As usual, any optimizations would be helpful. (I feel like I'm getting better at this scripting thing) from timeit import default_timer as timer def product(n): from functools import reduce # Valid in Python 2.6+, required in Python 3 from operator im...
I do not like this implementation as is seems too much complicated. My idea was to implement some BFS algorithm variant. Some points to notice: I use one queue. In the begining put the tree root in the queue and dummy treeNode delimiter which is recognized by its data == -1. (I need this for distiguishing between...
I have a question about of the performance of using for loops (normal for, for each and for key in object) in JavaScript. Just now I created this code to test: var stopwatch = function(){ var start; this.Start =function(){ this.start = new Date().getTime(); } this.getDifference= function(){ ...
I am making an application which fetches tweets for a specified amount of time, then inserts those tweets in a database and when the user presses another button the top n words and the hashtags will be shown. This is my Twitter package: [Package]Twitter >[Class]TwitterTools.java This is my Analyzing package: [Pac...