instruction
stringlengths
71
95.1k
My insight here is that it's usually not useful to distinguish between null and empty strings. Sometimes it is, but usually not. Usually I like to assign my strings as empty if they would have been null. var lastName = Request.Params["lastName"] ?? "" Thus I had the idea of a struct which would wrap a real string, inte...
I'm a Java developer, I'm new to Ruby and I'm worried that I'm forcing or not-so-well using the goodness of the Ruby syntax. What do you think about the Exception catching and how to print it in error messages? What about the code block (closure?) I'm passing to the "until" method? Is it ok to implicitly rely on what...
I have the following requirement for valid usernames: Only alphanumeric characters and - Must not start with a - I wrote this regex (on Rubular): /^[^a-zA-Z0-9]|[^a-zA-Z0-9-]+/ Is there a better to test this requirement other than to iterate through all the possible scenarios? I'm doing something like this. # Ther...
During Winter Bash 2014, the Naruto hat was awarded to users who gave an answer that got accepted but hasn't received votes for 12 hours. It was a weird thing, really: why would someone ever accept a question but not upvote it? I haven't yet experienced a situation where this would be reasonable. Accepted answers witho...
I have this basic question about the efficient way to sort user-defined object. It can be done in many ways, but most of sorting algorithms at best cases is \$O(N)\$. I have come up with a fair approach to get \$O(N*log(size() + N))\$ by using std::set. Is it a good choice in such a case? #include <iostream> #include <...
I'm new to coding and I am self-taught up to this point, so my scope for creativity is quite limited. As such I'm doing something in particular that I suspect isn't the "best" way of achieving this very simple task. Basically, all I'm trying to do is remove a message notification which pops up after ajax has been perf...
I managed to create a Sudoku generator but I'll just go ahead and say that it generates 1 out of 500 tries on average. I'd say that's pretty inefficient and I'd like to ask you for advice on improvements. Basically what I figured is if I had defined a range of numbers that are possible for each cell, then started selec...
I'm building a search for Magento. Magento API doesn't provide an easy way to look up a customer using a phone number so I created a custom solution. My MySQL/PHP OOP skills are limited. Did I miss anything or is there a better way to do this? <?php DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_USER', ...
I have been running a program to read a file having 6 million rows and validate each line and write the string containing the validation message to an output file. I am using spring integration to achieve that as well as invoking spring batch from spring integration using spring batch-integration adapters. Spring batch...
I am quite new to C#, currently working through a number of pluralSight courses. I've written a few small things here and there, but never anything that performed an entire purpose/function from start to finish, until now, with this app. The app lists all the JPEG photos in an import folder and collects the takenDate f...
I have written my first regex: static void Main(string[] args) { string phoneNumber= Console.ReadLine(); Regex pattern = new Regex("(1-)?\\p{N}{3}-\\p{N}{3}-\\p{N}{4}\\b"); MatchCollection collection = pattern.Matches(phoneNumber); Console.WriteLine(phoneNumber + " is " + (collection.Count == 1 && co...
Based on these guidelines I optimised Bresenhams line algorithm, it now fits for all kinds of line cases like images a, b, c, d, e, f, g, h show in those guidelines. This is my test.txt input file for all line cases: x1 y1 x2 y2 10 10 50 10 10 20 50 20 60 10 60 50 70 60 70 10 80 30 100 50 100 60 80 40 110 60 130 40 1...
We have another team who is going to expose class packages for use to scan and pickup details from. If they should add some new packages or rename old ones I don't want to have to recode a thing. I am trying to get some input on the best way to accomplish that For the sake of maintainability we only want the code for ...
Details Can anyone instruct me on a more optimised way of querying this statistics of registered users? I currently lack the knowledge to create a better query. Right now it works fine, but I want to learn more about other ways to do the same thing and improve on it, this way I can expand my knowledge on MySQL, and st...
I have made a simple C# script that will find the largest palindrome made by the product of two numbers. These numbers will be between a minimum and maximum value, inputted by int.Parse(Console.ReadLine()). Is there a way to make this better? It is brute force, however I tried to make it use fewer numbers if one combin...
The problem is to count all possible sub-sequences of "welcome to code jam" in a given input string (and only return the last 4 digits of the count). Here is the link to the problem for reference. I've implemented a solution in Haskell that worked fine on the examples and small datasets but failed on the large data se...
Problem: Write a function that takes a String document and a String[] keywords and returns the smallest substring of document that contains all of the strings in keywords. Notes: document will contain at least 1 word document will separate words by a single space A word can only contain [a-z] and can appear multiple ...
Problem: dynamically calculate status in MLM only based on a structure. It works correctly but it's so slow. Only test processing takes about 20 seconds. I tried to replace some lists by generators, but it was bad solution, because they have to be changed during runtime. I have no more ideas of enhancements but I'm sur...
I have written code for scanning an N x M matrix in spiral order using a recursive function. It uses 5 parameters - including 2 extra variables: call to keep track of the no. of current call counter to keep track of no. of elements already printed Example: For matrix: 1 2 3 4 5 6 7 8 9 For call = 0: Output: 1 2 3 6 ...
I created the most simple though still quite flexible jQuery slider ever! Or at least, I hope so. var slider = $(".slider-ul"); slider.each(function () { var e = $(this), images = e.find("li"), current = null; slide(); function slide() { images.each(function() { var...
I'm building a RESTful API in PHP using the Phalcon framework. The API will consist of multiple modules (e.g. api.example.com/mail/users, api.example.com/web/users, etc). So I want to put all module specific logic at one place as much as possible. I have a lot of programming experience but PHP is all pretty new to me. ...
I am using this for in loop to loop through a JSON object and to assign the JSON object's value to my own object in a KnockoutJS setup. The JSON object looks like this: [ { categoryId: "013", categoryName: "Toys", id: 2328, name: "Megatron", summary: "", price: 120, extraInfo: { ...
Find the LCA in binary tree, where a node is also its own ancestor. This question is attributed to GeeksForGeeks. I'm looking for code review, optimizations and best practices. public class LeastCommonAncestor { private TreeNode root; /** * Constructs a binary tree in order of elements in an array. ...
Basically, I wish to have 3 printers to print in error state, success state or info state which means nothing but different colors. class ColorCode{ private static $options = [ "dark_gray" => "1;30", "light_gray" => "0;37", "blue" => "0;34", "...
Yes, yet another challenge on CodeEval! This one has the purpose of finding the major element of a sequence: the element which appears in a sequence of size L more than L/2 times. I have this: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Arr...
I have implemented a LinkedList in C#. What would you change/make better? What naming conventions are misused? What would you add? Some of my ideas are to make it thread-safe. using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; n...
Below is my code for a simple console base car game. Is this a good approach or am I missing anything? CarG.h #ifndef CARG_H #define CARG_H class CarG { private: int sleep; int points; int n, n1; char cash, keyp; public: CarG(); void gotoxy(int x, int y); ...
I created a function to test whether a single word string can be a rearranged into a palindrome (doesn't have to be a real word). My logic was if the string has an even number of letters, then each letter must occur twice. If the string has an odd number of letters, each letter must occur twice except for one. functio...
I've been designing a game engine for the past few months with little issues. However, one main goal with this project is to put it on my portfolio/résumé so naturally I want the code to be as good as possible. With that in mind, I got a little worried today because I designed a fair amount of my engine around using ...
My code goes from a class to DataTable, and back again. It populates the class's public properties, or creates DataColumns whose names and types match that of the the class's public properties. It also has methods that allow the developer to go from a query to a populated class, or from a class to an SQL script or SQL ...
The below code is for a simple password encryption/decryption program. The code is working perfectly, but the only thing I want to know from you is if this is good logic. PEND.h #ifndef PEND_H #define PEND_H class PEND { private: char UString[30]; char Password[70]; int key; int ra...
I'm developing an application to manage a player card-library from an online game. Each card has an image that is stored on disk with a numeric code, for example, the card with ID=1234 has his image stored as 1234.png and all the images are stored on the same folder. As of now there are more than 3500 images for a tota...
I'm new to writing VBA and having spent most of the day writing some code, I have finally got it working but it looks horrible. I'm hoping that someone can help me tidy it up. The code simply copies certain cells from one sheet into another. If a particular cell in the source sheet contains the word "Accepted". Columns...
I've written two functions: is_integer(), which tries to get a positive or a negative integer as input and returns the same value. square(), which takes this returned value as parameter and returns square of the same. The code in square() uses a for-loop that squares the integer by 'repetitive addition.' Finally, the...
Objective: A lightweight shell that runs on a microcontroller (MSP430) and parses incoming data into a command and additional parameters. Requirements: Support of quoting in parameters using " Escaping special characters using \ in parameters Ending commands with \r or \n Separating parameters using or \t Sendin...
Version 1: Graph implementation adjacency list 1.0 Please note the following: All edges are directed A user of the class Graph shall never be able to aces an object of type Edge or Vertex Only class Vertex can create an object Edge and only class Graph can create an object Vertex No loops are allowed Maximum one edge ...
I wrote a small scientific simulation where I wanted to manipulate vectors with the same kind of functionality that Python's NumPy vectors use. Namely, I wanted to be able to add vectors together, multiply by constants, etc. I have need for both vectors of type int and floating point, so I wanted to template the overlo...
R does not support line continuation as Python, and it's disturbing to have long file paths like /media/user/data/something-not-very-important-but-super-long/some-curious-secret-file.pdf and can't break it into multiple lines. The workaround is to use the file.path function: file.path( "/root", "folder", "file....
My project is composed of several parts: Repositories, Services, Domain objects, etc in a .NET MVC web application. My repositories handle all data i/o, the services are responsible for CRUD operations as well as other logic, such as getting a count of objects from the database. I am trying to shift from an "anemic" do...
I'm making a calculator that can solve calculations that are inputed in a very raw form. Say: "3*52+11+3/2" I'm using the console, at least for now. This will also take in consideration that multiplications and divisions should be completed first, so 2+3*4 is 14 instead of 20. I wanted someone to see if there are more ...
var addToTeam = document.getElementsByClassName('addToTeam'), parentElement = document.getElementsByClassName('playerTypeBlock'), playerName = document.getElementsByClassName('heading'), totalVal = document.getElementById('totalvalue'), tableBody = document.querySelector('.totalPlayers'); var updateP...
state object - a state or scene from the game. When the start function is called, the state starts rendering, shutting down any other state using the renderer, and calling the specified functions (init, update, etc.) as necessary. state constructor - given an object definitions, it overrides the object's default settin...
Task: Print sum of first 1000 primes. public class PrimeSummation { public static void main(String[] args) { System.out.println(sumFirstPrimes(1000)); } // Calculates the total of the first n primes public static int sumFirstPrimes(int n) { /* Since 2 is the only even prime it is pre-inc...
This was found on CodeEval. Challenge: Write a program that prints out the final series of numbers where those divisible by X, Y and both are replaced by “F” for fizz, “B” for buzz and “FB” for fizz buzz Specifications: Your program should accept a file as its first argument. The file contains multiple separated lines...
I have a structure like this: <a> <b> <c>foo</c> <d>bar</d> </b> <b> <c>baz</c> <d>qux</d> </b> </a> I set /a/b as context and loop through all occurrences to get the texts of c and d: VTDGen vg = new VTDGen(); vg.parseFile("test.xml", true); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPi...
My implementation of generic Tree structure: /** * Tree data structure */ public class Tree<T> { private T value; private Tree<T> parent; protected List<Tree<T>> children = Collections.emptyList(); public Tree(T value) { this.value = value; } public Tree() { } /** *...
Previous question: Text-based Tetris game with CRTP - follow-up 2 Summary of improvements: Fixed Issues preventing the code from compiling on Clang Implemented helper class range_impl Removed all std::initializer_list Elimination of magic numbers How can I improve this code further? Tetris.cpp #include <iostream> #i...
I am reading a large data file where the time is given in number of days since some epoch. I am currently converting this to Python's datetime format using this function: import datetime as dt def days2dt(days_since_epoch): epoch = dt.datetime(1980, 1, 6) datelist = [epoch + dt.timedelta(days=x) for x in days_s...
I am using the following code to copy the contents of two files into one. Earlier I was not closing the Buff and as eclipse gave warnings I did close it. I want to know if this code is susceptible to failure. public void mergeFiles() throws IOException{ ArrayList<String> list = new ArrayList<String>(); ...
Following from this question I created a Image cache of sorts (let's call it version 1.0) that used WeakReference as "cache" items. And this comes from the accepted answer: It looks like weak reference would serve the purpose of what you are trying to achieve [IF] those images will go out of scope (not being directly ...
I have been using the John Resig JavaScript class implementation in my web apps, but the tests shows it is really slow. I really find it useful for the way of extending objects, and the benefits got from having a better code and less redundancy. In some post was explained that it was slow because of the how the _super ...
Here's my function for calculating the volume of a tetrahedron. I've tried to comment well and perform a few checks on the types of the objects passed to it. Can the comments be improved? I'd also like an opinion about my method for checking the object types. Is it better to use assert for this? # eg9-tetrahedron.py im...
This code is used to toggle buttons within a div: var chosen = {}; var form_name = 'the_div'; function(what) { if('number' != typeof what) { // toggle-one var el = $(what); var name = el.html(); var ch = ['success','default']; if( !chosen[name] ) ch.unshift(ch.pop()); el.remov...
These functions work well for me. Can they be improved or made more standard in some way? Each function has a documentation header block, which contains a description of what it does, along with example usage and reference links where applicable. :<<COMMENT Alias function for recursive deletion, with are-you-sure p...
I am learning CoreData and I wanted to have my code reviewed. As usual, I get something to work, then I attempt to refine it. I have a data model that consists of an Item entity and a subItem entity. The Item has a 'to many' relationship with the subItem and subItem has a 'to one' relationship with Item. Basically I...
I am declaring a "class" using a "constructor method". In both samples, properties uuid and dateCreated are initialized but in different places. I would like to know the "best practice" in this scenario and why (also in terms of readability). Solution A define([ 'dojo/_base/declare', 'dojo/_base/lang', ], func...
I am working in C# to write a scheduling application for operations in a factory. I have a custom class Workday, with properties to represent a Workday for the operations in the shop. I also have a class Timeline that contains a dictionary of DateTimes as keys (using DateTime.Date to make sure we don't have two Workday...
I've built the groundwork for an attributes (as in Strength, Intelligence, not as in DebuggerHidden, TestMethod) framework for my game. Each attribute can be upgraded and downgraded individually as well as part of a bulk change (such as for upgrades that have side effects, or leveling up). I'm looking to get a thorough...
Given my IUnitOfWork interface using System; public interface IUnitOfWork : IDisposable { void Commit(); } I then create an abstract factory interface called IUnitOfWorkFactory using System.Transactions; public interface IUnitOfWorkFactory { IUnitOfWork GetUnitOfWork(IsolationLevel isolationLevel); } I ...
I am learning to code in the Assembly language for the x86 architecture. I currently know of a few registers and certain arithmetic operations like add, sub, inc, dec, mov and to check for conditionality using certain jump statements. I am using some "ready-baked" code for input and output. The input - call_hex reads h...
I got it working, all variations are displayed Sint-Anna as should be, but I wonder, is there a simpler way to this, since it looks very cluttered? String.prototype.capitalize = function(){ var sa = this.replace(/-/g,' '); var saa = sa.toLowerCase(); var sb = saa.replace( /(^|\s)([a-z])/g , function(m,p1,p2...
I saw this implementation of Least common ancestor and thought that it was very inefficient as it used Queues. I have tried to implement it using a normal tree traversal. I have also tried to keep all the utility methods as public static so that they could be accessed from anywhere. Is the implementation correct? I hav...
The objective of the two classes below is to manage a collection of records where the record structure (i.e. the fields that comprise the record) is variable and defined at run-time. The record structure may contain integers, amounts, dates and strings. The RecordDefinition class is used to define the record structure...
Zombies are questions with no upvoted answers. I came up with this SEDE query to find answers with zero votes on questions that have no accepted answer and no answers with greater than zero score. In other words, answers on questions that show up on the Unanswered tab, until the answer receives an upvote. (Latest versi...
This is a follow up to Rolling my own Configuration with UI. I got a lot of great advice about the Configuration system I created, but no one touched on how all of my logic for the UI was in the code behind of the control. I decided that it was a bad idea, and took a stab at the Model-View-Controller pattern. Mostly, b...
I have two matrices (a, b), each including 3 genes and 6 observations. I have estimated the Spearman correlation for gene pairs (rcorr.observed). Then I want to do an empirical permutation (1000 times) and estimate the correlation for each time, then achieve a Pval_estim file. Since I have a very huge datasets (23000*2...
I have a method to upload a file using the Net::SFTP gem: class Uploader def initialize(host,user,password) @host = host @user = user @password = password end def upload(local_file_path,remote_file_path) Net::SFTP.start(@host,@user,:password => @password) do |sftp| sftp.upload!(local_file_path,remote...
A = [9, 1, 4, 2, 5] k unique integers B = [3, 1, 8, 7, 6, 5] n unique integers Intersection => [1, 5] Find an algorithm that uses \$O(1)\$ space (the space used by the return variable is not considered) and runs as fast as possible to find the intersection of the arrays. private static List<Integer> getIntersec...
I've created a Timecode class. The "timecode" that I'm trying to represent is a timecode that is used in video editing quite often, and is seen displayed in the format "hh:mm:ss:ff", or 10:00:05:24, for example ("ff" = frames"). /// <summary> /// Immutable timecode. /// </summary> /// <remarks> /// Rep...
I have the following code that checks the value of a variable and then applies the correct id attribute accordingly. The value of menuLink will have the same value of one of the parts of .mainmenu a href path name. Is there a way to simplify this so it can search the href path of .mainmenu a instead of explicitly stati...
I have just written a function copy_lowbits_off to copy any number of bits (not bytes) from a source buffer to a destination buffer. The function also supports arbitrary offset (expressed in bits) in the source and the destination buffer. Could you have a look at it and let me know if anything can be improved in style,...
A while back, I posted a question involving code of the same function. This post contains improved code. From the last post, I have improved size, my work with conventions, and my comments. I was also able to minimalism memory interaction to speed things up/make things more efficient. %define KERNEL_CALL int 80h %defi...
The program is asking you to guess a number between 1-100 and if you guessed too low it says that in Swedish and the same goes for if it's too high and if it's the correct answer it says congratz you guessed right in Swedish. I'd like comments about any aspects of my code. public class Kidsprogram { public static v...
This just opens all drawing files in solidworks and saves as a *.pdf file. I just wanted to to get a second set of eyes on this before I let it go on the actual drawings database (i.e. all our files) and hopefully make sure it won't encounter any errors. using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swcon...
I'm trying to program a volatility updating rule using iteration. I start with the well-known Heston-Nandi model where the returns dynamics are: $$ \left\{ \begin{array}{rcl} R_{t+1} &=& r + \gamma h_{t+1} + \sqrt{h_{t+1}} z_{t+1}\\ h_{t+1} &=& \beta_0 + \beta_1 h_t + \beta_2\left(z_t - \beta_3 \sqrt{h_t}\rig...
I have developed a simple weather application that provides the current weather report based on the city provided by the user. Can anyone help me to improve this code? MainActivity public class MainActivity extends ActionBarActivity implements OnClickListener { TextView lblLocation, lblTemperature, lblPressure...
Is it possible to optimize this solution to the N-queens puzzle? #include <iostream> #include <cstdio> #include <cstdlib> #define N 10 using namespace std; /* print solution */ void printSolution(int board[N][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) cout<<board[i][j]<...
Is it better performance or not to call one of two separate functions in response to an if statement over passing an argument to a function? And, what are the performance implications? My first function checks for the existence of a cookie: function checkCookie() { var accept=getCookie("_cmci"); if (accept !==...
There's some repetition in here. I tried making it into a function but then the response wasn't filling up the #project-container div. Is there a way to condense this code to make it more elegant? // Activate projects $('.post-link').click(function(e) { e.preventDefault(); var post_id = $(this).attr('rel'), ...
In my previous question, I got heaps of good advice BUT no solution for the problem apposed. I applied the valuable learnings from the past on this.question and am also hitting it from a different angle. The second part is the reason I didn't mark the question as 2.0 version of the first but feel free to let me know ho...
In the game of Narcotic Solitaire, played with a standard 52-card deck, the player deals a row of four cards onto the table, from left to right. If all four cards are of the same value, they are removed from the game. If two or three cards are of the same value, they are moved on top of the leftmost card of that value....
I have an IRepository class that I use a lot. But I noticed that for many of my repositories I do not implement most of the methods. Also, I usually don't have a TKey that I want to specify if I'm not using the GetById method but the current design forces me to specify it. I was thinking of changing the interface o...
The following code interweaves two linked lists together in three flavors: iterative, recursive top-down, and recursive bottom-up. My iterative solution feels like it can be optimized better and my bottom up recursive design skills are not necessarily the best (although this solution is a much smaller task than most re...
I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation. class Theatre COST = { running: 3, fixed: 180 } attr_accessor :number_of_audience, ...
A few days ago I decided that I wanted to get involved with libgdx. So far I'm blown away by how simple it is to get something on the screen to work with. I'm trying to make a very simple tech demo where stars fall from the sky that can get collected by a player controlled cloud. Stars that get not collected will be le...
I am aware that most 'generic' BFS algorithms that use a queue also check for uniqueness of visitation to 'speed things up' as it were, but I'm a bit unclear as to how to implement such a method as I'm still a newbie to graph theory. Beyond any general critique, I am curious about how I can modify the iddfs_queue() fun...
This is a follow-up of: Very basic shell on microcontroller in C A few days back I've asked for a review on a simple shell parser in c. Based on the answers, I've restructured my code to use a table-based Mealy machine. shell.h #ifndef SHELL_H #define SHELL_H #include <stdio.h> #include "usart.h" #include <string.h> #...
I've been doing some JavaScript for fun again. This time I tried my hand at drawing the Dragon curve - a neat fractal that consists of one line traveling across the plane, never crossing itself, and creating an interesting shape in the process. There's several ways to go about generating the Dragon curve; for instance,...
I needed to convert a formatted file size back into its length in bytes. I came up with the following code but want it reviewed: /** * Converts a formatted size to its equivalent in bytes. * * @param size * The formatted file size. Examples: "125.5 MB", "1KiB", "0.8 GB" * @return * @throws NumberForma...
I have defined the tag that can sit on all the pages of my website and be easily integrated into the admin tool. It is the broadest category with properties that are relevant for all pages. Can you please tell me if it is written correctly? I am concerned that the URL code line might be picked up as a circular link and...
I wanted to learn how to create awesome parallax scrolling effects so I decided to look up how to do it, after some searching I put together this test. It works fine to some extent but it feels a bit messy, especially if you would expand it with more effects and elements. You can see it in action here (had to replace ...
I'm trying to learn how chained hashing works, but can't get any further than this. I think hashing works, but after finishing this little program, someone told me that what I have created so far has nothing to do with hashing. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> #d...
I am taking an algorithm course and we are to implement merge sort that handles list of elements with even or odd number of elements and handles duplication, so I wrote this function: void mergesort (int* list, int len) { if(len == 1) return; int i = len/2, j = len-i; int list1[i], list2[j]; ...
I have a small UI that involves adding roles and modules to a user database array. The interface works as is, no problem at all, but it seems to have a bit of 'duplicate' code that I was hoping I could get some advice on ways to refactor, if at all possible. JS and Knockout function Db() { var self = this; se...
This code is supposed to find, in a graph, the node with the smallest maximum distance to all the other nodes. The problem from Quora is : How do I find the node that has the least maximum distance to all the other nodes in a tree? "So you're thinking about moving into an unknown city. You have been given a map of...
I want to wait for a line to be read, but only for so long before timing out. This is what I came up with. Is there a better way to do it? Dim reader As New System.IO.StreamReader(pipe) Dim nextCommand = Await New Func(Of Task(Of String))( Function() Dim t = reader.ReadLineAsync() If (Not t.Wait(...
The koan is at the end of this snippet. It requires you to write a function to convert a map to a string, and then prepend a full name to it. The following solution works fine. I am just wondering if there are simpler or more efficient ways of doing the same thing. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ...
I came here to ask if there is a way to prevent already guessed guesses from being guessed again in my brute-force Java program. Basically I used a rand.nextInt in my program but the program will guess already guessed passwords again even if they were incorrect. How could I prevent this as it wastes time and processing...
I am working on a 2D tile based platformer and was hoping to get someone to review my collision detection. I've only included the X collision check since the Y is essentially the same. Any suggestions/criticisms are appreciated. // Corrects X movement if a collision occurs. private void checkXCollision() { ...
def current_active_role user_roles.each do |r| if r.is_active_role return r end end return nil end The block above returns whatever the user's currently active role is. There are User, UserRoles (lookup table), and Roles tables. I'm looking for a more concise way to say "go throu...