Skip to content

Instantly share code, notes, and snippets.

View begriffs's full-sized avatar

Joe Nelson begriffs

View GitHub Profile
@begriffs
begriffs / eq_classes.js
Last active December 16, 2015 19:39
Given a set (actually an array) and a symmetric relation (actually a boolean function), this divides the set into the equivalence classes of the reflexive and transitive closure of the relation.
function eq_classes(set, rel) {
var classes = {}, connected_stack, root,
stack_top, elt, pushed_more;
while(set.length > 0) {
root = set.shift();
classes[root] = [root];
connected_stack = [root];
while(connected_stack.length > 0) {
@begriffs
begriffs / eq_classes_example.js
Last active December 16, 2015 19:39
Example using eq_classes on the relation "differs by three"
eq_classes(
[0,1,2,3,4,5,6,7,8],
function(a,b) { return Math.abs(a-b) === 3; }
);
// returns {0: [0,3,6], 1: [1,4,7], 2: [2,5,8]}
@begriffs
begriffs / gist:5561121
Created May 11, 2013 19:34
Nodejitsu deploy error
info: Welcome to Nodejitsu begriffs
info: jitsu v0.12.10-2, node v0.10.5
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in node server.js
debug: { method: 'GET',
debug: uri: 'https://api.nodejitsu.com/apps/begriffs/pace',
debug: headers:
debug: { Authorization: '*****************************************************************',
debug: 'Content-Type': 'application/json' },
@begriffs
begriffs / MyModule.js
Created May 31, 2013 13:03
A CommonJS module which is AMD compatible
if (typeof define !== 'function') {
/* jshint latedef:false */
var define = require('amdefine')(module);
}
define(function () {
function MyModule() {
// ...
}
@begriffs
begriffs / commonjs_require.js
Created May 31, 2013 16:32
How to use your module from CommonJS
var mod = new (require('my-module'));
@begriffs
begriffs / amd.js
Created May 31, 2013 16:34
Using your module in AMD
require(['my-module'], function (MyModule) {
var mod = new MyModule();
});
<body>
<div>
Zip code:
<input type='text' id='zipcode' value=''/>
<button id="lookup">Lookup City</button>
</div>
<div>
City, State
<input type='text' id='city'/>, <input type='text' id='state'/>
</div>
@begriffs
begriffs / masonry.html
Created July 10, 2013 03:29
Using masonry
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/masonry/3.0.0/masonry.pkgd.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {
var container = document.querySelector('body');
var msnry = new Masonry( container, {
itemSelector: 'div'
});
ghci> -- yawn
ghci> 5 == 5
true
ghci> 5 == "a string"
<interactive>:3:1:
No instance for (Num [Char]) arising from the literal `5'
Possible fix: add an instance declaration for (Num [Char])
In the first argument of `(==)', namely `5'
In the expression: 5 == "a string"
ghci> :t (==)
(==) :: Eq a => a -> a -> Bool