Skip to content

Instantly share code, notes, and snippets.

@colelawrence
colelawrence / promise-keeper.coffee
Last active August 29, 2015 14:04
Promise Keeper Super Class
{ Deferred } = require 'promise.coffee'
class PromiseKeeper
constructor: (value=null) ->
def = new Deferred
def.resolve(value)
@promise = def.promise
@_data = {}
set: (name, setValue) ->
@colelawrence
colelawrence / node-style-lift.coffee
Created July 16, 2014 13:09
Node style lifting function for promises
# Promises
{ Deferred } = require 'promise.coffee'
fs = require 'fs'
emptyPromise = ->
def = new Deferred
def.resolve(undefined)
return def.promise
; AutoHotkey Version: 1.x
; Author: Cole Lawrence
; Script Function:
; Use capslock as control key
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetCapslockState AlwaysOff
Capslock::Ctrl
@colelawrence
colelawrence / isEq.coffee
Created August 4, 2014 20:43
object is equal
# Helper function: compares objects
isEq = (a, b) ->
if a isnt b
if typeof a is 'object' and typeof b is 'object' and a? and b?
if Object.keys(a).length isnt Object.keys(b).length
return false
for ak, av of a
bv = b[ak]
if not isEq bv, av
randomString = (len)->
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={[}]:;\"'|\\<,>.?/"
res = ""
res += chars[Math.random()*chars.length|0] for num in [0..len]
res
// found on http://snipplr.com/view/36790/jscookies--my-simple-easy-pure-js-javascript-cookies-function/
// Modified with Regexes by Cole Lawrence (ZombieHippie)
// create my jsCookies function
var jsCookies = {
// this gets a cookie and returns the cookies value, if no cookies it returns blank ""
get: function(c_name) {
var regex = new RegExp(c_name + "=([^;]+)");
@colelawrence
colelawrence / bookmark-link-courses.js
Last active August 29, 2015 14:09
MOState course numbers linker bookmark
@colelawrence
colelawrence / tokenStore.js
Created January 5, 2015 16:49
Stores randomized tokens and data with expiration.
var tokenStore = {
store: {},
lastExpirationRemoval: Date.now(),
EXPIRATION_REMOVAL_INTERVAL: 30 * 60 * 1000, // 30 minutes
EXPIRATION: 2 * 60 * 1000, // 2 minutes
getToken: function(token) {
var stored = this.store[token]
if (stored != null)
if (stored.expires < Date.now())
throw Error("Token expired.")
@colelawrence
colelawrence / formatString.coffee
Created January 7, 2015 17:23
Super simple string handlebars formatter
formatString = (string, locals) ->
string.replace /{{([a-zA-Z\.]+)}}/g, (match, value) ->
values = value.split(".")
value = locals
while key = values.shift()
value = value[key]
String value
Say formatString "Hello {{user.name}}", {user:name:"Cole"}
@colelawrence
colelawrence / typename-nesting.cpp
Last active May 16, 2022 15:25
C++ vector<type>::iterator implementation example
/*
Name: Cole Lawrence
Date: April 13th, 2015
Assignment: Asn6
Platform/IDE: Windows 8/MVSCPP2010Express
Description:
Here we have written a LinkedDeque class that inherits a majority of its code from
a created Singly Linked List called SLinkedList. In addition, we have exceptions in
place that are written in an effort to conform to good programming practice. In
addition to this we also have NodeList which supports iterators using its nested