instruction
stringlengths
71
71.9k
I want to toggle button visibility based on values a user selects within a group of checkboxes. For example, the user may be given a group of checkboxes with colors: <input type="checkbox" value="red">Redbr> <input type="checkbox" value="blue">Blue<br> <input type="checkbox" value="green">Green And the available v...
I hope I've asked this in the right area. I'm writing a program that deals with enqueueing a class on STL queue in C++. Initially it queues initializations of the class. Then while the queue is not empty, it performs some operations on the class and then checking if an inequality works it either pops the queue or passe...
I have these two methods: public static String buildLine(String[] values) { StringBuilder lineBuilder = new StringBuilder(); for (int i = 0; i < values.length - 1; i++) { lineBuilder.append(values[i]).append(SEPARATOR); } lineBuilder.append(values[values.length - 1]); return lineBuilder.toSt...
Recently Torbjörn Söderstedt shipped the chicken programing specification. The basic premise of chicken is this: Only the word chicken, spaces and line breaks may be used. It was inspired by this paper and this talk. Along with the specification he also created a javascript function that implements the chicken VM. Sadl...
I have a basic swing application that I am trying to develop using MVC structure. The principal class in the model connects to a derby database and retrieves values from columns and stores them in arrays. My methods in the model (Connect(), Retrieve()) are public void. In runApp(), which is a SwingUtilities runnable, I...
Instead of writing HtmlAgilityPack document code over and over, I've decided to create a helper class for HtmlAgilityPack that prevents me that problem and adds a dispose feature for HtmlDocuments. What can I do better? public class HtmlParser { private ArrayList Documents { get; set; } public HtmlParser() ...
I know there are many PHP upload classes out there, but I'm comfortable with my own code, so I made a simple one here. What do you think of my approach when isImage is true? Of course a general opinion about it and any feedback will help. <?php /** * This will allow easy handling of a php upload * @author: Mihai Ion...
When I chose an element from this HorizontalScrollView, I was setting focus to that element by calling: else if (v.getParent() == candidatesScrollView.getChildAt(0)) { Button candidateButton = (Button) v; v.requestFocusFromTouch(); v.setSelected(true); (...) } Here is part of my XML: <Horizonta...
This code works well, but it's too long and looks too bad. I've tried to format it, but it all sets data, so I don't know how to make it better. Here is the class: private static BrandProfitAndLoss getAllRateComparisonRecords(BrandProfitAndLoss brandProfitAndLoss , BrandProfitAndLoss brandProfitAndLossComp){ BrandP...
My concern lies in understanding the nature of an object. My reasoning: when I instantiate my class, I am either creating an entirely new coupon, or I am referencing an existing one from the database. So I am thinking that the new TJ_Coupon actually is a new coupon. Am I thus using the constructor correctly? And then ...
There's this Ajax-heavy, jQuery-based site which I'm about to work on. There hasn't been much structure in the JavaScript code so far (lots of functions at global scope, hard-coded in the HTML onclick="something(args);". How can I improve upon that and introduce some structure? Here's what I've tried. This part is sup...
I have come across a fun puzzle, sorting a linked list, and I wanted to go for quicksort. However, I am not quite sure whether my partitioning algorithm is efficient enough. I also believe that my code is not clean. Is it possible to remove some variables or make it more efficient? #include <iostream> #include <cstdlib...
I have the following code, which does the following: Reads from the packet from UDP (SNMP) into an array, check if this number is > 127, if yes then '&' this with 127, now pad it with leading zero's to make it 7 bits in total. Combine it with result. Now check the next one in the packet and repeat the above. It works...
I come from a C background and need help refactoring the following imgur image uploader script I wrote. It checks if a token_file with access_token and refresh_token exists. If not, it instructs the user to go to a webpage, allow access to my app and enter the PIN generated from the site back to my program so that I ca...
Here is a function I wrote that can read chunks of large files (> 3 GB). It's designed to be used contentiously so that one can use it in a while loop until it returns EOF. It's an early prototype and is only written to work under 32-bit Linux. I'm okay with feedback on readability, maintainability, or anything else. ...
I've decided to learn Haskell by following the current Coursera algorithms course using Haskell to implement the algorithms discussed. First up is merge sort, which I've implemented as shown here. I'm brand new to Haskell so looking for any suggestions for improvements to the code - it seems quite verbose - and pointer...
I am trying to implement in C/C++ a 'classical' Divide and Conquer algorithm which solves the following problem "Given an array of n-1 numbers (int) from 0 to n, find the missing number". I am using the typical algorithm: start from MSB (1) find out how many bits of 1, 0 I should have (MSB bits) (2) find out how many ...
How should I approach refactoring this code? def separate_comma(number) a = number.to_s.split('') b = a.size/3.0 if a.size < 4 p number.to_s elsif a.size%3 == 0 n = -4 (b.to_i-1).times do |i| a.insert(n, ',') n -= 4 end p a.join("") else n = -4 b.to_i.times do |i| ...
I'm new to PHP programming. I would love some feedback on this simple code I wrote which queries a database based on some arguments supplied by a user and returns an HTML table displaying the data. The table in my db has three columns: Manufacturer, Model, ForSale. The user picks from three drop down menus on the web...
I am reading "Object-Oriented JavaScript" by Stoyan Stefanov to learn JavaScript and in the end of the chapter named "Objects", there's an exercise that asks you to implement your own String object. I have implemented some methods of String (not all), I'd be happy if you could check and let me know how it could be done...
I have written a unit / component in Delphi which helps make it easy to write JSON data. I know there are already existing ways to do this, but the ways I've used are too awkward. I have used an XML writer in Delphi before (not sure exactly what one) but I liked the way it worked, and re-created a JSON version. It's ve...
I see many many programs that are written out of the main method. But most of my programs are written in main() and access some methods from other classes. Am I programming in the correct way? main.java: import java.util.Scanner; import games.Spin; public class Mains { //Declaring Scanner object as console. s...
How can I refactor this? require'yaml' require 'text-table' class Yahtzee def initialize puts "Welcome to Yahtzee, please enter your name." @name = gets.chomp @turn = 0 @scorecard = {"aces" => 0, "twos" => 0, "threes" => 0, "fours" => 0, "fives" => 0, "sixes" => 0, "3 of a kind" => 0, "4 of a kind" =...
MyText.txt This is line 1 This is line 2 Time Taken for writing this# 0 days 0 hrs 1 min 5 sec Nothing Important Sample Text Objective To read the text file and find if "Sample Test is present in the file. If present print the time taken to write the file (which is a value already inside the file)" My Code with...
Introduction So i am building a SPA with AngularJS. The application provides a large number of <input> elements and can be seen as a huge form. However, i am not using an actual <form> element because of the applications architecture. Once everything is filled, all of the data will be submitted by a single button, thou...
In my system there are 3 main functionalities: Add users to database Delete users from database Updater users This is the screenshot in my UI: When clicking on the button of add new user, a jQuery modal form dialog appears and there is a form to add user details to the database. When clicking on the images under...
I am unit testing that the URL that I give to my IRestClient is valid. This client talks to a third party Web API. The test is as below: [Test] [ExpectedException("System.UriFormatException")] public void MakeRequest_EndPointIsInValid_ThrowsUriFormatException() { var stub = new Mock<IRestCl...
I'm currently writing a REST-tool that connects to a third-party server (duh). They offer a fairly large (if not too large) API in a single wsdl file, as well as separate wsdl's for each specific part of data you want to work on. When writing my code, I created an abstract Api class, and a number of child classes, one...
I have a site were we sell unique items. When a user clicks to buy an item we have to reserve it. This prevents other buyers from purchasing the item while the first buyer is checking out. When a buyer clicks the "Buy" button, he is redirected to the orders controller. The orders controller executes the following steps...
Overarching Problem I am creating a threadsafe queue that will act as a shared buffer between two threads for a game I am developing. I need it to be threadsafe so that one thread can throw messages into the queue, and second thread can take them out for processing in real time. I have decided in order to really learn ...
I'm still learning Android, I need to have a spinner and for it to display a list of string values. However, when I submit that data later on I need a corresponding integer value. Similarly to how a HTML Select uses <option value="2">BlahBlah</option>. From searching I've come up with a method which works, just wonderi...
I don't really have experience in factoring. My code is really long, i don't use functions because i don't know if it needs to be a function. I hope you could give me tips so i could clean up my code. <?php # Required files include("simple-html-dom.php"); require("{$_SERVER['DOCUMENT_ROOT']}/config/pipeline-x.php"); ...
Battleship.py # -*- coding: utf-8 -*- import numpy import operator import commands import random import sys import os from time import sleep from grid import grid from fleet import fleet def setupNavy(setupSelection,gridClass,sortedShipList): used="no" shipCoordList=[] for shipData in sortedShipList: ...
This is working now, but it looks very inelegant. I'm sure there is a nicer way of doing this. # Get the outliers of both the dates and values maxDate = [] minDate = [] maxVal = [] minVal = [] for k, v of series for d, i in v series[k][i][1] = nearZero if d[1] is 0 series[k] = v = _.filter v, ...
For my application, I was using array_diff_assoc, when I noticed it was returning the wrong value. I was using multidimensional arrays, therefore I needed a array_diff_assoc_recursive method. I Googled around and found a few, but they all only took 2 parameters. The official array_diff_assoc can take an infinite numb...
I have this class that I've been working on for the past 2 or 3 days, now it's working I just want to know what you think about it, what other methods should I add, are the basic security checks impplemented correctly? etc etc /* * * Author: Carlos Arturo Alaniz * Contact info: caag1993@gmail.com; @alaniz93; c...
Can this be optimized? static internal Point3D[] _data; static internal Point3dTree _kd; static internal int _interpolation_count = 0; static internal int _iteration_count = 0; static Dictionary<int, Point3D> Interpolated_Values = new Dictionary<int, Point3D>(); static internal int _threasindex; static internal doubl...
I'm a novice at Java and just beginning with Swing. I’m trying to figure out how to separate event logic from the presentation logic. Look at the following classes: GUITest.java package guitest; import java.util.ArrayList; public class GuiTest { public static void main(String args[]) { new MainFrame2();}...
I am trying to pick 3 providers with the highest calculated score based on my algorithm, to recommend them to a user. The recommendation algorithm takes into account a few things. Most are static values, but the one that is dynamic is the physical distance from the user (based on lat/lng). Since each user's location is...
This code is supposed to grab live camera feed, display feed in a window, mark in rectangles all detected faces, get the biggest detected face (by total area), display it in separate window, convert it to grayscale and finally save as PNG to hard disk, in project directory. Any ideas for optimizing this code? It has to...
I have a pretty big method where I read data from files and then put them into a combined file in a specific format based on an ID, first and end timestamp. I already refactored some of my code to reduce the code complexity of my method, but it's still over 11 right now. So I was wondering if I should leave the method ...
Is there more efficient way remove duplicate records? strsql := 'delete from ' || TableName || ' a where rowid < ( select max(rowid) from ' || TableName || ' b where a.val=b.val )';
This is a very small MVC framework. I have tested this framework and it's working fine. I can do CRUD without any troubles. I am using Smarty to handle the view section. I still feel I can improve this framework and also I want to find out whether I'm doing something wrong here. Could you please spend a moment to check...
Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented insertion sort in C. The algorithm is structured as a function called from the main function. The array to be sorted is allocated dynamically in the main function but can a...
I have this code: public bool IsWorkAddedWIthConcreteImplementation() { SomeAgentClass agentClass = new SomeAgentClass(); bool param1 = true; string param2 = "Hello"; DataTable dt1 = agentClass.ProvideData(param1, param2); SimpleDAl da = new SimpleDAl(); DataTable dt = da.ProvideData(dt1); b...
I am trying to allow users to upload profile pics on my site. Basically I am following this code: Allow users to upload a pic for their profile. I don't know if the code is secure enough. I am worried that users may upload malicious files. Also, I am concerned that if there is many users, I will have many pictures in a...
I am sure there are better ways to do things but this is part of my first JavaScript project and I'm slowly getting accustomed with how things work in JavaScript. This is also why I ask for a code review, to find what I could not see. Suggestions on idiomatic JavaScript would be welcome. /* Circular buffer used to add ...
I have three different types of XML files (structure) which I would like to import into a database. Every hour a cronjob calls my import.php with a specific XML file type as a parameter. The import script includes a bootstrap.php (AutoLoader, Setup Doctrine DB Connection) and puts all files matching the name convention...
I'm new to Java right now. Here is my following code snippet: for(int i = (SelectedAssets.size()-1); -1 < i; i--){ Double supportTime = 0; //Date class must be used. Cannot replace with another class Date oDate=SelectedAssets[i].Entitlement_End_Date__c; Date dateDifference = oDate.daysBetween(date.toda...
My old script: Exploitable holes in login script Have I improved? I've wrote this script today, by listening to many many suggestions from my last login script thread above. How secure is my script? What would you suggest me to change in my script to make it more secure? Any problems? (not 100% tester, but I haven't se...
I'm developing an Android app to view C-programs. I wanted to give a simple color scheme to the text which is stored in database, retrieved as a string and then passed on to the textview. The code I have written assigns the green color to header file declarations and brackets, the blue color is assigned to numbers, pr...
To implement an insertion sort that sorts an array with optional block to determine sorting order, how can I improve this code? (Seeking best practices and code correctness) def custom_insertion_sort(arr) for i in (1..arr.length-1) curr = arr[i] compare = i-1 if block_given? sorted = yield arr, com...
boolean isBalance(Node root) { if (root == null ) return true; return Math.abs(getHeight(root.left)-getHeight(root.right)) <=1; } int getHeight(Node N) { int L = 0; int R = 0; if (N.L!=null) L = getHeight(N.L); if (N.R!=null) R = getHeight(N.R); return 1 + Max(L,R); } I believe th...
How would I write a foreach statement that includes both of these statement together //clear textboxes foreach (Control c in panel1.Controls.OfType<TextBox>()) { if (!string.IsNullOrEmpty(c.Text)) { c.Text = ""; } } //clear price label text ...
I was doing a standard problem of DP (dynamic programming) on SPOJ Edit Distance using Python. t = raw_input() for i in range(int(t)): a,b = raw_input(),raw_input() r = len(a) c = len(b) x = [[0]*(c+1) for j in range(r+1)] for j in range(c+1): x[0][j] = j for j in range(r+1): ...
I was wondering if anyone would mind looking over my JSFiddle ( contains html / css / js ) and letting me know if this is best practice for the operation. //<!-- Services checkbox operations // i dont think this is the best way to do it but it works--> $(function () { $(".service-slider").on("click", function (...
I'm currently working to implement a simple configuration file parser. I intend to add more functional down the road. ConfigReader.hpp #include <string> #include <vector> class ConfigReader { public: struct record { std::string section; std::string name; std::str...
Much in the spirit of this question, I have implemented a simple class for parallel workers and wanted to get some feedback on it. Can I make the code even more concise or readable? Are there any hidden problems that I should be aware of? Worker class class Worker def initialize queue @queue = queue ...
I'm looking to create a model in JavaScript. Here is an example of the code that I have so far: // Person model function Person(firstName, age) { // Check first name if (firstName) { if (typeof firstName === 'string') { this.firstName = firstName; } else throw new Error('Th...
I have a comments page on my site and I was wondering if it is vulnerable to some sort of sql attack or something else. At the moment users can type what they want, they can even write a php script and it will upload to the database. Is this a problem and how can I fix it. This is the script I use: $name= $_POST['name'...
Suppose there is a number N which can be divided into two positive non zero numbers X and Y i.e N = X + Y. There will be N/2 pairs of (X,Y). I want to find the largest LCM(Least common multiple) of X & Y Example 5 = (1 + 4) and 5 = (2 + 3) Since LCM(1,4) = 4 < LCM(2,3) = 6 the largest LCM will be LCM(2,3) = 6. CO...
I would like a code review for my first simple slideToggle jQuery plugin. Demo (function($) { $.fn.ezToggle = function(options) { var defaults = { selector : '.yourSelector', speed : 300, openedClassName : 'opened', closedClassName : 'closed'...
Did I improve since then? I have been writing this program today, and tried my best to improve my object-oriented understanding. Mains.java: import games.GameHandler; import java.util.Scanner; import java.io.*; public class Mains { public static void main (String[] args) { //Start the game ...
I would like some help to clean up this action, especially from @companies and downward. The comments should be enough to explain :) def search @query = params[:query] unless @query.blank? @query.strip! #Get tags with fuzzy match tags = Tag.where("name LIKE ?", "%#{@query}%").pluck(:name) #Get vouc...
I got tired of stringing together objectAtIndex: and objectForKey: and hoping nothing fails along the way. I parse a lot of JSON from sources like the Google Directions API and it was cluttering my code and hard to read. In this example I am parsing the JSON returned by this call: http://maps.googleapis.com/maps/api/di...
I have to store and return data on multitasking requests. If data is missing, I schedule loading and return null. I'm using some nubie scheduling by saving current jobs in a list. Also I need data request to be locked during writing. .NET 4.0 How can I schedule and lock properly? private ConcurrentDictionary<string, ID...
I've just downloaded a script and would like to use it as a contact form on my site. The problem is I'm a front-end dev with little knowledge of securing PHP code. So, could you please have a look and let me know if there are any glaring problems with security with this script that uses phpMailer to send? As you can se...
I'm trying to find the closest point (Euclidean distance) from a user-inputted point to a list of 50,000 points that I have. Note that the list of points changes all the time. and the closest distance depends on when and where the user clicks on the point. #find the nearest point from a given point to a large list of p...
Is there a way to make this more pythonic? def money(): current_salary = float(input("What is your current salary? ")) years = int(input("How many years would you like to look ahead? ")) amount_of_raise = float(input("What is the average percentage raise you think you will get? ")) * 0.01 for years in ...
I wrote this program for an exercise in Bjarne Stroustrup's text Programming -- Principles and Practice Using C++. He recommended using a vector for pseudo randomness, however I opted for srand() and rand() from cstdlib. Any recommendations regarding efficiency or simplification would be greatly appreciated. I apologiz...
Yes, I know there are plenty of libraries to get this done (Q, step, async), but only for learning I'm wondering if the following code is ok and usable or have major drawbacks and it is only usable at a small programs. Usage: var g = new Manager(); g.then ( function() { console.log("hello"); setT...
I am doing some tests with html5 Canvas object. At the same time I am trying to make my javascript code more modular. In the following code, where/how should I declare canvas and context, so that it can be shared with other objects? Please provide general comments/improvements? Output: Code: $( document ).ready(func...
This program will show or alter the timestamp header on gzip archives. It was created for people who have issues using hash functions to compare gzip archives as the timestamps would be different. I want my code to really speak its intention without having to use comments outside of initialization (unless it is better)...
Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented merge sort in C. The algorithm is structured as a function called from the main function. The array to be sorted is allocated dynamically in the main function but can also ...
I am currently going through Codecademy's Python course (I don't come from a coding background but I'm thoroughly enjoying it) and I got to the end of one of the sections and thought, "Well it worked, but that seemed wildly inefficient." I tried shortening unnecessary parts and came up with this: lloyd = { "name":...
I have the following code to open and close some popup divs. I'd like to know whether there is a shorter solution to close the currently opened divs, as soon as another div is opened, so that there is only one open div. The current solution works as you can see in this jsFiddle, but I guess it is a bit inconvenient. jQ...
Say I have [1, 2, 3, 4, 5, 6, 7, 8, 9] and I want to spread it across - at most - 4 columns. The end result would be: [[1, 2, 3], [4, 5], [6, 7], [8, 9]]. So I made this: item_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] item_count = len(item_list) column_count = item_count if item_count <= 4 else 4 items_per_column = int(item_c...
Edit: Even adding a comment of "looks good to me" and up-voting that comment would be appreciated :) I just want the feedback! Thanks! For the fun of it as well as professional development, I wrote a small "library" (single 24 line JavaScript function) that will allow a developer to double check that all external libra...
I came across this interview question and it has been asked to print combinations of the characters in a string. For example: "abc" --> a, b, c, ab, ac, bc, abc. Also it has been mentioned that 'ab' and 'ba' are same. I want to know if there is any improvement I can make in terms of memory usage/performance. public st...
After finding myself sometimes needing a map of maps, and as I couldn't find one in existing libs (like Guava), I wrote my own implementation. Do you think this version is okay? Specifically: Is it acceptable that I don't permit empty "inner" maps as content for my "outer" map, hence probably breaking the contract of M...
I got bored recently and wrote a tool to re-order out of order classes in Python files. This can occur with some auto-generation code tools for databases and the like; these files can sometimes be thousands of classes big. I've posted it here to gauge its general utility and get feedback on the code (logic flow, readab...
Building on my previous questions. I've managed to make a GUI that queries a SQL database and displays the result in a table. Christ, it's a lot of work for such a simple activity. The code below works. Does it adhere to MVC conventions? If I understand correctly, MainFrame and CustomTable are the "View" classes. They...
I wanted to eliminate some duplication and came up with something I've not seen so I figured I post it and see if others had. Using a delegate to allow the method to return another call to itself. The commented out code is what I replaced. delegate ChainRepositoryCommand ChainRepositoryCommand(Action<Data.Repository> a...
We are in the process of creating a book with the purpose of teaching people the art of html and CSS to create a website from scratch. In our book the focal point, so to say, is that the reader is given a webdesign that he converts into a website by himself. The reader is given the webdesign for the website of a (ficti...
I'm working on a simple CMS. It's working quite ok, but I think my code can be improved a bit. I work with a section.php, which is included from the index.php with (example): switch($_GET['key']) { case '': $page='section'; $id='1'; break; case 'home': $page='section'; $id='1'; break; } include ('header.php'); include ...
I am attempting to come up with a better method for doing this: public static String longToPlayerName(long name) { int i = 0; char[] nameCharacters = new char[12]; while (name != 0L) { long ll = name; name /= 37L; nameCharacters[11 - i++] = playerNameXlateTable[(int) (ll - (name * 37...
As far as I can tell, no gem currently exists to wrap shred, the *nix utility to securely delete files. I created a small class to do this, the key methods are: def self.run cmd stdout,stderr,status = Open3.capture3 cmd raise "Failed executing #{cmd}: stdout: #{stdout}, stderr: #{stderr}, status #{status}" unless ...
I made an example for learning Dependency inversion principle in JavaScript OOP programming . String.prototype.ucfirst = function() { return this.charAt(0).toUpperCase() + this.slice(1); } function textHandler(){ this.printRedbox = function( ){ return ' Red Box text '; } this.printBluebox = f...
I have session controller for mobile devices. I would like to refactor it a little, for example because my session controller is sub class of Devise::SessionsController I had to duplicate error methods from BaseController. class Api::V1::SessionsController < Devise::SessionsController include Devise::Controllers::Hel...
I want to abstract away differences between zipfile and rarfile modules. In my code i want to call ZipFile or RarFile constructors depending on file format. Currently i do it like that. def extract(dir, f, archive_type): ''' archive_type should be 'rar' or 'zip' ''' images = [] if archive_type == '...
I have extension methods to encapsulate query conditions, however I have to separate IQueryable and IEnumerable. Is there any way I can reduce the redundancy and still not lose the performance benefit of IQueryable? public static class PAYTRACK_PARTNER_Extension { public static IQueryable<PAYTRACK_PARTNER> WhereIn...
I have, in Java, an arraylist with these values (many lines, this is just an extract): 20/03/2013 23:31:46 6870 6810 6800 6720 6860 6670 6700 6650 6750 6830 34864 34272 20/03/2013 23:31:46 6910 6780 6800 6720 6860 6680 6620 6690 6760 6790 35072 34496 ...
I know that there is a function bsearch present in stdlib.h but still I want to implement this. This is my code for binary search. Any and all reviews are welcome. #include<stdio.h> #include<stdlib.h> int compare (const void * a, const void * b) { return (*(int*)a - *(int*)b); } int bin_search(int arr[], int min...
This is the relevant piece of my code (false is returned if the whole cycle is finished, pattern is a String passed to the function): for (FileLine fileLine : fileLines) { itemText = fileLine.getText(); itemStrings = new ArrayList<String>(); itemStrings.addAll(Arrays.asList((itemText).split(" "))); for...
I'm working on figuring out the best way to design this so that it's well organized and it seems like the factory design pattern makes sense. Updated: What I'm building: - Pricing calculator - There are 4 products each having their own specific pricing rules that vary from user input - The person can choose betwe...
I'm yet to add garbage cleanup, ID regeneration and the ability to unset sessions, but this is what I have so far. Does this help prevent session hijacking/fixation? Can you see any vulnerabilities? index.php require 'Session.class.php'; // I know this isn't done very well $pdo = new PDO('mysql:host=localhost;dbnam...
I have written an infix-to-postfix program that I would like reviewed and with a few suggestions on improving it, such as a more modularized approach. package basicstrut; import java.util.Stack; public class Infix { private String infixStr; private Stack<Character> oprStack; public Infix(String infixSt...
I have a method: def removeExpiredCookies(jar: CookieJar): CookieJar = { val currentDate = System.currentTimeMillis / 1000L jar.filter(_._2._2 > currentDate) } You use said method like so. var cookieJar = new CookieJar cookieJar = removeExpiredCookies(cookieJar) That method has no side effects. But it's u...
this code works fine but i want to know if this can be improved in any manner . For every user I am fetching the namesList corresponding to that user and for each fetched nameList , i am fetching the ItemsList . I have tried to replicate the sample using this below standalone program as i cant paste my project code as ...
I have a Rails app and in it I have two models, widget and votes. Votes are used to keep track of the desirability of a widget. In my models I have: class Vote < ActiveRecord::Base belongs_to :widget end class Widget < ActiveRecord::Base has_many :votes end I am trying to figure out the best way to route vote...