Skip to content

Instantly share code, notes, and snippets.

@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(){
@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();
/**
* 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 / 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>
{
@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();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
namespace Async.iOS
{
public static class Layout
{
@atheken
atheken / grunt_supervisor.js
Last active December 21, 2015 18:19
Stupid simple spawn, allows for supervisor to be run and prevents it from being restarted each time.
var proc = null;
grunt.registerTask('supervisor', function(){
if(!proc){
proc = grunt.util.spawn(this.options());
}
});
grunt.initConfig({
supervisor : {
@atheken
atheken / jade_shim.js
Created August 27, 2013 00:51
When you pre-compile your jade templates for the browser, interpolated locals will still require jade.escape, but it's a simple fix, and here it is!
// this is required in order to properly escape
// jade interpolation
jade = {
escape: function(html){
return String(html)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
namespace Async.iOS
{
public static class Layout
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
using System.Reflection;
using MonoTouch.Foundation;
namespace Praeclarum.UI
{