instruction
stringlengths
71
71.9k
Description of Kadane's algorithm. Please comment on the efficiency and approach. class Kadane { int sum = 0; int max = 0; public static void main(String[] args) { int[] full = { 1, 2, 3, 4, 5, -6, -77, 3, 14, -10 }; Kadane Kadane = new Kadane(); int max = Kadane.splitArr(full); System.out.println("The...
I understand that because of JavaScript's single-threaded execution, long loops or recursive calls could make the browser unresponsive while they execute. I thought about simulating recursion using setTimeout with a delay of 0, so as to queue the next call to execute as soon as possible. Here's an example comparing a s...
I have two classes with similar first checking codes, but different behaviors. I suppose there is a way to refactor the code, so I don't need to retype it every time. Is it possible to refactor this, or I must retype this code every time? # Get actual logged user user, msg = checkLoggedUser() if user: self.renderP...
Does this code look okay? #include <stdio.h> #include <ctype.h> int case_letters(); int main(void) { case_letters(); return 0; } int case_letters() { int ch; int numOfUpper = 0; int numOfLower = 0; printf("please enter a some characters, and ctrl + d to see result\n"); while ((ch ...
What I'm trying to accomplish here is to pull a table of open employment positions with AJAX, filter out the garbage code that comes with it, put each <tr> from the response into its correct category <div> according to the type of position. The trick is that there are no ids or class names on the <tr> being pulled mak...
I'm trying to create daily, monthly and weekly SQL Query report to our services time we spent int task and total billing time just want to see if I'm on right track GO --Daily SELECT SUM(billingsTimes.actualTotalTime) AS TotalTime, Tasks.taskName, billableType.billableTypeName FROM billingsTimes INNE...
I wanted an elegant way to implement memoizing. Here is what I came up with: function memoize(fn) { var cache = new WeakMap(); return function() { if (!cache[arguments]) { cache[arguments] = fn.call(this, arguments); } return cache[arguments]; } } It's quite nice, but th...
My intent is to use Bash functions defined in functions.sh in a C program. I am doing this so that I don't have to rewrite the Bash functionality again in C. I want to use one common library for functions I need. Here is my C code and functions.sh. #include <stdlib.h> #include <sys/wait.h> #include <stdio.h> void shel...
For the past few days I've been working on a AES-128 encrypt/decipher class. I needed something very scaled down from Cryptolib so that I didn't have to constantly import the .lib file on all my programming computers (work, home, laptop1, laptop2). I've decided that since I will only every use AES-128 for one my progr...
I created a Letterpress solver that will take a string of letters and return a list of valid words that can be constructer with the provided letters. Not all letters need to be used in each word. This works by reading all words into a list named dictionary, transforming that list of words into a map, letter-permutation...
I'm learning Node. I'm working on a personal project that uses Node + Express + Node-MySQL + Generic-Pool (for MySQL pooling). I am new to the idea of module.exports and I'm still grokking it. The following code works. However I want to organize my code in a way that is logical and optimal, and MVCish. I am wonderi...
How to get rid of that duplicaiton in if conditional? def set_caption(result) if result.respond_to?(:app_name) content_tag(:div, result.type_name, class: 'type-name') + content_tag(:div, result.app_name, class: 'app-name') else content_tag(:div, result.type_name, class: 'type-name') end end
I am writing a JavaScript/HTML driven web application. For the user interface, I am not completely sure that my JavaScript is 'OK'. Mainly, I switch between "modes" by assigning a placeholder variable to a new function, which changes what the onclick event does for items in a table (either open, edit, or move them). Am...
This is my code: #include <stdio.h> #include <ctype.h> int average_of_let_wor(); int main(void) { double answer; answer = average_of_let_wor(); printf("%.2lf", answer); return 0; } int average_of_let_wor() { double numberOfLetters = 0; double numberOfWords = 0; int userInput; double ...
Is there any way to simplify this code with loops or anything? I'm a beginner at JavaScript and my code is horrible. Please don't tell me to convert to jQuery or anything. function dragLeftdropLeft1(ev) { ev.preventDefault(); var data=ev.dataTransfer.getData("Left"); document...
I've a web form that allows users to create clusters of three sizes: small, medium and large. The form is sending a string of small, medium or large to a message queue, were job dispatcher determines how many jobs (cluster elements) it should build for a given cluster, like that: # determine required cluster size if cl...
Below is the code for knowing all the prime factors of a number. I think there must be some better way of doing the same thing. Also, please tell me if there are some flaws in my code. def factorize(num): res2 = "%s: "%num res = [] while num != 1: for each in range(2, num + 1): quo, rem ...
I am writing a program that will deal with formatting the text in a text area. The user will use Ctrl + A, Ctrl + C to copy the entirety of a web page, then paste that text into a text area. The program will take the text area, remove the junk, and output the important information to then be copied and pasted into a d...
Matlab profiler throws this horrible bottleneck which is called 700000 times: for k =1:model.nlf, for r =1:model.nlf, KuyDinvKyu = zeros(model.k,model.k); for q =1:model.nout, KuyDinvKyu = KuyDinvKyu + model.KuyDinv{k,q}*model.Kyu{q,r}; end if (k == r) model.A...
I've written a framework in MVC. I call it Midget MVC, as it's so darn small. The reason I wrote it is because I wanted a lightweight and extensible framework to use in projects. It eventually got abandoned due to it's break-ability and my lack of experience in the subject. However, I've got a bigger project I'm workin...
def divisible?(n) if n % 1 == 0 && n % 2 == 0 && n % 3 == 0 && n % 4 == 0 && n % 5 == 0 && n % 6 == 0 && n % 7 == 0 && n % 8 == 0 && n % 9 == 0 && n % 10 == 0 && n % 11 == 0 && n % 12 == 0 && n % 13 == 0 && n % 14 == 0 && n % 15 == 0 && n % 16 == 0 && n ...
I put this together and it seems to work. 1channel.py -breakingbad 1 The Output (1-10): (1) - Currently 3.80/5 (2) - Currently 3.50/5 (1 opens the link in browser) If anyone has any suggestions or wants to improve it: from bs4 import BeautifulSoup import urllib2, sys, webbrowser def Work(tvshow): print "\n[*...
My question is really simple. Does this code cause memoryleaks? If so, where/how/why? HDC hDC, memDC = 0; HBITMAP hBMP = 0; HBITMAP hOldBMP = 0; PAINTSTRUCT PS; HBRUSH hb212121, hb141414, hb070707, hb000, hbF7F7F7, hb989898, hb707070, hb494949, hb984921 = 0; HPEN hp353535 = 0; case WM_PAINT: hDC = BeginPaint(h...
I'm working on my first web app and would like some feedback on the code I have completed. I asked for a similar code review a few weeks ago but I have since improved my structure and added some user adjustable settings. The app is a simple math quiz (addition, subtraction, multiplication, & division questions) where u...
I'm brand new to AngularJS. I would like advice as to whether I'm approaching the design of a simple login section of an app built with Angular correctly. The app consists of two view partials: login.html and user-admin.html. Of what I have so far, the user types their username into the login page. A controller checks ...
I would really like some advice from any DB gurus who have a few minutes free. After doing some reading and playing with sqlfiddle over the weekend I have constructed this PostgreSQL schema and it is the first proper one I've ever done, so I am sure I've made some poor choices. This is what I've got for a "job" and "ad...
My conditional code here seems repetitive and long. Is there a better approach? I want to test for a string value in a NSDictionary object and then depending upon the value prefix a UILabel with $, £, ¥ currency symbols. I've just shown 2 examples below. I have more currencies and the code is very long. if ([[item obj...
I have to do some encoding and then assign the result to a label. Is there a more optimal (or concise) way to write this? // encoding fix NSString *correctStringTitle = [NSString stringWithCString: [[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding] ...
I wrote a program to find the longest common subsequence among several strings. I used a naive algorithm and implementation. The motivation was solving the Rosalind problem at http://rosalind.info/problems/lcs/ . You can find sample input there as well. The Rosalind problem concerns strings as DNA, but I think my code ...
I am writing an audio engine that must be multi-platform (win/linux). Basically, a CSound represents a sound file, and CSoundInstance represents one playing of a CSound. Obviously, playing sound is very different on Windows than it is on linux. A CSoundInstance needs access to some data from its corresponding CSound. T...
To delete a key from a trie, there are four cases: For the explanation of trie data structure, please check the following link: http://www.geeksforgeeks.org/trie-insert-and-search/ (1) Key is not in the trie. (2) Key present in the trie as a unique key. (3) Key is the prefix of another longer key. (4) Key presents i...
This is a simple program that gets a number from a user and calculates the number of primes between 3 and the user's number. I'm just curious if I'm using too many variables. I'm only asking since I'm used to not needing to initialize iterator variables before a loop. #include <iostream> using namespace std; int isPrim...
I am learning OOP using PHP5 and I wrote two simple classes for receiving data from a database using the dependency injection pattern and rendering a grid with Twig. Does this code have sense for OOP logic? index.php <?php /* * Remplazar con autoload */ require_once 'class/class.db.php'; require_once 'class/class...
My HTML has three divs, each id tagged with the logic behind my object (ma/shadow/traps) which contain 10 div each (every icons), also ID-tagged according to the object. On click, I'm gathering the ID and the parent ID to traverse the object and find the value. It's only possible to raise the value if the pre-requireme...
I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, as it could be. The former is really what I'm trying to address here. I feel this can be done much more elegantly and w...
Looking for feedback on how to better improve the code below to simplify the code below. var animateTop = $('body'); if ($('html').hasClass('lt-ie9')) { animateTop = $('html'); } $('.var').on('click', function() { animateTop.animate({ scrollTop: $('footer').offset().top }, { queue: false, du...
I am in two minds about function calls as parameters for other functions. The doctrine that readability is king makes me want to write like this: br = mechanize.Browser() raw_html = br.open(__URL) soup = BeautifulSoup(raw_html) But in the back of my mind I feel childish doing so, which makes me want to write this: br ...
I am using this static method in my class IconManager to read an image from jar file. imagepath is a relative path to the image. This code works perfect. But I was told it is error-prone, because does not handle Exceptions correctly. private static BufferedImage readBufferedImage (String imagePath) { try { ...
since in my website I have a lot of <HEADER>, <FOOTER> AND <SECTION> do you think is appropriate if i use a .main class for the main HEADER, main FOOTER AND main SECTION? In the CSS I will never style the .main class like this: .main { ... } but always like this: header.main { ... } footer.main { ... } section.main { ...
I get a lot done with Python scripts but always feel like I'm working with a messy desk when I'm using it. I assume this is because I am not coding in Python correctly. Coming from a C# and Ruby background, I've used Python mainly as a utility language writing together things that I need quickly - never really trying...
Question from Skiena's Programming Challenges. Getting WA (wrong answer) in Online Judge even though it's working for sample test cases. Can somebody find a case where it fails? I tried the tricky case from this link and it gave the right answer- "The Trip" challenge from Programming Challenges Input Standard input wi...
I'm new to TDD, never used it ever. I understand the basic concepts but I'm now working on a small project which will be the first time I've ever actually used TDD. The code is pretty self explanatory, it's a simple user data storage class. I've written an interface, a UserData class, and then implemented the interface...
Ok, so I started to build my own CMS. You can see Aleksandar Golubovic's Blog,and I need your help. Please, look at my code, and tell me is that safe? You can download current version from Twitter Bootstrap CMS. If you want to install it, just read instructions. So, please, tell me if I get some errors, or some of your...
I wanted to implemented an algorithm in Python 2.4 (so the odd construction for the conditional assignment) where given a list of ranges, the function returns another list with all ranges that overlap in the same entry. I would appreciate other options (more elegant or efficient) than the one I took. ranges = [(1,4),(...
As the title says, I'm looking for a better way of writing the following PHP function as it's a very very long one. It's part of a bigger class and I'm trying to keep the amount of code as little as possible. The reason why I needed so many cases is because the function can accept all kinds of arguments in different w...
My task was: Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes u...
I am a newcomer to design patterns. I read some articles about the abstract factory pattern, and wrote the following simple example: public interface ParserFactory { List<ITransport> getBusList(); List<ITransport> getTrainList(); List<ITransport> getPlaneList(); } public abstract class XMLParserFactory im...
I'm writing a WPF application and I have several ReadOnlyObservableCollection fields in my models. Suppose that I wanted to create a FooViewModel instance for each FooModel instance. FooModel has an observable collection of BarModel, and FooViewModel should contain a (read-only) observable collection of BarViewModel. I...
You can see the JavaScript at the end of this post in action here. I've recently picked up JavaScript/jQuery and would love some feedback on how I'm implementing this functionality. As you can see, the li items in the navbar change based on where the user's scroll position is. Is this an efficient way of implementing t...
I've been experimenting with the Express Node.js framework. On the face of it, the approach of passing functions to app.VERB methods seems unusual. In other frameworks I've used (in languages other than javascript), you create a single handler class for each url pattern, with methods representing different HTTP verbs. ...
I need to get from an array of booleans to a Flags enum. Here's what my enum looks like: [Flags] public enum UserContactPreferences { None = 0, SMS = 1, Email = 2, Phone = 4 } Here's what my parsing code looks like currently. private UserContactPreferences GetContactPreferences(bool email, bool phone, bool sms) { ...
Im currently working on a system that will communicate with other systems via webservice (or some sort of communication). I have a system that stores all user data already and don't want to duplicate data in this new system so I have come up with a way of accessing the data when needed. In my current system I am plann...
I needed a task scheduler that could be used somehow like this: #include <iostream> // To compile and run this example, include here the code listed in the second code block void Task2() { std::cout << "OK2 ! now is " << std::chrono::system_clock::now().time_since_epoch().count() << std::endl; } void Task3() { ...
I implemented this Agent class for a project recently and was wondering if I could get some other eyes to look at it -- I'm currently the only developer where I work so I can't exactly ask someone here to do it. I'm pretty sure it's correct, but then I'm too close to it. public abstract class Agent<M> : IDisposable { ...
Posted my question here. Here is the full code: 'buy a blank deck of cards 'declare variables dim defaultDeck(51) dim trueDeck(51) dim isUsed(51) numPlayers = 1 numCards = 12 intMyHand = 0 '0 through numPlayers-1... highest number is dealer Set objStdOut = WScript.StdOut 'put values on the blank cards: i=0 for suit...
I my class hierarchy looks like this: P I : P O : P I have this method. The goal of this method is to return a new object of type I or O depending on a certain condition. public P GetP() { this.Session.Begin(); var pDetail = GetPDetail(); if (pDetail == null) { this.Session.Close(); ...
I'm trying to make a sprite cache for SFML sprites. The basic idea I got was to use a map of an enum and a sprite pointer. Then when I would ask for a certain sprite I'd have a manager that would check if the pointer for that sprite is null. If it is, then it would create a new sprite object and clip it to fit what it'...
Checklist from FAQ for proper posting. Does my question contain code? - YES Did I write that code? - YES Is it actual code from a project rather than pseudo-code or example code? - Strait from actual code, minus a few functions that do not apply to the Q To the best of my knowledge, does the code work? - T...
I did this program and I need to make sure I did it right. The answers come out to be right but I want to make sure nothing is wrong with the coding. class RecursiveMethods { RecursiveMethods() //default constructor { } public int fOf(int x) { if (x <= 10) //...
I just started Java programming yesterday (so don't expect too much), and I've written some code. My code works the way I want it to work, but there are obviously things wrong with it. I was wondering how it could be improved. I think I've added unnecessary things. I'm practicing using classes and other stuff. testing....
As a fairly new C# programmer I am a unsure about when and how to best make use of LINQ (and also when to choose the expression method syntax vs. the query syntax). This question often comes up for me at work, because I heavily lean toward making full use of new language features and a functional style, while my collea...
I have some code that uses a multidimensional look-up table (LUT) to do interpolation. The typical application is a color space conversion, where 3D inputs (RGB) are converted to 4D (CMYK), but the code is rather general. The look-up table is a numpy array, which will generally have a shape like (4, 17, 17, 17). Here, ...
I am looking for a memory efficient python script for the following script. The following script works well for smaller dimension but the dimension of the matrix is 5000X5000 in my actual calculation. Therefore, it takes very long time to finish it. Can anyone help me how can I do that? def check(v1,v2): if len(v1)...
Here's my attempt at Project Euler Problem #5, which is looking quite clumsy when seen the first time. Is there any better way to solve this? Or any built-in library that already does some part of the problem? ''' Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 ...
OK, I've been playing with D for a while (and been in love with its expressive power and simplicity, to be honest). However, since I'm still new to D, I'm facing a few issues. Let's take the following example. All the following program does is to take numbers in the 0..10000000 (fairly big one, for benchmarking purpose...
I've written a program that calculates the best rational approximation for e with a 1, 2, 3, 4, 5, and 6 digit denominator respectively (on Matlab). For a 5-digit denominator it takes about a minute. For a 6-digit denominator it takes 2 hours. I've tried to improve the code, but I am a beginner. Suggestions are kindly ...
I have a situation where I would like to use a single QThread to run two (or more) separate methods at different times. For example, I would like the QThreadto run play() sometimes, and when I am done playing, I want to disconnect the QThread.started() signal from this method so that I may connect it somewhere else. In...
I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many). Input.readInt() is a method I made which simply reads an integer from the command line and returns it. There are a few things I'd like to improve - for the average the flo...
I do a single select in one radgrid, and based upon that selection I want to select multiple rows in a different radgrid: <telerik:RadGrid ID="rgPaymentLines"> <ClientEvents OnRowSelected="RowPaymentSelected"/> ... </telerik:RadGrid> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javas...
I am working on a way to quickly build JSON strings in Java. To this end, I have created the following two files. Assuming that I do not need to parse JSON strings for Java, is this an efficient implementation? Furthermore, are there any cases where it would output an invalid JSON string? JSONList.java: public class JS...
I have the following code, but it somehow looks a bit redundant. As I am new to ColdFusion, I am not sure how to optimize it. Can someone suggest an alternative? <cfparam name="url.idInfopage" default="0"> <cfif not isNumeric(url.idInfopage)><cfset url.idInfopage= 0></cfif> <cfif isDefined("stElement.idInfopage") and...
I have created this simple code: For the size of an array with 2 values (n and m), verify if n and m are >= 1. m = width and n = height. The code works but I'm sure it isn't optimized. printf("Number of ligns."); scanf("%d",n); printf("Number of columns."); scanf("%d",m); if(*n >= 1) { if(*m >= 1) { ...
This is the first time I've written JavaScript in this way (previously all I've done mostly is DOM manipulation and form validation in vanilla and jQuery). I've begun working on a basic Pong game. It's currently unfinished, but before I continue, I'd like to get some feedback from experienced JS developers: Full codeba...
This is my first attempt at reading the contents of a file consisting of strings separated by a null character. vector<string> CReadFileTest::ReadFile( const char * filename ) { ifstream ifs(filename, ifstream::in); if (ifs) { vector<string> list ; while (ifs.good()) { s...
I started taking a look at a programming challenge I had read about earlier today on 8thlight. Unfortunately, it seems to have been taken down and all I could remember about it was the problem posed: Given an array of integers, find the maximum sum of contiguous values (a sub-array). I wanted to tackle the problem fro...
I'm looking for a general review of a generalized linear interpolation table. Design decisions, anything that's missing, anything that could be clearer or simplified, any style considerations. Keep in mind that I've tried to keep this C++03 compatible, so no recommendations for using C++11 features please. linear_table...
I am writing a program which calculates the scores for participants of a small "Football Score Prediction" game. Rules are: if the match result(win/loss/draw) is predicted correctly: 1 point if the match score is predicted correctly(exact score): 3 points (and +1 point because 1st rule is automatically satisfied) Sco...
I need some advice off the back of a question I posted on StackOverflow. I'm a procedural PHP programmer and I'm looking to make the move into object oriented PHP. I have started a small project that basically acts as a small CMS that allows me to separate my website content from the actual structure of the page. The c...
I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class, public static class FileHelper { public static void ExtractZipFile(Stream zipStream, string location) { .................................. } public static void CreatePa...
I was hoping someone could give me some feedback on my code. I am still new to php and I'm sure I have messed up somewhere. The code pasted is for a registration page where users will submit their information which will then be posted to the database. <?php> include 'PasswordHash.php'; $sql = new mysqli('localhost', ...
I am trying to create a multiway tree with the following code in C++. As of now, it is more like a sample piece of code. I wish to do the following with this piece of code(and I am able to get the desired result): Create a struct Node of two members : value(of the node) and array of children of the node. Make 'root's ...
I have made a function which calculates the index of a point to which an arbitrary point on a polygon made of XY points belong. This is a visual representation: And this is the function I made: stock GetNodeIndexFromPolygonIndex(polygonid,Polygon_Size) { new polid = (polygonid - (polygonid % 2)); new mid = Pol...
My overall challenge and why this code was written was to compare two strings. One string being a description of a item in inventory and one string being a description of a item, but possibly truncated/missing some characters. I am trying to match up the items I have posted on Craigslist and the items I think I have po...
I'm new to Lisp and I'm yet to wrap my head around the lisp way of writing programs. Any comments regarding approach, style, missed opportunities appreciated: In particular, please advice if I build results list correctly ((setf merged-list (append merged-list (list a)))). ;;;; Count inversions (defun small-list (list)...
I have a simple form validation script. Could you tell me how I can improve this script (mainly regarding security)? HTML page <form name="input_form" action="process_form.php" method="post"> <p> <label for="name">Name</label> <input type="text" name="name" id="name" maxlength="25" /> </p> <p> ...
I have this piece of code to replace current text inside an array of html divs with values coming from a JSON file: $.each($('.something'), function(){ if($(this).text()=="1"){ $(this).html(jsondata.CameraTypeLabel1); }else if($(this).text()=="2"){ $(this).html(jsondata.Camer...
I'm just trying to learn how to write jQuery better so I wanted some smart peoples opinions. The code is checking the billing and shipping address fields to see if it contains a PO Box address by looking for variations of "PO" and then displays a warning message after the input if it does contain it. The code is duplic...
Suppose User and Item are two models, and User has many Item. Both models are derived from the parent Model class. In order to retrieve the list of all items a particular user has: $user = new User(100); // User with ID = 100 $items = $user->getItems(); Now suppose that there are two tables in a database, use...
I am creating a simple template engine that uses Regex to find special expressions, which are parsed and processed. They are enclosed in Ruby-style opening tags and have the format: <% label %> OR: <% function(arg1, arg2, arg3) %> However the problem is that I cannot have multiple entries on the same line, so...
I have two classes, Database and Logger. Database is responsible for handling SQL queries, and Logger logs messages to an external file. Whenever the database executes an SQL query, I want Logger to log it. Right now my implementation looks something like this: class Database { public function query($sql) {...
I've started learning .NET with MVC 4 in C# and I built a basic application to display records from a MySQL database. It's incredibly basic, but it's the best I could come up with being a complete beginner to C# and all. Most of the programming I do is with Ruby on Rails and I tried to carry over some of the design pat...
I have decided to create a simple Option type for C#. I have essentially based it on the Scala's Option. It was mostly a fun exercise, but it might come in handy at work or any other project, even though it's less powerful than the Scala version. Now I'd appreciate all remarks regarding this little piece of code, but e...
Is there a better way of creating this terminal animation without having a series of conditional statements (i.e. if ... elif ... elif...)? import sys, time count = 100 i = 0 num = 0 def animation(): global num if num == 0: num += 1 return '[= ]' elif num == 1: num += 1 ...
I know i have some real problems with the following code (as others said). can you please help me to optimize it a little bit? Maybe some example of how to do it. (find the longest repeating substring with length between x and y) public static String longestDuplicate(String text, int x, int y) { String longest ...
For the sake of learning JavaScript better and getting used to the Google Chrome Extension API, I'm currently writing a little Chrome extension. To keep things simple and being able to make use of prototypal inheritance, I decided to write a little instantiation/inheritance helper before I get started. But as I am stil...
I'm trying to optimise my implementation of a static kd tree to perform orthogonal range searches in C++. My problem: The code performs slowly even for a small number of queries when the number of points is around 105. I've constructed the tree based on this (i.e, It's a static kd tree where the data is stored both in ...
Can anyone please tell which one is the more effective way to write C# code, among the two options below? Option A: internal static string GetLast3Years() { return (DateTime.Now.Year - 2).ToString() + "," + (DateTime.Now.Year - 1).ToString() + "," + DateTime.Now.Year.ToString(); } Or option B: internal static stri...
I'd like to find a way to do what this method does in a cleaner, less hacky looking way def self.create_from_person!(person) spi = new(:person => person, :provider => person.provider) spi.age_eligible_code = participant.age_eligible?(person) ? 1 : 2 spi.county_of_residence_code = participant.psu_county_el...
I'm working on a javascript intensive user-interface application. (At least it's intensive for me, it's my first serious javascript project). I have a few jquery functions going whenever a div is rolled over or mouseout. For example there are some divs which are draggable objects, and so when they are mouseovered, the ...
I'm currently changing some legacy code over to PDO. The below code works, but not 100%. I would like to know if it's best practice or if anything can be done better. //Database Array $config['db'] = array( 'host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'local'); //New...