instruction stringlengths 71 39k |
|---|
I have a Visual Studio 2008 C++03 project where I need a timer. I have an implementation that works well, but I'd like any general suggestions from the community on how to improve it. (More generic, lower cost of creating timers, etc...)
class Timer
{
public:
typedef boost::function< void( ) > OnTimer;
Timer( ... |
Is this the best way to prevent that foreach loop from happening if $terms doesn't exist?
$terms = get_the_terms( $postid, 'fecha' );
if(!empty($terms)) {
foreach($terms as $term) {
$myterm = $term->slug;
if(in_array($myterm, $queried_terms)) {continue;}
$queried_terms[] = $myterm;
}
}
|
The program is supposed perform discrete mathematics operations on a number of conjunctive statements (see lines 34 - 50). Currently I just have it so they print out the tables in 0's and 1's, but I'll be adding a compare functionality shortly.
Even though I'm sure this work leaves much to be desired I'm currently wor... |
I am about to >explode< :) due to amount of reading on this subject...
My head hurts, and I need some honest opinions...
There is a similar question/review that I noticed, but I believe my approach is bit different so I wanted to ask.
We are embarking on a really big project that will use ASP.NET MVC 4 with Web API and... |
I'm developing a Java Helper Library which has useful methods developers don't want to type out over and over. I'm trying to think of the best way of checking whether a string is a valid number.
I've always just tried something like Integer.parseInt(iPromiseImANumber); and if it throws an exception then it's not a vali... |
I have two icon animations that pretty much do the same thing, the only difference between them is positioning... one is left and the other right.
I would like to use one block of code for both left and right icon animations.
//////////// Left Icon Animation ////////////
$('.recent .left-icon').css({opacity:0, left:33}... |
I've written a program that creates the (minimal unique) directed acyclic graph from the tree structure of an XML-document. The program prints a Bplex-Grammar to cout. I'm interested in all kinds of remarks, and especially performance optimization.
#include <iostream>
#include <sstream>
#include <boost/foreach.hpp>
#... |
I have translated the following F# code to C# and would appreciate constructive criticism. This code computes the symbolic derivative of the expression f(x)=x³-x-1:
type Expr =
| Int of int
| Var of string
| Add of Expr * Expr
| Mul of Expr * Expr
let rec d f x =
match f with
| Var y when x=y -> Int 1
| ... |
This is HtDP Excercise 12.4.2:
Develop a function insert-everywhere. It consumes a symbol and a list
of words. The result is a list of words like its second argument, but
with the first argument inserted between all letters and at the
beginning and the end of all words of the second argument.
This is what I wro... |
I've used this PHP/AJAX method of validation for a bit, but I think it could use a little peer review. The basic idea was to create a way of verifying forms in a nice manor using AJAX, but also fall-back to PHP when the user disables JavaScript.
One extra note: jQuery is used throughout the JavaScript files.
field_vali... |
I have a user class comprised of the code below. It has functions to insert a user, update a user, delete a user, look up a user, and search for users. What I'm wondering is if I this class would pass the Single Responsibility Principle as stated here (http://en.wikipedia.org/wiki/Single_responsibility_principle).
clas... |
I am trying to create a simple factory pattern demo in PHP. I am not sure if my codes are the best practice. It seems that I have some duplicated codes but I am not sure how to improve it. Basically, I want to create 3 types of accounts (basic, premium and vip). Please advise. Thanks a lot.
abstract class
abstract clas... |
I feel that I am repeating myself a lot with this HTML/PHP code. Am I right, and is there a maintainable way of reducing the amount of repetition in the code?
mydomain/index.php:
<!DOCTYPE HTML>
<?php $root="/mywebdir"; ?>
<html>
<head>
<?php include("$root/inc/meta.php"); ?>
<meta name="description" content="Some desc... |
I'm teaching myself how to program Haskell, and I decided to make a find function in Haskell. What it does is it takes two strings, such as "hello" and "he", and it counts how many times "he" appears in "hello". In addition, it also uses the * character as a wildcard, so searching for "he*o" in "hello" will return 1.
L... |
I have a linearized 2D array u (block_height * block_width) containing the values of a physical quantity over a regular 2D mesh. I need to downsample boundaries (top, bottom, left, right) of this array for communication with another process. I've refactored some code that does this, and I'd like people's thoughts on wh... |
This function takes a URL structure which is most often a query string (but sometimes not) and generates filters to remove query variables from the URL.
If you're looking at an archive like
http://example.com/?genre=rock&band=deep-purple
you'll get the following output:
[ROCK X] [DEEP PURPLE X]
so you can remove tho... |
My application has a thread for handling database inserts and updates. Data is added by other threads to a generic queue in the DB thread. The contents of this queue is retrieved and is sequentially inserted to the database by the thread.
To improve performance, I am planning to bring in a priority mechanism so that m... |
As this community is full of experienced JavaScript developers, and I'm a newbie in JavaScript, I would like if some of you could look over my code for a website I'm building (personal portfolio) and give some insight on how I can improve it, maybe make it more readable and clean, things I may be doing wrong or I misse... |
I've been programming in C++ again (after switching to web languages) for about 2 weeks now. I wrote this simple Node class from which all other objects within the Tree will be derived from. Any critique is very welcome here, however please use clear explanations, don't just point out flaws.
#include <string>
#include ... |
These days I read a lot here on SO about password hashing and data encryption. It's a real mess, I mean, deciding what the best practice is. I need a very simple class that can be reused anywhere and that provide a decent-but-not-paranoic security level for my PHP applications (I do not handle bank data). Additionally,... |
I'm developing applications using Qt which highly make usage of the JSON language to communicate, store and load data of different types. I often need a simple viewer similar to the Firebug JSON explorer to view this data. I already had a JSON parser and serializer called QJson. (update: I also posted my QJson class on... |
This is a class that downloads files in a smart way: it tries to download from different sessions. This do speed up things. How can I Improve it?
import os
import urllib2
import time
import multiprocessing
import string, random
import socket
from ctypes import c_int
import dummy
from useful_util import retry
import co... |
I was looking to do this with sizeof() and I just gave up. As minimal as I can make it, I was wondering if there was a less crude way of doing the const char * as a convenience. I thought about doing this as a template, but I thought having another bit of generated code every time it is called seemed kinda dumb for me.... |
I currently have a selection sorting algorithm, but need some help turning it into a insertion sort, I understand a insertion sort if faster? The hand array is full, and it needs to sort from lowest to highest rank.
private void sort(PlayingCard[] hand)
{
PlayingCard temp;
for(int i = 0; i < hand... |
These are the steps to determine coordinates of the 4 points (P1, P2, P3, P4) that make up a tangential trapezoid connecting to circles. Another way of looking at it is to think of the tangential segments of being the parts of a belt that would not be wrapped around the pulleys. The math should work regardless of the o... |
I have a function named InserUpdateRecords(int flag) to which I pass integer variable which indicates the type of operation it has to perform , if flag==1 then insert , if flag==2 then update. Here is my code:
public void InsertUpdateRecords(int flag)
{
Data_Customer_Log customer_log=new Data_Customer_Log();
tr... |
I'm very new to C++ and would like you all to review the source code I wrote for a program that calculates the user's BMI and loops the program back to the start if the user needs to do additional calculations.
#include <iostream>
#include <stdlib.h>
using namespace std;
float bmiNumber(float pounds, float inches) //B... |
I have some data in a database, organized like (time, category, value), and basically, I want to show it in a histogram. But the library I use to draw historgrams only works properly if every value is filled.
For instance, this does not work:
bin category value
1 A 5
2 B 3
But this is ok:
bin catego... |
My code does what I need it to do, but I think I am missing the "right" way to do this with comparing the arrays. Essentially what I need this to do is compare a textbox entry against two different arrays and redirect based on which value matches.
Protected void Button1_Click(object sender, EventArgs e)
{ ... |
We developed a potential solution for the double form submit prevention and we need some review on it. To be able to execute this code on asp.net we needed to add our function call directly into the onsubmit event of the form. This cannot be handled by jQuery because asp.net use a dopostback function and called form.su... |
I am implementing the Factory pattern for creating my objects and am trying to compose the factories using the AssemblyCatelog from MEF.
The problem I have is that while the Import of the InspectionFactory works the Import of the InspectionPhotoFactory does not.
If I call the AddPhoto method on an InspectionFault objec... |
So this is a lot more confusing than it has to be (I could just stick all of this in the main class with the ui event handlers) but I wanted to decouple this class for learning purposes.
Basic information:
I pulled out a bunch of code and put it in a separate class. This separate class opens files so I used exception h... |
After hours of working, I've finally finished my first C log parsing program! (previously was a bash script, now it is C).
Although I think I've gotten most everything, I was just wondering if you saw any possible buffer/memory overflow dangers in the coding?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#... |
I'd like to improve the readability of the following code. The aim of this code is to apply formatting to row(s) in a WinForms DataGridView based on the Priority of an item, determined either by its currentPriorityValue or its dueDate property.
Because I've got tiger striped rows in the grid I used the modulo ternary t... |
I'm working with two remote APIs: one which manages customers and the other (a Paypal API interface) which manages billing. To delete an account, I must delete the records from both.
function deleteAccount($account_id) {
try {
$api1->deleteAccount( $account_id );
} catch (Exception $e) {
Logger:... |
I try to avoid using classes in Python as much as possible; if I don't plan on building on it, I don't build it in the first place. It helps me avoid Java-like classes like FileDownloader(), when I could build download_file() instead.
That being said, I wanted to discuss getter and setter methods -- particularly getter... |
I made an object wrapper/parameter injector and I hope it will be useful. I made it for a project I am working on but then decided to try polishing it a bit.
The use case is for wrapping objects such that you can inject parameters into their methods by calling the wrapper as a function. I was heavily inspired by Angula... |
For practice I tried implementing a bubble sort algorithm in Ruby. I'm especially interested in creating clean DRY and KISS code and keeping things readable, but efficient. Any hints to improve things would be very much appreciated. The code looks like this:
class Sorter
def initialize
end
def sort(stack)
if... |
Some time ago I've written a small parser (about 250 LoC) which is capable of executing the four arithmetic operators +-*/ as well as a dice-roll operator, NdM, which "rolls a dice", DnD style. The source contains only integers, but of course due to division, not only integers are handled. Floating-point errors are sil... |
I'm building a form dynamically in a web app where I'm using product_id to keep track which product I'm reading and then product_<id>_property to grab the value of it. Then in my view I end up with this:
for product_id in request.POST.getlist('product_id'):
ProductPlacement.objects.create(
product = Product... |
I have a hierarchy of types in my program and need to be able to create them dynamically at runtime. The solution I've come up with below is not the most elegant solution. Are there ways of improving it?
Specifically would it be possible to have the method getBuilderFor(...) not need to instantiate the type it's trying... |
I'm a JavaScript newbie who was first introduced to JavaScript by jQuery. I'm trying to switch over some of the small things I've written in jQuery to JavaScript as a way of learning. I was wondering how I could make my code cleaner and if there were any bad habits which I am guilty of doing.
function getTweets(user) {... |
So, first time I try PHP. Thought I'd set a goal for myself, divide it up in smaller problems and start googling. So yes I got it to work, very happy.
But, it is rather crude and ugly. So now I would like to know how it should look.
Proper regex, proper formatting in the array, keeping the links as links and any other ... |
I am looking for a more efficient or shorter way to achieve the following output using the following code:
timeval curTime;
gettimeofday(&curTime, NULL);
int milli = curTime.tv_usec / 1000;
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%... |
I was asked to submit my request for code review on https://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here.
This is a follow-up to the post I made in https://stackoverflow.com/questions/1683312/is-there-a-safe-way-in-scala-to-transpose-a-list-of-unequal-length-list... |
When we select the 'info' list in the select field, the article with type 'info' characteristic automatically showed up, and when we select 'Berita' list in the select field, the articles with type 'Berita' characteristic automatically show up.
This is a long script that uses a post method. Can you help me make it sim... |
I have following code for a content scroller. This has been implemented with basic jquery. Iam trying to convert the same using advanced javascript concepts. Guide me to implement the same.
Working Code :
$(document).ready(function() {
var currentPosition = 0,
slideWidth = 112,
slides = $('#scroller ul li'),
... |
I wrote QJson, a utility class in/for Qt, I need you to take a look at. It is both a JSON parser and serializer, but with extended functionality (going beyond the JSON specification) (see first section of this post).
Features
QJson uses QVariants for parsed values and QStrings for serialized JSON data.
The parser not ... |
Quite some time ago I started this question: Mathematical Vector2 class implementation and have since improved on it. I've been using it and it seems to work fine, but I'm always looking for ways to improve on code. I also have a question, should I force inline for all my operator overloads or should i just leave the... |
I messed a little bit with pthreads and needed an alternative to the C++11 function std::lock (2 args are enough), and this is what I came up with:
void lock(pthread_mutex_t* m1, pthread_mutex_t* m2) {
while(1) {
pthread_mutex_lock(m1);
if(pthread_mutex_trylock(m2) == 0) { // if lock succesfull
break;... |
The following counts the number of page loads and then does something if < MIN_PAGE_VIEWS.
Can anyone give me any pointers to improve both this function and my JavaScript in general? Both in terms of patterns, design and algorithm.
// Call on body onload event.
// Checks to see if prompt is to be displayed and if banne... |
I have a query to return the ids of failed logins that are newer than a supplied date, and also newer than the last successful login.
Table:
#######################################################
# user_attributes #
#######################################################
# id # u_id... |
The main class (SMSHelper) is responsible of query a REST web service which in turn returns an XML string. This helper is going to return a new SMSCreditInfo instance (merely a data container), with the help of a parser (SMSCreditParser):
class SMSHelper
{
protected static $base = 'https://gateway.skebby.it/api/sen... |
Well this was a simplest code competition at my work.
I tried a couple things, they accepted but none of them is I wanted.
Because both are always giving same result.
I tried to randomize like this
var list = $(".content li").sort(Math.round(Math.random())-0.5);
and this
var list = $(".content li").get().sort(function... |
let binsearch ~arr ~cmp x = (
let cmpx = cmp x in
(* Assuming arr is ordered according to cmp, then (bs min max) is an *)
(* index of a value v in arr such that ((cmp x value) = 0) between *)
(* min (inclusive) and max (exclusive). *)
let rec bs min max =
i... |
I would like to refactor a large Python method I wrote to have better practices.
I wrote a method that parses a design file from the FSL neuroimaging library. Design files are text files with settings for the neuroimaging software. I initially wrote the code to do all the processing in a single loop though the file.
I'... |
Using the eclipse formatting on a class with some @NamedQueries created concatenations.
While I have been doing this for years without paying attention I just realised that may be it
is not a good usage.
So basically Which one of these Strings inside the queryis better ? Is the second one creating too many Strings? Sh... |
I want to realize an object cache which holds objects loaded from database, file or other slow access source, to make them available quickly with high performance. There will be a lot of accesses to get these objects from the dictionary!
It's not supposed to be Singleton/Static; multiple different object holders are po... |
It's been a long while since I've done any Python programming so I thought I'd start with a simple Blackjack game. Any comments on how I can make this more readable? Use more methods perhaps?
from sys import exit
from random import randint
class Game(object):
def __init__(self, start):
self.quips = [
... |
Recently I started working with TinyMVC, wrote a simple menu model and I have few questions for those who are using it... or used before.
For the following code should I keep it as Model or as a Plugin?
How should I implement it in the view and use it on every page that is required without breaking the ideea of MVC ... |
I have to implement WMSAuth in C#: http://wmsauth.org/examples
// The following function was copied from http://wmsauth.org/examples
public static string BuildProtectedURLWithValidity(string password, string media_url, string ip, int valid)
{
string result = null;
DateTime cur_date = DateTime.Now;
TimeZone ... |
I did this as an exercise just to practice/improve using generics.
Independent of how useful this implementation of a Singleton is, how is my coding in terms of using generics and any other aspect of class design of code style?
void Main()
{
var a = Singleton<MyClass>.Value;
var b = Singleton<MyClass, MyClassFa... |
I am trying to improve my skill in C, and this time by getting away from strtok. The following code splits the input string into a token_list, an array of strings.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LEN 256
#define NULL_TERM '\0'
/* A function that will print the content of th... |
Please offer some advice for this code. It all works, but I know that its messy and I don't think the Exception catching is doing what I want it to. Thanks in advance for any and all advice...
def main():
# loop over this forever
while True:
print '--- Getting next job for Device: %s' % device['Name']... |
I use jQuery and underscore.js, I have title1-2 and I would like to have the action corresponding.
this.items = {
menuItems: [
{ title: 'title1',
data: [
{ title: 'title1-1',
action: 'action1-1'
},
{ title: 'title1-2',
... |
Consider the scenario below. It covers multiple methods of my unit under test.
public class OriginalSample
{
public bool Foo(ISomeEntity entity)
{
return entity.IsThatSo ? entity.IsThatSo : Bar(entity);
}
public bool Bar(ISomeEntity entity)
{
return entity.IsThatAsWell;
}
}
[Te... |
Question originally posted on Stack Overflow here.
I'm trying to do an elegant round method that only use the JDK methods and leverage the TimeUnit class of that JDK.
/**
* Get the date rounded to the given unit
* @param date
* @param unit
* @return the rounded value
*/
public static Date round(Date date,TimeUnit ... |
I am using this code for receiving log messages from my clients. I receive more than 1000 connections per minute and I want to increase my log handling, which I have done with java threading.
What happens if it receive multiple client connections? Is this thread safe?
public class CentralizedLogging implements Runnable... |
In an effort to reduce code duplication, I often use and have used this style to capture handling of exceptions on a boundary of an application:
Given the following extension methods:
public static class FuncExtenstion
{
[DebuggerStepThrough]
public static Action<A> AsAction<A, T>(this Func<A, T> f)
{
... |
this.displayData = function () {
var i;
var $thead = $(thead);
var $tbody = $(tbody);
var numberOfFields = columnDataFields.length;
var numberOfRows = data.length;
// Variables to keep track of even and odd rows.
var evenRowClass = 'EvenBar';
var oddRowClass = 'OddBar';
var t = fals... |
I'm using this way to load a combo box with branch names, but it's taking more time if there is more number of data.
Is there a better way to do this, like binding in PHP?
<select name="CmbBr" id="CmbBr">
<?php
include ("dbcon_... |
I have this code:
var submit = document.getElementById('submit');
var error = document.getElementById('error');
var url;
submit.onclick = function(){
url = document.getElementById('url').value;
if(url == ''){
error.style.display = 'block';
return false;
}
};
Now, it's very simple in fun... |
I am looking for opinions on this code. I have been experimenting with SASS the last few days and have come up with the following code. The idea was to enable the creation of a fluid grid without having non-semantic markup in the HTML.
$columns: 12; //total number of columns to use
$gutter: 3%; // gutter width can be ... |
I threw together this C program today to handle a bioinformatics data processing task. The program seems to work correctly, but I wanted to know if anyone has suggestions regarding how the input data are parsed and how I've used control structures in the main processing loop.
#include <assert.h>
#include <stdio.h>
#inc... |
I just got through writing a bash script so my friend and I can share snippets of code to a central file via rsync and ssh. What it does is this;
Sets up ssh public key auth if not already working.
Makes a local "snippet file" using rsync to copy an exiting file from remote server.
Allows the user to edit the snippet ... |
The following is a little JavaScript project to display quotes on a web page. Since I want to use it in a number of different web sites, I read up on good practices for making portable JavaScript code, e.g.:
use no global variables
use namespaces
make it easy to plugin
use default values which can be overridden
For t... |
Alright so this isn't an issue with my program not working, it's more of a fact that I wanna learn to code better.
This is one of 6 if else statements that I use inside of my program. What I'm trying to do is make it shorter (easier) to do. I am learning AS3 with Flex 4.6 (started with Flex 4).
If I left something ... |
Here's an example of a logic structure I've refactored into something more complex on many occasions because I feel like it's wrong to have a side effect in a function that determines a yes/no answer to a question.
If I were to break this into multiple functions I would add to the main logic to call another function th... |
I want to optimize the performance of this SQL query. If I populate this hashtable with one million keys the query will take around minute. How I can optimize this Java method for faster execution?
private HashMap<String, Boolean> selectedIds = new HashMap<>();
public void deleteSelectedIDs() throws SQLException {
... |
I have this method inside a class that is responsible for setting up and executing a model:
public FlowJob PrepareAndScheduleFlowModelJob(string coordinates)
{
GeometryCoordinateString coordinateString =
new GeometryCoordinateString(coordinates);
DataSet intersectedWatershedsDataSet =
FindInte... |
What's the fastest (quality is important too, but a little less important) way to compare two strings?
I'm looking for the most efficient way to compare two strings. Some of the strings I'm comparing can be over 5000 characters long. I'm comparing a list of about 80 strings with another list of about 200 strings. It ta... |
I had to write a SQL query recently to do a few joins and sums, and at the end of it I realized that I have nearly written a storybook. I know the tools to optimize it, but my trouble is the length of it. I am very sure, it can be shortened up, but my little brain refuses to strengthen this belief.
Basically, I want a ... |
I am in between to create JavaScript Boilerplate (collection of best practices around) for low/medium complex project and will host on GitHub in sometime once finalized it.
Have divided the JavaScript modules in 3 parts
project.config.js - Would have all the required configuration
project.main.js - the JS Boilerplate
... |
I've implemented concurrent_blocking_queue for multiple-producers and single consumer.
I intend it to block the producers as well, when the queue is full, which is why I set the capacity of the queue in the constructor. I've provided my own implementation of critical_section, scoped_lock and condition_variable, using ... |
This is a simple thread safe queue that is used in a producer-consumer model.
public class ThreadedQueue<TType>
{
private Queue<TType> _queue;
private object _queueLock;
protected ThreadedQueue()
{
_queue = new Queue<TType>();
_queueLock = new object();
}
public void Enqueue(TT... |
There are two ways I have been using to create links and style them as buttons:
background: url("/images/sing_up_btn.png") no-repeat scroll 0 0 transparent;
font-family: Arial,Helvetica,Sans-serif;
text-shadow: 0 -1px #444444;
text-transform: none;
Another one is:
a.btn_link
{
background: #4468b2; /* Old browsers... |
I have a constructor which sets a member variable. The setting of this variable throws an exception. Should I be throwing the exception in the contructor or enclosing the try/catch like below. Is below snippet an example of code smell ?
private NewManager newManager;
public Save(final TheManager manager, final Str... |
I have the following function in a Service class
protected function writeToFile():void{
var destinationFile:File = File.applicationStorageDirectory.resolvePath(_newPath);
var fs:FileStream = new FileStream();
fs.open(destinationFile, FileMode.WRITE);
fs.writeBytes(_buffer, 0, _buffer.l... |
This is a minimal little utility that I've found useful while reorganizing my music and book libraries. Any issues you can see? Anything I could be doing better or more elegantly? Anyone wanna take a crack at the equivalent in Python/Perl?
Take 2:
#!/usr/bin/ruby
require 'optparse'
require 'pp'
require 'fileutils'
$o... |
See the full calculator with HTML -> https://gist.github.com/1861120
You should be able to drag that html file from github into a browser and start using it. I'm only putting the js below. The calculator works fine but JS Lint is telling me I have an unexpected 'function' doCalc line 9 character 1.
Also just looking fo... |
I am trying to optimize inserts from a returned JSON which contains data from multiple tables on the remote server. My code is working, but I just want to figure out a way for it to work better. I need the structure to be very dynamic (i.e. fetching the table names from JSON then looping through to complete the inserts... |
I have a Core Data model with two entities: Video and Playlist.
A Video can be a member of many Playlists
A Playlist can have many Videos, including the same Video multiple times
A Playlist's Videos are ordered
Video <<----->> Playlist
That being said, I've decided that I need a third entity: Playlist Item.
A Play... |
I find myself nesting a lot of grids inside grids in WPF. I just found myself 3 Grids deep, and stopped to think: "Should I be doing this?" Is there some kind of performance cost? Is it unmaintainable? (Kind of like heavily nested ifs maybe.)
I guess the alternative is to have one grid, and use a whole lot of column sp... |
I took my first stab at a user authentication function. I invented my own way of doing this. Is this a safe and efficient way of giving a user Read/Edit/Delete permission on tables in a MySQL database?
The Class
class Personnel {
//set tables that will need permissions and actions
protected static $actions = array("rea... |
I'm working right now in a readers social network. The main points are this:
When an user connects with his account I save his user id in the
session variable.
My MVC is working with DTO's all the way, filling the necessary
variables for the presentation in the model.
So, everything was ok, until today that I had to... |
The code below is for modern browsers only.
Naming conventions are as follows:
m or M - Model
v or V - View
c or C - Controller
/********************************************************************************************
***************************************************************************************... |
Could you explain to me which code is better (more optimal) and why?
Vesion 1:
while(something){
Runnable task = (Runnable) taskQueue.dequeue();
Throwable ex = null;
...
}
Version 2:
Runnable task;
Throwable ex;
while(something){
task = (Runnable) taskQueue.dequeue();
ex = null;
...
}
For me it looks like second ve... |
I have n-times similar statements
if trigger_data.tt_closed
unless trouble_ticket.changes.key?(:status)
@run = 0
break
end
unless trouble_ticket.changes[:status][1] == "Closed"
@run = 0
break
end
end
if trigger_data.tt_assignee
unless trouble_ti... |
I wrote this algorithm to determine the winning hand of two players going head to head with a hand of One Pair. Note that the hand is sorted once it is given out, and the algorithm has to compare the two hands one pair, if one has a higher one pair such as AA vs 33, there is an obvious winner. If the hands have match... |
I'm teaching myself BigDecimal and would appreciate a critique. In the code fragment below, I calculate a tip from user input: check and tip percentage (entered as integer):
txt_check = txtcheck.getText().toString();
tpercent = txttippct.getText().toString();
BigDecimal hundred = new BigDecimal("100");
BigDecima... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.