Skip to content

Instantly share code, notes, and snippets.

@atheken
atheken / 0_ProductModel.cs
Created July 22, 2010 00:21
Multiple snippets of how to use NoRM to do common tasks, originally authored by: Anirudh Sanjeev (http://github.com/ninjagod)
//This is a model that will be used in each of the examples below.
public class Product
{
public Product()
{
// Default values are to be set here
Shipping = new Address();
}
public ObjectId _id{get;set;}
public double Price{get;set;}
@atheken
atheken / SampleCalls.cs
Created July 22, 2010 21:03
Using Expression trees to Curry a Lambda
var func = WrapLambda<Outie, Innie, bool>(j => j.BoolVal, "Inner").Compile();
var resultTrue = func(new Outie { Inner = new Innie { BoolVal = true } });
var resultFalse = func(new Outie { Inner = new Innie() });
@atheken
atheken / JSUnitTest.js
Created September 26, 2010 13:00
JavaScript Unit Test Creator
/*
via: http://javascriptweblog.wordpress.com/2010/09/20/auto-generating-javascript-unit-tests/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+JavascriptJavascript+(JavaScript,+JavaScript)
*/
var tester = {
testing: [],
console: window.console || {log: function(a) {window.status = a}, warn: alert},
defineBaseTests: function() {
this.baseTestBefore = [this.argumentsDefinedTest, this.thisBindingTest];
this.baseTestAfter = [this.returnTest];
#!/usr/bin/env ruby
require 'nokogiri'
require 'yaml'
class File
def writeline(value)
self.write(value + "\n")
end
end
/*
http://www.JSON.org/json2.js
2010-08-25
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
See http://www.JSON.org/js.html
@atheken
atheken / DB Module.cs
Created November 26, 2010 00:28
PiesApp.cs
using System;
using Manos;
namespace pies
{
public class DBModule : ManosModule
{
public DBModule ()
{
}
@atheken
atheken / jsonr.simple.js
Created December 3, 2010 23:11
Using JSONr
// 0. find your XML feed url and combine it with
// (ex. 'http://news.google.com?output=rss&q=javascript')
var jsonFeed = 'http://jsonr.com/json/news.google.com?output=rss&q=javascript'
//1. get the json and apply it.
jQuery.getJSON(jsonFeed,null,function(jsonObj){
//2. use the jsonObj for good.
alert(jsonObj);
});
@atheken
atheken / chunk.cs
Created January 8, 2011 19:31
ChunkIt
public class ChunkUtils
{
public static IEnumerable<T> Chunk(Func<int,IEnumerable<T>> chunkFunc){
var taken = 0;
var last = 0;
do{
last = taken;
var values = chunkFunc(taken);//taken is the "skip" count, the "take" count will have been closed into the chunkFunc.
foreach(var v in values)
@atheken
atheken / user.rb
Created April 30, 2011 15:21
Critique my model
# == Schema Information
# Schema version: 20110429204914
#
# Table name: users
#
# id :integer not null, primary key
# full_name :string(255)
# email :string(255)
# salt :string(255)
# created_at :datetime
# == Schema Information
# Schema version: 20110430183939
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255)
# created_at :datetime
# updated_at :datetime
#