All Questions

Filter by
Sorted by
Tagged with
6
votes
1answer
3k views

Performance testing functions for wrapping an index

After asking this question, I decided to write a test and determine the fastest way to wrap an index (where my maxSize is always a power of 2). There are 3 ...
6
votes
2answers
133 views

How to reduce this archive detection function and make it supports wildcards

The function below is called to determine if a given file is the archive of another file. I'm also looking for a way to supports wildcards. For example if the original log file is serverw3c.log and we ...
13
votes
8answers
6k views

"Hello, world!" program using a class for printing

Please take a look at my program and let me know how I can improve it. ...
8
votes
5answers
13k views

Database class using PDO

The point of this question I'm actually using it while developing a simple application and it seems to cover all my needs. Also it uses PDO so that we don't really have to worry about SQL Injection. ...
8
votes
2answers
5k views

Connecting to a database

I'm working on a web application that I inherited from a colleague long gone. To connect to the MySQL database I use the following classes: statement.php ...
4
votes
1answer
420 views

Autodetecting monitors in XFCE

I got sick of manually xrandering things on my computers (especially since I always just sequence monitors from left to right and set each at the highest resolution) so I wrote this: ...
11
votes
5answers
9k views

Nested if statements with 3 different parameters

I have a block of code below. The allDone() method at the bottom should only be run if the allCompleted == true. It should run ...
8
votes
2answers
1k views

Multithreaded log test

I'm writing a logger extension that allows multiple threads to log a process, and then dump that log to the main log in one atomic operation. The point of it is to make the logs easier to read when ...
6
votes
2answers
11k views

Handling COM exceptions / busy codes

This code writes to Excel using the COM interface. The general issue is that any exception handling has to handle the "Excel is busy" exception. This occurs if information is sent to Excel quicker ...
8
votes
3answers
468 views

Basic JavaScript library

My own CMS is currently using jQuery, but as one of the goals is to have the whole project to be very small, I've decided to write my own basic library. I only really need to select elements and ...
10
votes
1answer
521 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...
12
votes
5answers
3k views

Binary tree encoding

I implemented a solution to this coding challenge on the Code Golf. I have decent experience with C/C++, but it's been a while since I've used them extensively. ...
13
votes
3answers
525 views

Reservoir Sampling in Clojure

I am learning clojure and decided to start out by trying to write a solution to a fairly simple algorithm, reservoir sampling. As I stated, I am learning clojure specifically and problem solving in a ...
8
votes
4answers
530 views

Spawning threads to process data

I have a class that spawns threads to process data. I am working on instrumentation code. When the process is started, time = System.currentTimeMillis(); When it ...
15
votes
2answers
637 views

Sudoku Grid special purpose Iterators

Please have a look at these iterators which I use for my Sudoku solver. They behave slightly different from STL iterators and don't implement all functionality that would be needed to use them in a ...
3
votes
2answers
1k views

abort() implementation

Here you go: #define abort(msg) (fprintf(stderr, msg) && *((char*)0))
12
votes
5answers
8k views

Image resizing class

How does this class to resize an image look? ...
70
votes
8answers
12k views

Open, write and close a file

I have a small 10-liner function that writes some data to a file using an std::ofstream. I did not explicitly call .close() at ...
12
votes
3answers
3k views

Random Number Generator Class

I've written an abstract class in C# for the purpose of random number generation from an array of bytes. The .NET class RNGCryptoServiceProvider can be used to ...
10
votes
3answers
4k views

Windows service for monitoring network interface changes

I'm currently working on several projects for my company to help reduce the amount of calls we have to deal with so we can focus on higher priority task, such as server resource reduction, etc. The ...
1
vote
4answers
20k views

Is there a better way than lambda to filter on attributes/methods of objects?

Is there a better (more pythonic?) way to filter a list on attributes or methods of objects than relying on lamda functions? ...
8
votes
1answer
6k views

Hypothetical SalesTax challenge

I have a small solution to the following hypothetical problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty ...
4
votes
1answer
1k views

NHibernate (UoW) + cCommand pattern

I'm building an ASP.NET MVC app and would like some feedback for my way to query/execute statements to the ORM. I'm using Fluent NHibernate, and have mixed the UoW provided by NHibernate with a ...
14
votes
2answers
304 views

Executing a program with a temporary directory and measuring the running time

I need a code review for best practices and code correctness of the following piece of code. run executes a program and validates in output. If the output is valid ...
1
vote
4answers
1k views
16
votes
1answer
3k views

House number parsing

I have 2 functions used for parsing a house number and I think these can both be improved. Any suggestions? input: 45a - 47b or ...
5
votes
2answers
460 views

Converting an already-uploaded file and saving it to a model's FileField

Please review this: ...
28
votes
4answers
15k views

Unit-testing a controller in Ruby on Rails

I intend this to be a general question on writing an effective set of test cases for a controller action. I include the following ingredients: Ruby on Rails RSpec: A testing framework. I considered ...
7
votes
1answer
4k views

Workaround for overloaded constructor in PHP

I have a class whose purpose is to display a comment. I'd like to be able to instantiate it by passing a Comment object if I happen to have it available, or just ...
8
votes
1answer
253 views

RubyGem for Enums

A little background first. I've been working on a fairly large Rails application which quickly grew into a breeding ground for "smelly" code. One antipattern we were using a lot was storing objects ...
8
votes
1answer
23k views

Filtering (search) a model with multiple params in hash

This function in my Profile model receive a hash from a search form and should filter the table depending on those values. I guess there is something like a pattern ...
13
votes
6answers
43k views

C function to find and delete a node from a singly linked list

I'm looking for the most commonly used style for writing the delete_item() function of a singly linked list, that find a matching item and deletes it. Is what I ...
2
votes
2answers
227 views

Function to turn to requested bearing

I've been writing a function: float turnToRequestedHeading(float initialHeading, float requiredHeading, float turnRate) I keep thinking there must be a clever ...
22
votes
1answer
1k views

Dynamically generating a list of events

This is a simple list of items in a list, which allows the user to dynamically generate that list of events. Then a controller action does the work of serializing that into the database. The issue is ...
11
votes
3answers
19k views

Simplified Android Spinner

I have written a simple spinner wrapper, but was wondering if any of you could think of any ways to make it more robust. It only handles strings at the moment. ...
7
votes
1answer
511 views

Tame this Beast: TSQL Unpivot

Okay... here's the beast: ...
28
votes
6answers
56k views

Class for measuring distance as feet and inches

My homework question states: Develop a class to measure distance as feet (should be int), inches (should be float). ...
9
votes
3answers
421 views

Function, taking up to 27 parameters, that checks for the existence of a path in a graph

There's got to be a better way than this that preserves the logic while sparing me the multitude of lines: ...
26
votes
3answers
13k views

Usage of the ternary "?:" operator with functions listening to click events

I've recently been doing some mods to some old code I've been maintaining for a couple of years now. As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I ...
6
votes
6answers
461 views

Arguments in constructors matching fields

What is your opinion in arguments in constructors matching members as in the following example ...
5
votes
2answers
424 views

Need a feedback on my Javascript code and app implementation idea

I'm new into Javascript, and I'm not sure that is a good approach. The code works, and does what I need it to do but I'm sure I didn't do the things the right way. Can you give me feedback about the ...
4
votes
1answer
2k views

Simple MVC in PHP

I have a very simple PHP MVC library for my auto-didactic pedagogical purposes. I'm having a little trouble figuring out how to add in the observer patterns as show in this UML diagram from Wikipedia. ...
10
votes
2answers
651 views

Loops for removing unnecessary lines

I have the following method: ...
6
votes
1answer
39k views

Django query_set filtering in the template

Can I make my template syntax simpler? I'm hoping to eliminate the if and maybe also the for block. This worked in the shell ...
13
votes
2answers
3k views

Simple star rating system

I'm working on a simple star rating system, and before I move on to actually "tallying" the votes, which I figure I'll just do with $.ajax, I wanted to make sure ...
12
votes
4answers
5k views

Calculating totals of a transaction

I am working on a project where I have to calculate the totals of a transaction. Unfortunately, coupons have proven to be quite an issue. There are four types of coupons: transaction percentage, ...
21
votes
5answers
12k views

MVVM, WPF Ribbon V4, with Prism

This weekend I've been having one heck of a time getting WPF Ribbon v4 working with MVVM and Prism (using unity). After much trial and error, I believe I have it working. I was hoping someone could ...
13
votes
3answers
1k views

Was this shell script ready for open-source? (Random XKCD wallpaper)

I wrote the following little shell script and published it on GitHub. In the repo there's also a README file that explains how to use it in more detail. This is the first time I open-sourced/...
6
votes
2answers
672 views

JSON API for some bank account

I have been developing this class, and was wondering if anyone had any thoughts on how I can improve the performance of it. ...
24
votes
2answers
4k views

Ruby Koans' Greed Task

Having coded in Java and C# for quite some years, I'm currently learning Ruby. I'm working my way through the Ruby Koans tutorial. At some point, you are to implement a method that calculates the game-...

15 30 50 per page