instruction
stringlengths
71
71.9k
I have created a calculator in Ruby. I am using Ruby 2.1.0. I'm fairly sure that someone will be able to improve this, as I am quite new to Ruby. puts "Welcome to Calc" puts "" puts "Please enter the first number" n1 = gets.to_i() puts "" puts "Please enter the second number" n2 = gets.to_i() puts "" add = n1 + n2 s...
Find the sum of product of all numbers in first array with all the numbers in second array. Input Format 1st line contains 2 space separated integers N and M. 2nd line contains N space separated integers Ai. 3rd line contains M space separated integers Bi. Output Format 1 single line containing only the require...
I wrote a map reduce program which uses multi threads, bounded buffers, condition variables. It works perfectly for some types of inputs. In the program there are N mappers, R reducers, 1 merger. mappers get data from input files, put each string in files to corresponding buffer-X-Y. reducers read from those buffers, ...
Noobie to Numba here, I'm trying to get faster code from existing function but the result is not faster. 10 times faster would be heaven, but I know nothing about optimization. This is code about parsing gaps in DNA sequences pairwise alignment and doing statistics about it. The code looks like this: import re import t...
This is my first program I can call 'something'. I would be glad to hear what you think of it, so I wouldn't pick up bad habits further on. It catches errors, but requires numbers to be separated from operators. It ignores a lot of characters, therefore (+ 2 2) is as valid as (+ 2 blargh 2) 100 lines of code + comments...
This will get quite clumsy if I continue down the road with this design, so I'm asking you, enlightened ones, is there a way to make this prettier and easier to understand? Primarily the run-function (Especially in the else if where self.query and self.find are set), also, I want it to be chain-able, with .run being th...
I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this. if (row < comparedFile.Count) { var regexJobNumber = @"([0-9]{4})"; var regexTimeStamp = @"([0-9]{8}_[0-9]{6})"; ...
This is problem 50 in https://wiki.haskell.org/99_questions/46_to_50. The website has more elegant Haskell solutions, but I wanted to get feedback on how the code I wrote on my own below could be improved. import Data.List data Tree a = Leaf a Int | Internal (Tree a) (Tree a) Int instance (Eq a) => Eq (Tree a) where ...
I just wrote a program which performed some elementary set operations as you can see below. It's the first time I have used input and output of text files so I am mainly looking for critique on that, and also how I use cells. clear all; clc; fileID = fopen('inputseto.txt','r'); data = textscan(fileID,'%s',3,'Delimiter...
My Cocoa event code always tends to descend into madness, I need to advice on how to reduce complexity. I've spend a few hours putting this example together. CanvasView is a layer hosting subclass of NSView which uses Cocoa's eventing handling (-mouseDown:, -mouseDragged:, -mouseUp:) to enable clicking and dragging of ...
This executes a predefined script on a remote host, and somehow retrieve variable values without affecting STDOUT and STDERR. My idea was to encode the data in JSON, write it to a file, then read the data in a separate request. The cons of this method are that: I would need to add the following code (file_put_contents...
I'm learning F# and functional programming, from a background in C# and imperative/OOP. I've ported a small, one-off console app from C# to F#. The port worked (the app behaves the same way), but I'd love to get some feedback on writing more stylistic F# and thinking about code in a functional way, as this was a port o...
I'm inspecting VBA code to find obsolete code constructs - namely explicit Call statements, like this: Call DoSomething(42) The "correct" code construct would be to omit the Call token and drop the parentheses - my code locates the obsolete Call statements and rewrites them like this: DoSomething 42 I have an Id...
The exercise 1.3 of the book Structure and Interpretation of Computer Programs asks the following: Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. My answer is this: var sumSquareLargest = function (x, y, z) { var number...
I need to extract a ID (int number) from a Url. Example: http://www.example.com/foo/bar/12345 For this I wrote 4 methods where the first one ReadIDsFromFile() is called by my constructor and the return value is set to a properties of this class. The methods are called in the order I posted them below. private List<stri...
The exercise 1.3 of the book Structure and Interpretation of Computer Programs asks the following: Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. My answer is this: import Data.List(sort) sumSquareLargest :: (Ord n, Floati...
This program is supposed to prompt the user for hours and wage of 4 employees. Then the program will use a selection sort to sort the data into ascending value using the wages. The information like employee id and hours and what not should be adjusted to match the sorted data. My program works but are there improvement...
I want to know if there's a better way of doing a select on dropdown and selecting the items. I bound ng-click to every anchor and assign a value on click, but it just doesn't feel like a clean way to do it. Also, is there a way to use ng-repeat to create the dropdown list dynamically? The problem I get if I use the n...
I have the following method, which finds all the possible paths from the top left to bottom right of an N x M matrix. I was wondering what is the best way to optimize it for speed as it is a little slow right now. The resulting paths are then stored in a set.You can only move down or right to an adjacent spot, no diago...
So far I have attempted to find the inorder successor through recursion and it seems to be working right. Can someone review the code and give suggestions? struct node { int data; struct node* left; struct node* right; }; struct node * inOrderSuccessor(struct node *root, struct node *n) { if(root == NU...
This is an update to my question Class for easier to read IProgress handling and includes the suggestions from @svick, with one exception. It was also suggested to change the setter for Content, so the report object could be set directly. I didn't make this change because this could result in reporting the same instanc...
I wanted to display 1 outcome of 1 single custom field or attribute in the category overview, using a third party customfield extension in my J! and VM website. I got it working using the code below. As this is the first time I actually write PHP and MySQL stuff myself, I was pretty proud, but also thinking 'this can p...
This bit of code gathers data from two methods and puts it into an array. The code works fine but it doesn't look pretty and I feel like there is a better way of doing what I have done. public static function RagUpdate() { $MachineOnOffStatus = self::RagOnOffStatus(); $ActiveMachine = array(); foreach ($Mac...
I have a snippet of SQL that compares the last two records and gives the datediff in seconds. However, the way I have it is quite slow, taking up to 20 seconds to execute depending on how many controllerIDs I need to check. What would be a more efficient way of doing this? select T.controllerID, ...
I was given a file of size 46KB full of names (around ~5000), in the format as shown below: "MARY","PATRICIA","LINDA","BARBARA","ELIZABETH"..."DARRELL","ALONSO" I wonder if my code below is optimal in doing what I want, which is to translate this txt file into an array of names. array = [] File.readlines('names.txt')....
I've implemented a table view controller for the purposes of subclassing. The table view controller implements a pull-to-refresh which will automatically reload the table view's data. I am looking for general feedback on my class. DXYBaseTableViewControllerHD.h #import "DXYBaseViewControllerHD.h" // Displays a table...
Here is a lazy dictionary with test cases. """ A dictionary whose values are only evaluated on access. """ from functools import partial from UserDict import IterableUserDict class LazyDict(IterableUserDict, object): """ A lazy dictionary implementation which will try to evaluate all values on access and...
I am able to develop this matrix but I think code can be improved. I am creating a map on which each rectangle may have zero through many list items with their titles (still need to add code for adding titles): var width = 600, height = 600; var margin = {top: -5, right: -5, bottom: -5, left: -5}; var zoom = d3.beha...
The program should read equations from stdin, parse them and generate a matrix of the coefficient which represents the system. Example: $ ./eqs x + y = 4 -y + 4x = 2 1 1 4 4 -1 2 As you can see, the user can input as many equations they want and the program stops reading when an empty line is sent. #inclu...
Find the sum of all the multiples of 3 or 5 below 1000. https://projecteuler.net/problem=1 Is there any hack to do modulo operation in better way? #include<iostream> int main() { unsigned int sum=0; for( int i = 0; i < 1000; ++i ) { if( ( i % 3 == 0 ) || ( i % 5 == 0 ) || ( ( i % 3 =...
As part of the odin project I've written this bit of code that allows two users to play a game of Tic Tac Toe. I'm still a relative newbie to Ruby and to coding and am guessing that there are much better ways to do what I've done here. I'd love to get input, suggestions and recommendations. The full code is below but ...
I was practicing some C and decided to write this simple command line utility for stripping leading and trailing white-space characters. Note: see the next iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up The code: #include <ctype.h> #include <stdio.h> #include <stdlib.h> ...
I'm trying to review and figure the issues in the above code. Any inputs to point out problems are welcome. using namespace std; typedef basic_string<char> string; class CHighLow { public: CHighLow() : nCurLow(0), nCurHigh(0) {}; void add(int nHigh, int nLow) { if (nHigh > nCurHigh) ...
Problem description: A non-empty zero-indexed array A consisting of N integers is given. A pit in this array is any triplet of integers (P, Q, R) such that: 0 ≤ P < Q < R < N; sequence [A[P], A[P+1], ..., A[Q]] is strictly decreasing, i.e. A[P] > A[P+1] > ... > A[Q]; sequence A[Q], A[Q+1], ..., A[R] is strictly increa...
See the previous iteration: A trivial command line utility for trimming whitespace from lines in C Note: see the next iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up 2 Now my code looks like this: #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string....
I have a list of error messages: def errorMessages = ["Line : 1 Invoice does not foot Reported" "Line : 2 Could not parse INVOICE_DATE value" "Line 3 : Could not parse ADJUSTMENT_AMOUNT value" "Line 4 : MATH ERROR" "cl_id is a required ...
I'm looking to pull all the youtube links from a string of text and was wondering how does this look? if (preg_match_all('/(https?:\/\/)?(www\.)?(youtube\.com)\/watch\?v=([a-zA-Z0-9_-]+)[^\s]*/im', $this->content, $matches)) { } Obviously this doesn't take into account the youtu.be links as they are formatted differe...
I am running a test load using Telerik Test Studio using 100 users at once entering search filters on a page that calls a stored procedure. My application that calls the stored procedure is an ASP.NET MVC 5 application and it returns this error: Timeout expired. The timeout period elapsed prior to completion of the op...
This is my first attempt to a serious Node.js application, I've tried to follow the async style of Node at my best, but I have several doubts and I am sure that this code can be massively improved. The idea behind this little service is to get a minified stacktrace and return a 'translated' stacktrace, if there is any ...
I have a code snippet which I wish to improve to increase my program's FPS, but as a beginner in JavaScript, I do not know how. I know the problem, which is the fact my counter mechanism used to delay attacks is causing lag. I just don't know how to change my code to minimize this lag. I am looking for helpful criticis...
The exercise 1.3 of the book Structure and Interpretation of Computer Programs asks the following: Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. My answer is this: #![feature(core)] use std::cmp; fn sum_square_largest(x:f64, y:f6...
The task was to build a simple parallel server in erlang that prints what it receives through a socket and alerts when the socket is closed. -module(server). -export([start/0]). start() -> {ok, ListenSocket} = gen_tcp:listen(8211,[binary,{packet,4},{active, once}]), spawn(fun() -> accepter(ListenSocket) end),...
I'm working on this small program for practice and would like to know how I could improve it from here. I'm still a relative beginner with C++ and would like to know if there is a better why to design this program. Things I want to do: Implement a while loop so that the program will continue to take input and write t...
I have created a Library Management system. Can anyone please look at if see if there's any bad practices or if anything could be done better? Main.cpp #include <stdlib.h> #include <iostream> #include <fstream> #include<iomanip> #include<stdio.h> #include <string.h> #include "Book.h" #include "DVD.h" #include "Student....
I'm extremely amateur when it comes to C++ in general, but I wanted to make a little "Pyramid Escape" text based game. I'm not done whatsoever but before I continue I want to see what I could possible do differently. // // main.cpp // TextFiles // // Created by Neal Carico on 3/12/15. // Copyright (c) 2015 Nedev. ...
This code finds expectation and standard deviation of sum(x) of 6 digited base-49 numbers with all digits distinct. The expectation is: \$\mu={\rm E[X]}=\frac1n\sum_{k=0}^{n}x_i=\frac{x_1+x_2+\ldots+x_n}{n}\$ whereas standard deviation is: \${\rm \sigma[X]}=\sqrt{{\rm E[(X-\mu)^2]}}=\sqrt{\frac1n[(x_1-\mu)^2+(x_2-\mu...
I wrote a sub to remove the blank entries in a row without shifting the cells around but it seems unnecessarily clunky and I'd like to get some advice on how to improve it. Public Sub removeBlankEntriesFromRow(inputRow As Range, pasteLocation As String) 'Removes blank entries from inputRow and pastes the result int...
I have a set of API endpoints where the URL is not standardized, so I could either get "api/auth" or "api/auth/" (may or may not end with "/"). I'm 'registering' the endpoint, plus the HTTP Method that comes in, so I can exclude certain endpoints from having to authenticate. I've written this piece of code, which has a...
I'm just learning Haskell and I wanted to know if I'm going in the right direction with my solving of the Haskell 99 problems. The file of interest is here which I've also reproduced below. module OneToTen where {-- Problem 1: Find the last element of a list. --} myLast :: [a] -> a myLast [] = error "Empty list." myL...
Problem statement The Utopian tree goes through 2 cycles of growth every year. The first growth cycle occurs during the monsoon, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter. Now, a new Utopian tree sapling is planted at the onset of the mon...
I'm a Java beginner, going through the Generics Questions and Exercises in Oracle's The Java Tutorials. Here's my solution to #8: Write a generic method to find the maximal element in the range [begin, end] of a list. All suggestions for improvement are welcome. I'd especially like feedback on the following: Java li...
I've got a filter that I'd like to work out how to optimize. The most basic implementation, using loops is like the following: import numpy as np nrow = 500 ncol = 500 refArray = np.random.randint( 0,100, (nrow,ncol) ) boundsArray = np.random.randint( 90,95, (2,nrow,ncol) ) window = 31 halfwindow = window/2 result = np...
I wrote a script that reads a file containing a password ("password"), loops each character in that file to see if it matches a character in the alphabet, and when every letter has been found the password is printed. def readFile(): file = raw_input("Enter file that contains the password: "); file = open(file, ...
This Python 3.4 script downloads stock data and puts it into an Excel file. ## Imports/Initiation # Put a "#" in front of the one you don't want to use. signs = 'a abc abt ace acn act adbe adi aet afl agn agu aig all alxn amgn amt amzn apa apc apd axp azo ba bac bam bax bbby bdx ben bfb bhi bhp biib bmy bp brk-b bud ...
I developed a script for the company I work for in order to extract data from SAP (CJ74) and analyze the data. One particular issue I am finding is that for any data sets which have over 1000 lines, it struggles to execute the section of code below, therefore I am searching for answers. This code takes free hand text...
I have a big log file (say 1-3 Gb) which I need to parse, extract data & save it in a CSV file. Text File Data * D:40035FC8 wr-long 00000008 \\core0\Global\u4TimeHiCnt 1.000us * D:40027C5C rd-byte 00 *core0\Global\Ypf_OILL_OilLvlOn 20.342us * D:40010044 rd-word ...
What is Coupon Collector's Problem? In probability theory, the coupon collector's problem describes the "collect all coupons and win" contests. It asks the following question: Suppose that there is an urn of n different coupons, from which coupons are being collected, equally likely, with replacement. What is the prob...
For some time it has been bothering me that there is apparently no way to directly initialize variables from input streams (something like int i << std::cin;) My solution is this: #include <iostream> #include <iomanip> #include <string> template<class T> T get(std::istream& in){ T tmp; in >> tmp; return tm...
In this constructor function I'm assigning everything to the proper variables. For the third parameter it accepts an options argument that contains the optional settings. To prevent a Cannot read property x of undefined. error I'm always checking this variable by steps, since the options variable can contain both compl...
This question is a continuation of my previous question: Check is_permutation on a pair of same sized arrays. I improved the implementation to generalize for all sequence containers. Please let me know how I can improve this implementation again. #include<iostream> #include<algorithm> #include<unordered_map> #include<a...
I am working on an AB tool in JavaScript using the following: Calculate the Conversion rate based on the conversions divided by the hits. Calculate the Z Score by passing in the control and treatment objects. Determine the confidence of the Z Score with Cumulative Normal Distribution. How accurate is this? /** Exam...
I am writing a system for doctors who are regularly visited by patients. The doctor adds each patient's visit to collection/database. The class can save data to an .xml file and restore it. Can you give your feedback about this code? // https://github.com/veitsi/jcrf-noweb import java.util.ArrayList; import java.util....
Being pretty new to testing, I was wondering how many of these tests make sense. restaurants_controller_spec.rb require 'spec_helper' describe RestaurantsController do describe "GET #index" do before(:each) { get :index } let(:restaurants) { create_list :restaurant, 5 } it "populates @restaurants" do ...
I am new to Azure and SQL. I have the following function that is part of a larger Web-API which is hosted on Azure and is querying an SQL Server database that is also hosted on the Azure platform: [WebMethod] public string RetrieveUserFriends(string userId) { //Ensure there is a user id if (userId == null) ...
For this assignment, you will create the pattern of a chess board that is 8 x 8. Use X and O to represent the squares. Create the appropriate nested looping structure to output the characters in an 8 x 8 grid on the screen using Console.Write() or Console.WriteLine() as appropriate. Include a decision structure ...
I am fairly new to the Groovy arena. I recently modified some code to add the following block. This code is added to remove dates we were supposed to remove from the total counts. This data goes on reports that a bug was noticed, that we weren't removing the queue entry dates. result.processed.each{ def queueEntry...
I am implementing an automated help function in my code. It is simply a few bubbles that pop up with some text in them. I use d3 to select one bubble, display it for a short time, and then select another bubble and display that one. It works, but I don't like the shape the code is taking. Am I approaching this correctl...
I have been working on a project to randomly generate a torus made through the use of an adjacency list and disjoint set structure (to be extended to solve the maze later), made from scratch. I think that I have optimized my code pretty well, but may have over-looked some things. Program Description: The program works ...
I have attempted doing a fluent API for creating random int arrays, and the following is what I came up with: fluent_arrays.h: #ifndef FLUENT_ARRAYS_H #define FLUENT_ARRAYS_H #define REQUEST_THREAD_LOCAL 1 #ifdef REQUEST_THREAD_LOCAL #define THREAD_LOCAL __thread #else #define THREAD_LOCAL #endif /*****************...
I am playing with Rust, and am trying to write a simple parser. I need to parse the string: "0123,456789" into a stucture: Passport { label : i8 = 0, body : i32 = 123456789 } I am using parser_combinators and my code is working, but very ugly. How can I rewrite this code? extern crate parser_combinators as pc; use ...
So I'm trying to code a navigation scroll bar like that looks like this: This is the code: <!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; } li { float: left; } a:link, a:visited { display: block; width: 120px; height: 50px; ...
I'm trying to write a simplistic Monte Carlo simulator to predict asset prices. For example, if something has an initial value of 50 and an historic daily standard deviation of 2, what are the odds it will be 40, 40-50, 50-60 or greater than 60 in 25 days? import random start = 50 sd = 2 days = 25 bins = [40,50,60] i...
I’ve written an answer for The Grid Search challenge on HackerRank. Please let me know of any improvements that can be made to my implementation (specifically if there's any way to make the algorithm more efficient. I'd like to make this algorithm optimal). P.S: My implementation is a brute force algorithm, and I reck...
I tried to implement an immutable list. public class ImmutableList<T> : IEnumerable<T> { public T Head { get; set; } public ImmutableList<T> Tail { get; set; } protected ImmutableList() { } public static ImmutableList<T> WithItems(IEnumerable<T> items) { if (items.Count() == 1) ...
The program adds two binary numbers in two' s complement ignoring the overflow for a constant size of bits. I am trying to generalize the program by taking input from the user in a single line without memory wastage. Is there any way to achieve this? #include<iostream.h> #include<conio.h> void main () { const int ...
I am going through the CodingBat exercises for Java. I got to this problem: Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and right (if any) are gone. So "ad", "ab*cd", "ab**cd", "*ead", and "ade*" all yield "ad". I decided to solve this u...
As I am a totally self-taught 'person writing code', I decided to learn algorithms with one online course that taught them using Java for demonstrative purposes. The first topic I covered is the graph data structure and API. I undertook to rewrite Java examples into PHP for training purposes. I would be really grateful...
I am working through the Coding Bat exercises for Java. Here is one I have just completed: Given a string and a non-empty word string, return a version of the original String where all chars have been replaced by pluses ("+"), except for appearances of the word string which are preserved unchanged. And here is my sol...
Goal: create a new OrderedDict instance's keys in such way that keys in the specified order list appear first. If some keys in order list are not present in OrderedDict, ignore them. Additionally, reordering should be "stable", that is, if some keys were not specified in order list, they should keep their original ord...
How can I do this better? $a = "Tom Smith" ; $e = $a.substring(0,1) $ee = ($a).split(" "); $y = $e + $ee[1]; $y TSmith
Here is the source of the question, and my solution is below. Did I determine the worst case correctly? If you find any input where it doesn't work, please let me know. public class Main { /* * http://www.careercup.com/question?id=6305076727513088 * * Worst case: O(2*n) * [ 1, 3, 4, 1, 0, 23 ]...
I have here some code which is working but it seems to be a lot of coding to do here. I would really appreciate if someone could make this simpler. <!-- *********************************************** --> <div class="widget search-w"> <div class="wrapper"> <div class="big-icon search icontap"><a class="widg...
A code challenge between some friends, as I came from a Procedural way of coding, instead of using Objects. The paramaters are below: store the properties of a car colour make model speed direction demonstrate how these properties are accessed manipulate these properties through standard calls (functions/methods)...
This was a little app I wrote looking for a way to create consistency in the way employees taking phone orders enter the address. The purpose of the app is to require a user to enter a valid address. The scope broadened to include two secondary objectives, performance and proper rendering. Performance: No IF ELSE o...
I am writing a stop watch utility class in Java that I want to be thread-safe (concurrent). Here is what I have right now: public class Stopwatch { private volatile long beginTime; private final AtomicLong lastLap = new AtomicLong(); private final AtomicReference<List<Long>> laps = new AtomicReference<Lis...
I need to perform few tasks inside a Windows Service I am writing in parallel. I am using VS2013, .NET 4.5 and this post shows that TPL is the way to go. I was wondering if anyone can tell me if I have done it correctly. public partial class FtpLink : ServiceBase { private readonly CancellationTokenSource _cancella...
I have written a small plugin library for CKFinder that I would like some critiques on. The library is located here. If you are looking for where to start, check out plugin.php and hook function in here in the assets/ckfinder/core/connector/php/php5/CommandHandler/ folder. I would really love to hear your critiques on:...
I've developed as part of a game engine a template class for a factory which manages objects of one specific type. The factory handles initialization, destruction, and accessing previously created objects by string identifier. It allows forwarding parameters to object constructors with variadic arguments, and is interf...
I am new to Python. I wrote a code that works but the algorithm is obviously not efficient at all. I am stuck in the loop on iterrows and I do not see how to get rid of it. First a little bit on the data, they look like that: var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 var13 var14 var15 var16 n ...
I would like to get a distinct array of objects. The code below is the first thing that came to mind. Do you see any room for improvements? function distinct(objectArray){ var distinctResult = []; $.each(objectArray, function(i, currentObject){ if(!exists(distinctResult, currentObject)) ...
I've been looking for a way to have a predicate that establishes that all elements of a list are substrings delimited by a given string. Analogues in other languages include: 'delimiter'.join(list) in Python, (mapconcat function sequence delimiter) in Emacs Lisp, array.join('delimiter') in JavaScript, and I'm sure ther...
For a while, I have tried to find ways (known or new) to do stuff with Gray codes. As some of you probably know, I already tried to implement an algorithm to add two Gray codes without having to convert them to a regular binary representation, perform a regular addition and convert the result back to a Gray code. The f...
The previous iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up Note: the next iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up 3 Now my code looks like: #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string...
It has been very hard to use recursion, but I think that it made the code shorter and cleaner. import doctest import operator as op START_FOR_SYMBOLS = {'+': 0, '*': 1, '/':1, '-':0 } OP_FOR_SYMBOL = {'+': op.add, '*'...
I have the following CSS: .class { margin: 1%; margin-left: 0; } I wonder whether another way would be better? Option a) .class { margin: 1% 1% 1% 0; } Option b) .class { margin-top: 1%; margin-bottom: 1%; margin-right: 1%; } Option ... Any other recommended ways?
I wrote perfectly working code that reads an image, and then does a kind of threshold on it by zone. If the zone has too much white then it turns all the zone into white, otherwise it turns into black. The problem is that the code was originally from a C++ source with pointers and all instead of GetPixel() etc. Speed w...
I created this responsive jQuery navigation which will re-size when the pixels get < 500 px and display the mobile navigation, although when the browser resizes > 500px it runs the widthCheck() function which is supposed to run the jQuery code that returns it to tablet/desktop size, although it doesn't do this transiti...
I have a basic version of CGoL running with pdCurses. My goal was to have each newly spawned cell take on the dominant color of their neighbors (if a spawned cell is mostly surrounded by red, make it red). I managed to get a half-baked solution working, but it has a few problems, mainly: It requires another member vec...
I have a method in my Ruby code that sets the default name for my model. Rubocop complains that Assignment Branch Condition Size is too high, 21.24/15. How can I improve this? def set_default_display_name return unless display_name.blank? count = user.credentials.where(type: type).count if count == 0 self...
For fun, I've made a practical file IO class in C++ with the purpose of being light and quick, and extendable for custom parsers. Here is the code: parser.h // // parser.h // // Created by Taylor Shuler on 4/8/15. // // #ifndef _parser #define _parser #include <fstream> #include <iostream> #include <list> #include...