instruction stringlengths 71 71.9k |
|---|
I'm working on a socket application that will listen to incoming messages from about 400 devices. They all send a message at least once per minute. Now I have a working program and it has been running for a few days without problems as a test with about 10 devices, but I keep thinking I missed something and it could fa... |
Could this code:
var a = new StringBuilder();
var b = new StringBuilder();
var kvps = new List<KeyValuePair<Guid, object>>
{
new KeyValuePair<Guid, object>(Guid.NewGuid(), 1),
new KeyValuePair<Guid, object>(Guid.NewGuid(), "hello")
};
for (var c = 0; c < kvps.Count; c++)
{
a.Append(kvps[c].Key);
b.Appen... |
I've got a tab menu and functions that change the tab's color on click, giving the clicked tab a different color from the others. The thing is, when I click one, I give it another background-color easily but I'm also setting all the other tabs background-color.
In my largest menu there are 6 tabs:
document.getElementBy... |
I've written the following code:
{- ...
...
... -}
data Ellipsoid
data Halfplane
data Intersection
data PointSet s a where
Halfplane :: RealFrac a =>
a -> a -> a -> (a -> a -> Bool) -> a ->
PointSet Halfplane a
Ellipsoid :: RealFrac a =>
a -> a -> a -> ... |
For many days, I've been re-designing my application, applying some custom pattern and making our code looks like a framework. I have something like this for separate the business logic, from views:
if(file_exists($route . $urlpara[0] . ".template.php")){
require_once($route . $urlpara[0] . ".functions.php"... |
I have the following Matlab function:
function [res] = a3_funct(x)
res = 0;
for i = 1:size(x,1)
res = res + abs(x(i))^(i+1);
end
end
It's emulating this equation:
\$f(x) = \sum_{i=1}^{n}|x_i|^{i+1}\$
Here is an example use:
>> a3_funct([1,2,3]')
ans =
90
I know I should be able to use the su... |
I wrote this class which is comparing some values, how can I improve its performance and maybe make it prettier?
You can see at the bottom what type of data it requires, also the array size can reach 100 000 elements.
As it is the class is working fine, but I would like to get a second opinion on how to improve it (I k... |
I am looking to improve the following query.
We are using EF6 (CodeFirst) and C# Lambda Expressions, and Repository/Unit of Work patterns. Also, we needed to restrict the query in a way that we could inner-query the entities so that the query will only retrieve a subset of the joined data, and found this DynamicSelect... |
I'm extremely new to C++ and am doing the exercises on the book Accelerated C++. Here is one of the exercises:
4-5. Write a function that reads words from an input stream and stores
them in a vector. Use that function both to write programs that count
the number of words in the input, and to count how many times e... |
I want to read the content of file then want to make few updates to content and then write that content to another file. I have created the code with node.js as follows.
var filePath = path.join('public/index.html'),
exactFileName = path.basename(filePath),
outputDir = "output/";
function readContent(callback) ... |
I'm rather new to Java and to algorithms in general. I implemented the so called Two-pass algorithm, and want to know if there are improvements to my way of implementing it. What it does is it takes a matrix of ones and zeros and replaces all ones by labels. All ones that are connected should be labeled with the same l... |
I'm using basic jQuery to render tab data. I was wondering if anybody could comment on how to refactor the click() event handlers, and any general guidance or advice.
Here's the code/output in jsFiddle.
('#tab1').click(function() {
$("#page").empty().html("<p>Here is our menu: Crispy Duck, Shrimp Tempura, Christmas ... |
I'm currently looking to optimize my aStar algorithm as my last run through took roughly a minute to generate one path. I've never had to optimize before as I've never run into performance issues, so I'm not sure where to even start with this one.
http://pastebin.com/MbZtyQFu
import java.util.ArrayList;
import java.uti... |
Here is my implementation of the Euclidean Algorithm. My question is how to make it more "professional". It's working right, but isn't this too newbie?
public class Euklideszi {
public int Euklideszi(int a, int b, boolean lepesrolLepesre) {
int r = a % b;
if (a < b) {
r = a;
... |
My goal is to take any size number, and convert it to a string of smaller characters that represent the concatenation of the binary expansion of the number. To illustrate what I am talking about, here is an example using the number 4820:
4820's binary: 0001001011010100 # 16 bits of binary, enough to store the nu... |
I have been working on a small library of development utilities for some time now, incrementally improving and expanding it as I make use of it in other projects. I feel that it is fairly mature now; I've worked out enough bugs that I can say it is decently stable and I feel that it is time for a code review on what I'... |
Very similar to this question, I'm curious about common patterns/best practices for handling events in coffeescript classes, particularly when you also need to call the event handlers immediately to initialize state.
Unlike the answer to the question above though, let's assume though that you do need/want a class.
Her... |
I have the following solution for the Trip problem from Skiena's and Revilla's Programming Challenges (full problem description here).
#include <stdio.h>
double truncate_to_2_decimals(double n)
{
return (double)((int)(n*100.0)) / 100.0;
}
double mean(int n, double numbers[])
{
double r;
int i;
for(i =... |
I have created, in Django 1.6, a site for a school, where an applicant can get registered. It's a form that requests some information from the registrant and creates a random code for each applicant. That code is emailed to the provided address, and it is requested to be input in another form that appears right after ... |
For a while I have been interested in seeing if some tasks work well when split across multiple threads.
On the one project I have been busy with I have been creating a lot of small utility apps, to do single tasks for me, so this morning while modifying one I thought I would give it a try.
What I wrote seems to work, ... |
I am using "AndEngine" and I would like to know if I am following the best practice when I want to refresh the entity.
Let say, I have 2 sprites and I want change them into 2 another sprites.
I usually do it like this :
class MainClass {
private Sprite sprite1;
private Sprite sprite2;
private void someMeth... |
The problem is about finding the sum of all repeating groups from an integer array as explained below and here.
Problem statement:
Say that a "clump" in an array is a series of 2 or more adjacent
elements of the same value. Return the number of clumps in the given
array.
countClumps({1, 2, 2, 3, 4, 4}) → 2
countC... |
I would like a review for this connection to RabbitMQ. I just developed it and seems to be working well, but I would like another set of eyes on it before putting this on the sever.
package models
import com.rabbitmq.client.Connection
import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.client.ConnectionFa... |
I am working on an XNA project, and since procedural generation is likely to be used, I wanted to eventually create a helper class to work with data to facilitate that.
Design Goal:
Originally, I wanted to generate and modify a heightmap in a simple but efficient manner. The most straightforward approach to handle this... |
This is a fairly straight forward question. I have a C# WPF MVVM application that call a C++ DLL to do some compilation/crunching. To update the UI C# application for progress updates I am using callback delegates.
public static class Callbacks
{
public static ConsoleCallback ConsoleOutputCallback { get; set; }
... |
I have the following function that works fine. Is there a better way to do it and will this be efficient if I have 100+ rows returned from each table?
The database
Tables
wcx_articles
wcx_videos
wcx_apps
wcx_links
The corresponding _active column for each table
article_active
video_active
app_active
link_active
_a... |
I have two model classes as follows:
class FileInfo < ActiveRecord::Base
STATUS = {:UNAPPROVED => 1, :APPROVED => 2, :PROCESSED => 3 }
attr_accessible :id, :status
validates :status, :inclusion => {:in => STATUS.values}
end
FileInfo has id and status fields. Each file can multiple file-entries (rows) of the ... |
I created a classic snake game in the canvas element. I have not considered best practices when doing this, I just wanted to finish it first. Now it's time to improve the coding practice. You can help me out by mentioning bad practices, giving code improvements and suggesting anything else.
<!DOCTYPE HTML>
<html>
<he... |
I know the maximum array size is 6. So what is the best practice to declare an array?
In the following code I used it like this:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var marks = new Array(6);
marks = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = marks[3];
</script>
</bo... |
If the fractional part of the number is greater than 0.6, round up; if less, round down.
I need feedback about my code.
public static double DivisionMethod(double a, double b)
{
double div = a / b;
double temp = Math.Floor(div);
double fractional = div - temp;
if (fractional > 0.6)
{
... |
I am a Python beginner and wrote a script which should run on a Raspberry PI as a UDP server. It reads and writes to a serial device and has to process and forward JSON strings.
Because there is relatively much functionality included and I don't like cross compiling, I was too lazy to write a C program but instead chos... |
I've written this code to read CSV files written in a specific format. I would like to gather some feedback on where it could be improved. I'm trying to get into the Test-Driven-Development ideology so any way I could make the code play better with unit tests would be of particular interest to me.
An aspect I am not ov... |
I am trying to do the following. I have a list of Custom objects:
public class TestObject {
public int Id { get; set; }
public string Name { get; set; }
public bool First { get; set; }
public bool Last { get; set; }
}
I want to set the property First and Last to true at the first and last item in the list.
Sid... |
Problem Statement
James got hold of a love letter that his friend Harry has written for
his girlfriend. Being the prankster that James is, he decides to
meddle with it. He changes all the words in the letter into
palindromes.
While modifying the letters of the word, he follows 2 rules:
(a) He always reduces the ... |
I am trying to unit test a small class that I consider part of the "business-logic" layer of my project. It mostly just interact's with Doctrine's entity manager and a couple of entities with a many-to-many association. I'm finding that unit testing it while mocking out its dependencies is just ludicrous. Just the c... |
The online book Game Programming Patterns briefly describes the use of the command pattern to handle input in a game. I've attempted to write my own "one size fits all" input handling system based on the command pattern, as shown below.
Is this a correct implementation and use of the command pattern?
Would it be "bett... |
This is a script I made for testing a simple operating system.
It assembles the source and creates a boot image, then It automates the configuration of a Virtual Box machine.
#!/bin/bash
OS_NAME="hello"
MEMORY_SIZE=8
build_main () {
# remove old files
rm -f $OS_NAME.bin
rm -f $OS_NAME.flp
rm -f $OS_N... |
Follow up question for: Conditional row count across 4 tables
After getting some excellent help from 200_success, i managed to output the SUM() total of my query using the following code:
get_results returns standard mysqli_assoc_array:
$row = $this->get_results($query);
$sum = $row[0];
foreach($sum as $sum) {
e... |
After some free ASCII flowchart drawer started charging money, I decided to write my own. Salient features are that you can draw a box (mouse down, mouse move, mouse up), then ctrlB will draw a box. Copy/Paste, Undo, Redo, click anywhere and type are all working features. I pasted the main code here, and it relies on t... |
I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it.
/// <summary>
/// Compares wildcard to string
/// </summary>
/// <param name="WildString">String to compare</param>
/// <param name="Mask">Wildcard ... |
The following is working and readable SQL for Eloquent that I have created. The downside is that it looks more like a 1:1 with SQL and I don't think I'm using the full potential of Eloquent. I thought of using scope queries to shorten it, but for some reasons the selectRaw prevents it (due to multiple join variable sco... |
Looking for code review, optimizations and best practices.
public class FindMiddleStack<T> {
private Node<T> top;
private Node<T> middle;
private int size = 0;
private static class Node<T> {
Node<T> left;
T item;
Node<T> right;
Node(Node<T> left, T item, Node<T> next) ... |
I have a working function that may be optimizable.
Currently processing 4 objects gives me 0.0459822 for the elapsed time in seconds - used for testing purposes. Once implemented into the app I will be checking > 1000 objects at a time and would like to speed this up if possible. The format of the fd.dataTime and the ... |
Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. All these operations of SpecialStack must be O(1). To implement SpecialStack, you should only use standard S... |
I've recently learned how to use MySQL to store/retrieve data. I've created a MySQLManager class for creating connections and executing queries/updates. Would this be an efficient way to do so?
public class MySQLManager {
private String host;
private String port;
private String database;
private String user;
private S... |
I've been working on a generic graph library for a while now, in a bit of an off and on fashion. I realise that boost::graph exists, but it is a complex library that allows the user a huge amount of customisation. I have gone for a different approach; I constrain the library user much more, but this (hopefully) makes u... |
Is this the most elegant way to avoid declaring additional variables outside the following_triggers loop?
closest_trigger_utc_time = (2**(0.size * 8 -2) -1)
following_triggers.each do |test|
closest_trigger_utc_time = test.utc_time if test.utc_time < closest_trigger_utc_time
end
|
I have found myself needing to sample numbers from a given distribution and was wondering what the most efficient method of doing so is.
I have a set of N elements 0 to N-1 and an array mapping those elements to the probability of their selection, pp.
My approach is to create a new array, cdf, and accumulate the entrie... |
I have made a bootstrap accordion navigation bar that loads data dynamically from a database with PHP.
Here are the two tables that I use:
CREATE TABLE IF NOT EXISTS `top_tier` (
`id` varchar(50) NOT NULL,
`name` varchar(255) NOT NULL,
`date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by... |
Exercises have Muscles and Tools. When someone adds or updates an Exercise, they also send an array of Tools and Muscles. Adds are pretty straightforward, but my update method feels a bit bulky. How can I simplify this?
public void UpdateExercise(Exercise exercise) {
var dbExercise = db.Exercises.First(s... |
How's the following function to update an immutable Map's values?
scala> def updateMap[A](map: Map[A, Set[A]], item: A, toAdd: A) = {
map.map(x => if(x._1 == item) (x._1, (x._2 + toAdd)) else (x._1, x._2))
}
scala> val map = Map(1 -> Set(2), 3 -> Set(4))
scala> updateMap(map, 1, 5)
res1 ...= Map(1 -> Set(2, 5)... |
I have written my first real C++ project, a Sudoku solver! It's not elegant, but it works well. It solves easy and medium but not hard!
#include <locale>
#include <iostream>
#include <fstream>
#include <string>
#include <ctype.h>
#include <cstring>
const char test[11] = {'e', '1', '2', '3', '4', '5', '6', '7', '8',... |
(This is a follow on to this question).
Having given an implementation for some of the graph structures, here is a portion of the algorithms that are defined to work over them:
graph_degree.hpp
/*! \file graph_degree.hpp
* \brief Algorithms relating to node degree.
*
* Defines core algorithms to investigate inde... |
I have two class Task and Award which extends Task. I create this class objects according JSON data. At the moment I have one method that read data passed data and create Task. If I need Award I use method which convert Task to Award. I would like to know if I am following best practice when I want have one method to r... |
The problem is described in full here - Aaah!.
Input
The input consists of two lines. The first line is the “aaah”
Jon Marius is able to say that day. The second line is the “aah” the
doctor wants to hear. Only lowercase ’a’ and ’h’ will be used in the
input, and each line will contain between 0 and 999 ’a’s, inclusiv... |
I am learning C++ from a C background, and I was wondering if I could convert this old C program I'd written into C++ as a personal exercise. The original C program is a simple Monte Carlo simulation that simulates a virus spreading throughout a school population.
Currently, my C++ implementation is almost identical to... |
Follow up question for:
Update database, reload page then show a success message
I have a table of articles, in each row is a button to activate / deactivate the article, along with other actions shown here:
The problem I was having:
If I did a standard AJAX call, I could append a success message to a div but it would... |
This is my first attempt at creating a DAO.
I would like to get some feedback regarding the following aspects if possible:
Code readability
Efficiency
Usability
I also would appreciate any other suggestions for improvement as well.
UserDAO
class UserDAO
{
private $pdo;
public function __construct(PDO $pdo)
... |
I am trying to merge overlapping/intersecting sets given as a list of string vectors below in R (my actual data set has thousands of such sets). The overlap/intersection is based on the SDxyz: string and not the string after the ":".
d <- list(
c("SD1:LUSH", "SD44:CANCEL", "SD384:FR563", "SD32:TRUMPET"),
c("SD23:S... |
I have an object which represents historical prices of certain financial instruments as below:
class DailyPrice
{
public DateTime? Date { get; set; }
public double? Price { get; set; }
}
This needs to be converted into QuarterlyPrice objects which will have all daily prices a... |
I'm writing a PHP function to collect data from different positions in a given array. I've done it as follows which gives me what I require.
for ($a=9; $a < 13; $a++) {
$n = $arr[$a][2];
$p = $arr[$a][3];
$c = $p;
$v1[] = array($n,$p,$c);
}
for ($b=3; $b < 16; $b+=4) {
$h = $arr[6][$b];
$... |
I have an app that will be sending images ranging from few KB to ~20MB and I need to write a code that will do that in the fastest and most efficient way. I currently have a code that does this, but I fear that it's inefficient and slow:
// Read bitmap from file
Bitmap bitmap = null;
Uri uri = Uri.fromFile(new File("ca... |
I need to optimize this snippet to be faster:
Dim lst = (From t In DocElet.ChildNodes Select ID = t.item("ID").outerxml).Distinct().ToList()
Parallel.For(0, lst.Count, Sub(i)
Dim P As XmlElement = GetElement(lst(i))
Dim ls = (From t In DocElet.ChildNodes Where t.item("ID").innerText = P.InnerText... |
I made this admin login script a while ago. It works fine in terms of checking the database for username and password and logs me in. What I don't quite understand is how to secure my login once in.
Currently using:
Cookie and Session check to show admin pages
if(!isset($_COOKIE['Cckiuas']) && !isset($_SESSION["admin... |
I have a series of four method calls that all return Try[Something], with the last returning Try[Unit]. Something like this:
def getFields(): Try[List[A]] = { ... }
def getValues(): Try[List[B]] = { ... }
def createTmpFile(as: List[A], bs: List[B]): Try[C] { ... }
def runProcessWithFile(c: C): Try[Unit] { ... }
def ru... |
I'm new to Databinding in MVP and I want to bind my DataGridView to a object list. This grid may be populated in two ways.
There are TextBoxes in the form and users can enter text, and when they press Add button, a new object is instantiated with the provided fields and then it is added to the list.
Other way is, whe... |
As the title says, I refuse to use a common template engine. I have my reasons, so instead of doing this:
<ul>
<li><a href = "#">test</a>
<li>{CommonParam}</li>
</ul>
I do this:
function listBlock($array){
echo '<ul>';
foreach($array as $foo){
echo '<li' . $foo['args'] . '>' . '<a href = "'' . $foo['link] . '"'>' . $f... |
I'm trying to figure out how to refactor some code based on what codeclimate is telling me. So far it seems that any method that is longer than 5 lines or has an if statement is "complex". In this instance, I'm trying to create an event for a calendar based off of a meeting record.
Here is the Event model:
class Event... |
I have created a script to munge data off this tab-delimited table.
from collections import defaultdict
from utils import sync_and_read, currentdirectory
class MiniWALS(dict):
def __init__(self, toupdate=True):
WALS_URL = "http://wals.info/languoid.tab?sEcho=1&iSortingCols=1"+\
"&iSortCol_0=0&sSortDi... |
The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price o... |
Given an array of non-negative integers, find the largest multiple of 3 that can be formed from array elements.
For example, if the input array is {8, 1, 9}, the output should be "9 8 1", and if the input array is {8, 1, 7, 6, 0}, output should be "8 7 6 0".
Looking for code-review, best-practices and optimizations.
... |
My program 'Monkey', written in Go, can take a file like this:
+ 9 13
/ 10 2
And prints the output (in the case for the 'file' above, '22' and '5'.)
Variables can also be declared to an expression. In this 'file':
* 5 4 : a
+ a 2 : a
The variable a ends up as 22, because at first we assign it to 5 * 4 (20), and t... |
Suppose there is a circle. There are n petrol pumps on that circle. You are given two sets of data.
The amount of petrol that petrol pump will give.
Distance from that petrol pump to the next petrol pump.
Calculate the first point from where a truck will be able to complete the circle (The truck will stop at each pe... |
Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.
Examples:
Input:
arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}
k = 3
Output:
3 3 4 5 5 5 6
Input:
arr[] = {8, 5, 10, 7, 9, 4, 15, 12, 90, 13}
k = 4
Output:
10 10 10 15 15 90 90
Looking for code-review, best practices, and op... |
What can I improve in this form builder? I'm looking for code review, optimization, and best practices.
<?php
/**
* Project: validator - File: form_builder.php
* Author: danutz0501 ©copyright 2014
* Date : (m/y) 06/2014
*/
class form_builder{
private $form;
public function __construct(){}
public func... |
I have the code below that gets hit several hundred times per second. I'm wondering what I can do to improve performance. It seems that there should be some way to build up a substring index. Is there some existing examples of that or an explanation on how to do this?
using System;
using System.Collections.Generic;
usi... |
I'm getting familiar with python and I'm still learning it's tricks and idioms.
Is there an better way to implement print_html() without the multiple calls to html_file.write()? I only separated the HTML for clarity instead of putting the entire string inside write().
In get_car(), is there a way to avoid using if/e... |
This is the second time I have implemented saving and loading for a game using Objective-C. I am using the built in NSCoding methods. I would love to hear opinions about NSCoding and whether or not it is a viable option for saving and loading games. My code does function, however there is a lot of boilerplate code r... |
I've posted this feature request and would like to improve the code involved to handle a few "bugs" (not that it's necessary to provide such code, just for my own practice), but I doubt I'm doing it as efficiently as possible with my updated conditions for the feature:
$("textarea").keydown(function (e) {
if (e.shi... |
I wonder if the following configuration is correct and the handlers are in the right order:
application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: website/index.html
upload: website/index.html
- url: /
static_dir: website
Inside the website folder I... |
I've posted a similar program previously, but I have not made any major modifications in the code, so I am posting it again by deleting the previous question.
I am afraid of the thread keyword and I am not too familiar with threads and blocking, so can you please review this code for me?
Is the use of future enough or ... |
My objective is to update necessary data using one function instead of having different functions to update different fields. So, I've created one and I think this is not really elegant, efficient or secure. I would seriously like a review if possible.
Key.
$data is an array.
$data[0] = column to update.
... |
I have run into a bit of a dilemma. Binding user input and building a prepared statement is all well and good, but what if I need the user input as a variable for a compare?
Can I just create a function to clean the input?
This is the line that worries me:
$password = $_POST['password']
What I have working so far:
//... |
I wrote the following that tries to crack a message that was encrypted via a simple Caesar cipher through brute force. I'm fairly new to Haskell, so any and all input is appreciated.
Because there are infinite ways that something could have been encrypted, it assumes very simple "offset" encryption; like what decShift ... |
After reading a lot about F#, I am today cutting my very first real life F# code and I'd appreciate any feedback on my approach.
I'm writing a simple utility to analyse a log file. The code below represents my approach for identifying sections of the log and representing them in a structure. The "real life" situation... |
I've been designing a game server, where a player has inventory, bank, and other features with items.
There are some definitions of what item can be in my game:
Item is either stackable or not stackable.
If item is stackable, item's amount can be up to 100 per stack.
So since each item can have an amount if it's stac... |
The program should output this:
_1 _1
_1 0
_1 1
0 _1
0 1
1 _1
1 0
1 1
Currently I have this code:
(4 ~: i.9) # (3 # i:1) ,. 9 $ i:1
But I think it can be better.
|
I'm implementing a login script and I want it to be more secure:
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = SECURE;
// This stops JavaScript being able to access the session id.
$httponly = true;
// Forces sessions to... |
This script fast forward merges a branch and then deletes the old one. I normally run it like this:
git m master feature
Here's a link to the gist.
#!/bin/bash -x
set -e
#by naming this git-m and putting it in your PATH, git will be able to run it when you type "git m ..."
if [ "$#" -ne 2 ]
then
echo "Wrong num... |
I've refactored my code such that every function has only one responsibility. Now I'd like like to work on making it DRY.
I'm noticing a lot of duplication in the DocumentAnalyzer class. In nearly every function, I make a reference to @document.
Should my one-statement functions be collapsed into one line?
require 'set... |
public HttpResponseMessage Post(LongUrlModel model)
{
if (ModelState.IsValid)
{
var baseAddress = Request.RequestUri.ToString().TrimEnd('/');
if (model.LongUrl.StartsWith(baseAddress))
{
ModelState.AddModelError("", "You cant shorten a URL that belongs to this domain");
... |
I have written code which is easy to understand, but may not be efficient but will solve the purpose.
public static void main(String a[]){
int ar[] ={1,2,3,4};
boolean flag=false;
int count=0;
while(count<ar.length){
for(int i=0;i<ar.length-1;i++){
if(ar[count... |
I really enjoy Haskell but feel I still have a total beginner's style, and would like to move beyond that. The code below - for Dijkstra's shortest path algorithm - is a case in point. I feel as though I have ended up with a copy of the imperative pseudo code I began with, having done some small transformations, but ... |
I am new to jMockIt and so wanted to learn it. I thought of implementing a synonym servlet kata. The servlet takes a word as input and returns the synoyms of the words as a comma seperated string. The objective of the kata that I implemented was:
Learning jMockIt stubbing and mocking features.
Choosing between stubbin... |
I started a project to build my own invoicing and management system to take the place of prohibitively expensive QuickBooks software. This will be broken down in 5 steps, with the current step in bold font, and previous steps linked.
Design the DB schema and table relationships, and insert data for standards tables
C... |
I'm polling an ashx handler to check if a specific file is present and return true or false depending on it.
public void ProcessRequest(HttpContext context)
{
int myId;
if (context.IsRequestClean())
{
if (int.TryParse(context.Request["id"], out myId))
{
var directory = Directory.... |
I recently started using the builder pattern in one of my projects:
public final class DataKey {
private final long userId;
private final String uuid;
private final String deviceId;
private final int clientId;
private final long timeout;
private final FlowEnum flow;
private DataKey(Builder... |
My task was to take a configuration specified as a dictionary and run some function with it (the actual function is not relevant here). After implementing that, I was asked to allow some "sweeping" of values for the parameters.
After some discussion it was decided to keep the dictionary structure, but allow the user to... |
I've written some code that is suppose to read socket all the time and when needed return the partial data from it. I just want the response to send a command. It works, but this is a bit messy implementation.
Is it possible to write it better?
public StringBuilder message = new StringBuilder();
private BufferedReader ... |
In a jPanel, I'm displaying a 1203x1203 background that I rotate every 30ms. Problem is, Swing is known to be a slow library, and I assume rotating a huge picture at a quick rate would be quite resources demanding. But I've a powerful PC, and even if on mine it runs fine, I wonder if on slower machines it will be as fl... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.