Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
drewlesueur / file.md
Created November 28, 2012 22:00
test md

this is a title

foo

@drewlesueur
drewlesueur / y_combinator.md
Created June 27, 2012 06:21
How to generate the Y-Combinator in coffeescript

How to Generate the Y-Combinator in CoffeeScript

Problem

For fun, let's say you are programming in a language that doesn't allow variable assignments and you still want to make a recursive function. Although you can't assign variables, you can use functions (and enclosed function arguments). Can you make a function recursive without calling it by name?

Lets try implementing the factorial function. First with a function calling itself by name, then with a funtion that never calls itself by name

Here is the implementation of factorial that calls itself by name. It's a simple recursive function

@drewlesueur
drewlesueur / need_y_combinator.coffee
Created June 26, 2012 20:34
need_y_combinator.coffee
# normal factorial
factorial = (x) ->
if x == 1 then return 1
return x * factorial(x - 1)
console.log factorial(6) #720
# new factorial that doesn't reference itself
factorialGenerator = (fac) ->
(x) ->
@drewlesueur
drewlesueur / gist:2908335
Created June 11, 2012 03:13
vba (Visual Basic for Excel)
Sub mycro()
'
' mycro Macro
'
' Keyboard Shortcut: Ctrl+e
'
ActiveCell.FormulaR1C1 = "yo dawg"
Range("I9").Select
Dim ws As Worksheet
@drewlesueur
drewlesueur / fakedate.js
Created May 17, 2012 22:49
Attempt to mock a constructor
var withFakeDate = function (fn) {
var oldDate = Date;
var FakeDate = function () {
var self = new oldDate();
self.fakeDateWasHere = true;
return self;
};
var oldGetFullYear = Date.prototype.getFullYear;
Date.prototype.getFullYear = function () {
return 1996;
@drewlesueur
drewlesueur / gist:1896594
Created February 24, 2012 01:38
ssl stuff
#first generate a key for your domain
openssl genrsa -out yourdomain.com.key 2048
#then generate the request
openssl req -new -key yourdomain.com.key -out yourdomain.com.csr
#http://mikegrouchy.com/blog/setting-up-nginx-with-ssl-and-godaddy.html
@drewlesueur
drewlesueur / gist:1492122
Created December 18, 2011 02:04
events, callbacks and scope
server.setUpSocket(socket) ->
socket.on "data", (data) ->
server.allData.push(data)
#-----------------
server.setUpSocket(socket) ->
socket.on "data", _.bind(server.onSocketData, null, socket)
@drewlesueur
drewlesueur / alternative_syntax.dart
Created November 7, 2011 04:50
My First Dart Closure
main() {
var incMaker = () {
var x = 0;
var inc = () {
x += 1;
return x;
};
return inc;
};
var inc = incMaker();
class Point {
Point(this.x, this.y);
distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return Math.sqrt(dx * dx + dy * dy);
}
var x, y;
}
@drewlesueur
drewlesueur / presenter.js
Created November 5, 2011 11:57
Backbone presenter
Presenter = function() {
this.initialize();
}
Presenter.extend = Backbone.View.extend
_.extend(Presenter.prototype, Backbone.Events, {
initialize: function () {}
})