instruction stringlengths 71 95.1k |
|---|
Exercise 2.46.
A two-dimensional
vector v running from the origin to a
point can be represented as a pair
consisting of an x-coordinate and a
y-coordinate. Implement a data
abstraction for vectors by giving a
constructor make-vect and
corresponding selectors xcor-vect and
ycor-vect. In terms of your se... |
I have a class which is responsible for checking whether a website is up or down. I've made it to run asynchronously, but I would like critique if this is a good/bad way or if there is another better way to do it.
class UrlChecker {
private readonly IValidationCondition _condition;
private readonly Dictionary<s... |
I have been reviewing the code of a new co-worker and, although in general I think it's OK, there's a thing that causes me mixed feelings:
private void Method(...)
{
Thread t = new Thread(() =>
{
// Some ~50 lines of code here
});
t.Start();
}
This is no big deal, but I'm c... |
The script is fully working, but I ask is there a better way I can do this rather than name all of the query variables, $q, $q1 etc, and then use if else statements to execute the code.
<?php
// open the mysql connection
require_once('mysqli.php');
// successful login variables
$q = $dbc -> prepare("SELECT * FROM a... |
I've been using the following the code to store temporal error messages in TempData, to be displayed from my master page on production sites without any problems, but is this a good way of doing it?
The controller helper code:
namespace System.Web.Mvc
{
public static class Controllers
{
public static vo... |
I am making a simple transposition cipher. I am testing the program with the word "computer" with the secret key "5,2,8,3,7,1,4,6", where the encrypt method will put the 5th letter 'u' in the first position, 2nd letter 'o' in 2nd position, 8th letter 'r' in 3rd position...
So the output would be:
original: computer
en... |
I have this version comparison function in java.
Any cleaner way to write this without all the nested 'if' statements?
Note that the suggestions must be in Java code only.
@Override
public int compareTo(Version o)
{
int result = this.major.compareTo(o.major);
if (result == 0)
{
result = this.minor... |
I am trying to learn how to write good, clean, and efficient JavaScript. I consider myself a novice, at best, in JavaScript. Any comments are appreciated.
In an effort to become a better JavaScript programmer, I am trying to write a simple JavaScript animation using HTML5's new canvas element. Functionally speaking, wh... |
I'm working on interfacing some older positioning equipment with an arduino, but having done the majority of my work with higher level language I'm having trouble adjusting to the limitations of AVR-GCC.
I basically have two questions: Is this a good way to parse out the strings? What can I do to optimize this code for... |
I have a form that submits to a servlet that has optional parameters. If they are empty they are just ignored. This is the template I am using:
if (!(param = (String)params.get("httpParam")).equals("")) {
// Handle parameter
}
It doesn't quite feel right. It works, but I think it could be more readable. Any suggest... |
I have decided to go PDO and have started implementing it on one of my webprojects. I have limited programing skills but can usually pull it off with some tutorials and forums.
Here is my code this far and it works fine but how is the code correct regarding the picking up errors, syntax, order and begintransaction etc.... |
I just wrote this small inch <-> cm conversion program. It works just fine, although I know that I've done some things in a rather stupid manner and that it could be improved.
def conversion():
try: amount = int(raw_input("Please enter the value: "))
except ValueError:
print "Please specify a valid amou... |
Below I have some jQuery code that handles footnotes. My question is actually about the formatting and indentation of the code, so I won't bother trying to explain what the code does beyond that.
I'd like to know what patterns of indentation are considered the most maintainable and readable when chaining jQuery functio... |
I need to get the total milliseconds to the next mid-day (12:00:00) to signal a timer that will run once a day.
Assuming the application can be shut down and started anytime, is this code to get the milliseconds left to midday (used to set the timer) correct? (It doesn't need to be exact; it can be off by a few secon... |
I want to join strings together, but when doing this it often happens that there is a comma too many, and therefore I need to remove that comma. In this code, I use the substring to delete the two last characters.
How can this become more elegant?
List<String> paramList = new ArrayList<String>( );
paramList.add( "param... |
Could someone review an accepted answered I gave on Stack Overflow?
The use-case is as follows:
Given a messaging system where a user
can receive a message from a single
user and send messages to one or more
users, return the most recent
communication (sent or received)
between a passed userId and the
indi... |
I needed to write code in WPF for a client. The application is done with prism (not my decision, they already had people working on it), so I got a sparkling clean new module to work in. Since this was my first time writing WPF code going to production, I wanted to handle the code in a good manner. I decided to go MVVM... |
Exercise 2.54
Two lists are said to
be equal? if they contain equal
elements arranged in the same order.
For example,
(equal? '(this is a list) '(this is a list))
is true, but
(equal? '(this is a list) '(this (is a) list))
is false. To be more precise, we can
define equal? recursively in terms of
the basic e... |
Exercise 2.56.
Show how to extend the
basic differentiator to handle more
kinds of expressions. For instance,
implement the differentiation rule
$$ \frac{d(u^n)}{dr} = nu^{n-1}(\frac{du}{dr})$$
by adding a new clause to the deriv
program and defining appropriate
procedures exponentiation?, base,
exponent, ... |
Exercise 2.57. Extend the
differentiation program to handle sums
and products of arbitrary numbers of
(two or more) terms. Then the last
example above could be expressed as
(deriv '(* x y (+ x 3)) 'x)
Try to do this by changing only the
representation for sums and products,
without changing the deriv proc... |
I am making a website using the MVP pattern. It is a simple website, so for the repository I use Linq2SQL. My architecture is basically:
(View - Presenter) - Service Layer - Domain Models.
The View consists of 10 dropdownlists, and a submit button.
Between the (View - Presenter) and the Service Layer I use DTO's to exc... |
Background:
This began with James Colgan's Lisp-Dojo for Ruby. My implementation can be found here. I then moved on to Write yourself a scheme in 48 hours. This question has to do with one of the implementation decisions.
Code:
My implementation of eval
--# The eval function takes a scope and paresed Lisp value and
... |
I just started learning how to code PHP as well as HTML and as a challenge for myself I put together a questionnaire with what I have learnt so far which isn't as much as I would like to know e.g. sessions, databases, etc. Anyhoo, I would like to get the review of peers and would appreciate any constructive suggestions... |
How can I make this sort faster and better?
function OrderBy(a,b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
SortBy = function($th) {
var $tbody = $th.closest('tbody');
var $table = $tbody.parent();
$tbody.detach();
$('#Processing').show('fast',function () {
var column... |
if params[:package]
city_ids = []
city = params[:package].delete 'city'
city_ids << city if city.to_i > 0
cities = params[:package].delete 'cities'
city_ids += cities if cities.class == Array && cities.length > 0
params[:package][:cities] = city_ids.map{ |c| City.get(c) }.compact
end
|
I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP:
Exercise 2.58
Suppose we want to
modify the differentiation program so
that it works with ordinary
mathematical notation, in which + and
* are infix rather than prefix operators. Since the differentiati... |
For web-uploading of Cyrillic-named images, I've written the script below:
#!/usr/bin/python
# coding=utf-8
import os
import argparse
import shutil
class Error: pass
class FolderError(Error): pass
def copytranstree (src, dst):
names = os.listdir( src )
try:
os.makedirs( dst )
except WindowsError:
... |
From SICP:
Exercise 2.60. We specified that a
set would be represented as a list
with no duplicates. Now suppose we
allow duplicates. For instance, the
set {1,2,3} could be represented as
the list (2 3 2 1 3 2 2). Design
procedures element-of-set?,
adjoin-set, union-set, and
intersection-set that oper... |
From SICP:
Exercise 2.61
Give an implementation
of adjoin-set using the ordered
representation. By analogy with
element-of-set? show how to take
advantage of the ordering to produce a
procedure that requires on the average
about half as many steps as with the
unordered representation.
(define (adjoin-se... |
I've just finished the Ruby Koans and one of the last projects was creating a Proxy class that sends methods to another class. I was wondering whether you would change anything about my solution (if there's something wrong or a better way to do it). I'm still a beginner and I want to get better.
require File.expand_pat... |
From SICP:
Exercise 2.65
Use the results of
exercises 2.63 and 2.64 to give (n)
implementations of union-set and
intersection-set for sets implemented
as (balanced) binary trees.41
I wrote the following answer:
(define (union-set a b)
(define (rec set1 set2)
(cond ((null? set1) set2)
((null? ... |
I'm writing a function with the following signature:
(Ord a) => [a] -> [Int]
It's semantics is to find an order-preserving mapping from list of objects to list of Ints.
The version of mine:
import Data.List
import Data.Map (Map, (!))
import qualified Data.Map as Map
renumber :: (Ord a) => [a] -> [Int]
renumber list ... |
I have ext_scaffold (question.js). When I row click I get answers on this question, so
'rowselect': function(sm, row, rec) {
store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/answers/index_all_for_question_id/' + rec.data.id + '?format=ext_json',
method: 'GET'}),
re... |
From SICP:
Exercise 2.66. Implement the lookup
procedure for the case where the set
of records is structured as a binary
tree, ordered by the numerical values
of the keys.
I wrote the following:
(define key car)
(define make-record cons)
(define value cadar)
(define (lookup given-key set-of-records)
(cond... |
The ConcurrentDictionary<T,V> in .NET 4.0 is thread safe but not all methods are atomic.
This points out that:
... not all methods are atomic, specifically GetOrAdd and AddOrUpdate. The user delegate that is passed to these methods is invoked outside of the dictionary's internal lock.
Example Problem:
It is possible ... |
I have two elements on my page:
<ul id="VerticalMenu></ul>
<ul id="AccordionMenu"></ul>
I'm calling some JSON with jQuery and loading elements in the divs. I'm curious if there are things I can be doing more efficiently, and better ways to use selectors and JSON.
$().ready(function() {
//Load sections
GetCarli... |
This journey started with a quest to create the shortest possible case-insensitive verification number. Based on the answers there, I worked out a Classic ASP/VBScript implementation of Crockford's Base32 Encoding and it has served me well so far.
Out of semi-idle curiosity, I was wondering if there was a way to furthe... |
I don't have any questions about this piece of code; it compiles just fine in Visual Studio 2010. I just wanted to post it to see if anyone has any good ideas on how to simplify it, or pointing out any bad practices I have have done.
// Tic Tac Toe Game
#include <iostream>
#include <iomanip>
using namespace std;
clas... |
I've found this implementation on the web:
void insertSort(int a[], int length)
{
int i, j, value;
int k=0;
for(i = 1; i < length; i++)
{
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; j--)
{
a[j + 1] = a[j];
k++;
}
a[j+... |
I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution:
# app/helpers/application_helper.rb
module ApplicationHelper
include ApplicationContainer
# ...
end
# app/helpers/partials/application_container.rb
module ApplicationContainer
# ... |
This example comes from a code snippet posted on Stack Overflow:
private double brickVal(Color c) {
if (c == Color.RED) {
return 10.0;
} else if (c == Color.ORANGE) {
return 8.0;
} else if (c == Color.YELLOW) {
return 6.0;
} else if (c == Color.GREEN) {
return 4.0;
} ... |
string s = Clipboard.GetText().Replace("\r", " ");
string[] lines = s.Split('\n');
int row = dgView.CurrentCell.RowIndex;
int col = dgView.CurrentCell.ColumnIndex;
int linesCount = lines.Count();
if ((row + linesCount) - dgView.RowCount > 0) dgView.Rows.Add((row + linesCount) - dgView.RowCount);
asyncSqlResultsViewer.... |
From the text:
Exercise 2.68. The encode procedure
takes as arguments a message and a
tree and produces the list of bits
that gives the encoded message.
(define (encode message tree)
(if (null? message)
'()
(append (encode-symbol (car message) tree)
(encode (cdr message) tree))))
... |
From SICP:
Exercise 2.69. The following
procedure takes as its argument a list
of symbol-frequency pairs (where no
symbol appears in more than one pair)
and generates a Huffman encoding tree
according to the Huffman algorithm.
(define (generate-huffman-tree pairs)
(successive-merge (make-leaf-set pairs)... |
What would be a prettier/faster way to do handling of multiple errors in Ruby? Here is the code I am working with:
begin
response = session.get url
rescue Patron::HostResolutionError
puts "Error resolving remote host."
exit 1
rescue Patron::PartialFileError
puts "File size mismatch. (Host reported a file size, ... |
The TEA is a very simple encryption algorithm requiring little time and space - perfect for embedded systems. There are extensions to it, and every version has its flaws (WEP was based on it), but for casual protection it's perfect.
Also, the encrypt and decrypt routines are exactly as found from Wikipedia, so I don't... |
5 years ago, when i was in love with VB, I created this simple program to detect if a file is virus or not.
What I'd like is to see if you can help me optimize it, speed-wise.
I open an executable file in a rich textbox control and use the Instr method to search for occurrences of predefined string. The problem is that... |
In my nested for loops below, it is sometimes necessary to exit the outer loop and then continue program execution. Since loop labels and other goto-like constructions are heavily discouraged, I'm a bit afraid of raptors. Is this usage OK? Is there a better way to structure the program?
my @objects = load_objects();
OU... |
I am new to Rails and have a system that needs to process transactions.
A user can enter a transaction to which one or more users are tied. These users owe some amount of money to the person making the transaction. For example, Bill might buy lunch for 4 friends and the bill is $125. They decide to split the bill 5 ... |
My friend does a bunch of Java work (commandline, still toying around) and I notice a bunch of try/catch blocks like this:
try {
double a = Double.parseDouble(secondInput);
}
catch(NumberFormatException nFE) {
System.out.println("The input was not an integer.");
try {
Thread.sle... |
I have a simple quantity display function that runs for every product displayed in our catalog. The MaxQtyDisplay value is set in our web.config file. Part of me thinks the function is as streamlined as possible and part of me thinks it can be improved upon somewhere. Because this function is called many, many times... |
This is a jQuery plug-in I've created that relies on jQuery UI's tabs plug-in. It adds some framework specific logic when setting up tabs:
Fixes a bug in jQuery that appears when an id/class contains a "."
Manages the tab state using a framework specific cookie API (does not use the jQuery cookie plugin)
Exposes a cou... |
I am new to the world of coding as well as XHTML and PHP. As a way to gain more experience as well as to put theory into practice including a way to challenge myself, I put together the following code that calculates values a user enters into a form.
This was to test my knowledge regarding PHP's own functions but also... |
Edit:
The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original file from the source directory.
Is there a better way to write the following code?:
/// <summary>
/// Moves a specific file ... |
In a controller (PHP, CodeIgniter) I'm adding scripts & css to variables to be used in the view output. My initial coding looked like this:
private function _add_script($path, $where = self::ADD_LAST) {
$html = "<script src='$path'></script>\n";
switch($where) {
case self::ADD_LAST:
array_pu... |
I'm currently using an Open Source FTP library in all my projects as I've never managed to code a decent FTP Helper Library based on the C# 4.0 API.
What do you think about this approach? I'm not quite versed in TDD but ideally I'd like to make this class as testable as possible.
public void DownloadFile(string host, s... |
I am a newbie to Python and have started object-oriented programming recently. I have implemented a "Rock Paper Scissors" application in OOP. I would like for you to evaluate my code, and tell me where can I improve my code and how I can better organize the functionality.
import random
class RockPaperScissors(object):... |
This essentially reads a specially-structured file from the scanner and then parses random phrases and prints them:
{
<start>
<greeting> <object>
}
{
<greeting>
hello
bonjour
aloha
}
{
<object>
world
universe
multiverse
}
Possible random phrases could be: "hello world", "bonjour universe", etc...
Does anyone have so... |
From SICP:
Exercise 2.82
Show how to generalize
apply-generic to handle coercion in
the general case of multiple
arguments. One strategy is to attempt
to coerce all the arguments to the
type of the first argument, then to
the type of the second argument, and
so on. Give an example of a situation
where ... |
I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, how ... |
I have the following construction in the program:
while(true) {
<...>
try {
JobManager.markJobCompleted(unitOfWork.getSqlFactory(), jobId, dataOut);
} catch (DbLogicException e) {
logger.error(JobManager.CANNOT_MARK_JOB_COMPLETED + jobId, e);
try {
unitOfWork.rollback()... |
I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be improved to be more Ruby-like. I'll post my code samples one by one, so I can apply things learned in previo... |
As an exercise, I've implemented a simple reader macro in Common Lisp (using SBCL). It converts Octal (unsigned integers only) into numbers.
Usage:
* #z1234
668
The code:
(defun oct-string-to-number
(string)
"Converts an octal string to a number. Only digits from 0 - 7 are accepted; sign or decimal point symbo... |
In this post I asked about what would be idiomatic haskell database abstraction. I had been thinking for it a while, and the first answer was similar to what I had in mind, and I wrote a proof-of-concept of it. Discarding the abomination that is the schema, what would you change, and why?
Database.hs
{-# LANGUAGE Gener... |
I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be improved to be more Ruby-like.
Write a simple grep that will print the lines of a file having any occurrenc... |
I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be improved to be more Ruby-like.
Given: a CSV file structured with a first line with headers and
subsequent... |
I have been working with C# for quite some time but relatively new to the concepts of lambdas and Linq. I was working with a Linq To SQL example and trying to write a generic solution for executing a search against a collection of entities (eg. list of Customer objects) where the search parameter will be specified by p... |
Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all into one?
public void getFrmSingProgTbl(int flg)
{
if (flg == 1)
{
object[] astatus = ne... |
I have small Class which handles user's information. (name, surname, login, hash of password). Also this class can activate, register and login the user. This means I should connect to DB. Is it normal? I'm using Pear MDB2 to connect to DB.
Does it mean that every instance of User will have MDB2 object initialised?
cl... |
I'm giving a lecture on basic programming to first-year mathematics students. The programming language is Java (defined by curriculum).
Last week I gave the following task:
Write a program, that reads in the date of birth of the user separated into year, month and day and subsequently calculates the days the user has ... |
I remember once going to see [Srinivasa Ramanujan] when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavorable omen. "No," he replied, "it is a very interesting number; it is the smallest number expressible as t... |
The objective was the following to be solved in Python:
Given a string, def a function that
returns another string with the vowels
(upper or lowercase) replaced by
0,1,2,3,4 respectively.
Example input:
"bB nN aei ou AEIOU"
Desired Output:
"bB nN 012 34 01234"
This is in fact quite trivial and can be solved... |
I have been using the following function (in the kohana html class in a table) to generate tables.
function table($columns,$reverse=false,$fill=false,array $attr=null){
$c = '';
//ugly hack, looking for fix
$max=sizeof(max($columns));
for($i=0;$i<sizeof($columns);$i++){
$column = $columns[$i... |
In the situation where I am looping through a collection looking for an item, is it better practice to break before I return or should I break and then return?
Return during loop:
foreach(string item in items)
{
string[] split = item.Split('|');
if(split[0] == searchFor)
return split[1];
}
return null;
... |
I managed to get something up and running, but I've no idea whether there are better ways to do this. I've spent all morning trying to figure out the best way to use parameters (allowing objects from the pipeline, or to be passed in, allowing overriding the modelName, etc.) and trying to understand differences between ... |
I've never been satisfied with any of the possible sprintf()-like functions in C++:
sprintf() is a C function and it's very unsafe and dangerous to use (undefined behavior all over the place)
boost::format is too slow and awkward to use (think of the % syntax)
iostream is extremely awkward to use
So I came up with my... |
I am writing a wrapper for dynamic behavior in C#. If I use GetMethod(), then an exception is thrown when there is more than one method (overloads). I figure it will become apparent at runtime that if there is an argument mismatch anyway. Is this a good way to solve the problem?
public class StaticMembersDynamicWrapp... |
I am seeing it more and more.
Which do you think works best and why?
This:
$config = array(
'param1'=>'abc'
'param2'=>'dfg'
);
new Class($config);
Or:
new Class('abc','dfg');
|
http://en.wikipedia.org/wiki/Trie
The basic idea is to support fast searches via prefix matching. In my implementation, I allow each node to store all of the words that match its given prefix, and then if the word length exceeds the length of the node's prefix, it passes the word into its children for further storage.
... |
I have this python code that compares merge sort and selection sort, but it is taking "forever."
import time
import random
# Selection Sort Code #
def maxIndex(J):
return J.index(max(J))
def swap(LCopy, i, j):
temp = LCopy[i]
LCopy[i] = LCopy[j]
LCopy[j] = temp
# Implementation of selection sort
def ... |
In order to avoid the user having to explicitly prefix a script with sudo or su --command, I wrote the following:
import sys
import os
if os.getuid():
root = "/usr/bin/sudo"
if not os.path.exists("/usr/bin/sudo"):
root = "/bin/su --command"
command = "{} {}".format(root, sys.argv[0])
command = ... |
Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the form of Polish Notation.
The user will input something like
+ 5 6
And it will then output
11
Here's another sample input:
+ 5 * 2 3
And the output:
11
Users can even define their own variables, like this:
def myVar 10
and... |
Is it good or bad practice (or, when is it appropriate) to use shorthand methods?
Lets pretend we're using jQuery here, because it has a lot of them.:
jQuery.ajax()
jQuery.get()
jQuery.getJSON()
jQuery.getScript()
.load()
jQuery.post()
These are all really just shorthand forms for the ajax function, with the exception... |
I recently came up with the idea to attempt generating ungodly large prime numbers and their generators modulo N in php. I don't know much about number theory and just wanted to get some comments to see if this code should be sucessful. The output is just directed to a file at the moment because I didn't want to wast t... |
This is the first time I've written a start-stop-daemon script, so I would love some feedback. :) The goal is to have it start late, when the network and everything is ready. I also have 2 other start-stop-daemons that depend on this once being started before they launch and are nearly identical.
#! /bin/sh
# chkconfig... |
I was trying to write a program that will read a collection of strings from the user, and then end the moment it encounters a ".". So then I write a do-while loop.
I came across a something like this:
string temp;
vector<string> params;
do
{
cin >> temp;
if (temp == ".")
break;
params.push_back(tem... |
I have the task to create a function that adds some messages to the page and another to show them in last to first order with a jQuery slideDown() effect.
jsFiddle
jQuery("#input1").click(function()
{
//Represents the first function to add the messages
jQuery.each(["<div>1</div>", "<div>2</div>", "<div>3</div>"... |
The question of the cleanest way to write a loop that executes some action between each iteration has always interested me.
In a sense, what is the best way in c/c++ to implement this fictional construct:
for (...) {
} between {
}
Using such a construct you could trivially implement string join(): (pseudocode)
result ... |
I'm pretty new to Haskell and was playing around with some number manipulation in different bases when I had to write an integer logarithm function for my task.
I don't mean discrete/modular logs, but simply greatest x s/t b^x <= n
I developed a few versions and can't decide which I like best. Was hoping to hear what ... |
I have a WCF client which passes Self-Tracking Entities to a WPF application built with MVVM. The application itself has a dynamic interface. Users can select which objects they want visible in their Work area depending on what role they are in or what task they are doing.
My self-tracking entities have quite a few Na... |
This is a follow-up to the question that I posted earlier regarding my interpreter.
After a lot of help, I refactored my code and added more functionality to it. Now, it allows users to declare functions like so
func function_name param1 param2 param3 . / param3 * param1 param2
or like this
func to_radians deg . * d... |
Here's the issue. When I build an asp.net application I create a singleton to read the values from the web.config file so that the values are only read once and gives a slight speed increase to the app. I basically do the following :
/// <summary>
/// Static class that handles the web.config reading.
/// </summary>
p... |
I wrote a wrapper around boost-mpl and transformed it to an sql engine. It is a compile time sql thing, not related to normal databases. I have not finished it completely. I have some problem with the interface.
A template meta program run in compile time. So input data always present in compile time that is why I orga... |
The subroutine below, GetDetailsQuarterly, accepts two dates. Then it writes out each quarter that falls within the date range. It also gives the first and last day of the quarter. I really don't like how the beginning and ending dates of each quarter are hardcoded. I don't believe this solution accounts for leap year ... |
Can you please help me split this method to reuse the repeating code?
Any advice/comments on the code are welcome.
//This method will return Dictionary object having key/value pair of keywords and URLs.
//Keywords are single word or bunch of words from db.
//Value in dictionary is URLs against each key (keyword).
/... |
I'm learning Haskell at the moment, and have just written my first useful module - a parser fo INI files. I used Parsec. I'd like to know what can be improved here - or maybe I did some things completely wrong and there is a better way. Thanks.
module IniFile (iniFileToMap) where
import Text.ParserCombinators.Parsec
i... |
I would like to write the following piece of code cleaner and more efficient, any comments will be greatly appreciated:
Dim dt As DataTable = SomeDataTable
For Each dr As DataRow In dt.Rows
Dim myColumn As String = dr("column").Trim().ToUpper()
For Each group As String In collection
If (... |
How to make this code better?
if (Program.Data.DataBase.TryOpenDataBase())
{
bool result;
DataBase= new Program.Data.DataBase(out result);
if (!result)
{
if (Program.DataBase!= null)
Program.DataBase.Dispose();
Program.DataBase= null;
Log.WriteERROR("Can not open database");
Application.... |
I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ASPX page, everything uses untyped DataSets instead of returning objects, makes gratuitous use of Session and QueryString ... |
Note: This was originally posted at SO, and as per the recommendation moving to this form.
In my effort to learn JS on the backdrop of SVG development, I got lot of help from SO so far. The answer to previous query was the best to understand closure; its usage and caveats in very short time. While continuing on the sa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.