Skip to content

Instantly share code, notes, and snippets.

@atheken
atheken / evaluate_cs.cs
Created January 1, 2013 21:50
Is this how you use mono's evaluator?
public static dynamic ParseFunc (string func, out string error)
{
dynamic retval = null;
error = null;
using (var ms = new MemoryStream()) {
using(var tr = new StreamWriter(ms)){
var settings = new CompilerSettings();
@atheken
atheken / LazyEnough.cs
Created November 4, 2012 22:15
A lazy, but not too lazy, memoization class.
using System;
namespace BlogUtils
{
/// <summary>
/// An extension of "Lazy of T, but with the twist that it will
/// reload the resource at periodic intervals (and on request, of course).
/// </summary>
public class LazyEnough<T>
{
/**
* Rangy, a cross-browser JavaScript range and selection library
* http://code.google.com/p/rangy/
*
* Copyright 2012, Tim Down
* Licensed under the MIT license.
* Version: 1.3alpha.675
* Build date: 23 June 2012
*/
window.rangy = (function() {
@atheken
atheken / rasterize.js
Created April 19, 2012 13:01
more rasters
var fs = require('fs');
var page = require('webpage').create(),
address,
output,
size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
phantom.exit();
@atheken
atheken / gist:2295777
Created April 3, 2012 21:57
Guid generator in Javascript.
(function(){
if(!window.String.UUID){
var matcher = /[xy]/g;
var replacer = function(c) {
var r = Math.random()*16|0;
var v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
};
//maybe shouldn't be modifying the global variable, but seems like the best place to put this.
window.String.UUID = function(){
# == Schema Information
# Schema version: 20110430183939
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255)
# created_at :datetime
# updated_at :datetime
#
@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
@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 / 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 / DB Module.cs
Created November 26, 2010 00:28
PiesApp.cs
using System;
using Manos;
namespace pies
{
public class DBModule : ManosModule
{
public DBModule ()
{
}