Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / state-example-game.js
Created November 9, 2012 04:41
Implementation of a State monad in JavaScript
/*
* Example of a state monad in use. This is adapted from an example on
* the Haskell Wiki:
* http://www.haskell.org/haskellwiki/State_Monad#Complete_and_Concrete_Example_1
*/
require(['state', 'qunit'], function(state, qunit) {
/*
* playGame() is a recursive function that given an array of moves
* defines an algorithm for constructing a final game score. Along
@hallettj
hallettj / acorn.js
Created May 27, 2013 23:57
Defining a module in a way that will work in several different environments. This is from Acorn <https://github.com/marijnh/acorn.git>, a JavaScript parser.
(function(mod) {
if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS
if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD
mod(self.acorn || (self.acorn = {})); // Plain browser env
})(function(exports) {
"use strict";
exports.version = "0.2.0";
/* ... */
@hallettj
hallettj / for.sibilant
Created July 29, 2013 01:22
Demonstration of a monad comprehension macro in Sibilant, a Lisp dialect that compiles to JavaScript. See http://sibilantjs.info/ for information on Sibilant.
; A monad comprehension is a syntactic construct that translates
; synchronous-looking code into a callback-based implementation. Monads
; are a very general abstraction - which means that monad comprehensions
; have more expressive power than other sync-to-async code
; transformations.
; Here is an example that uses jQuery's $.get method to fetch resources:
(def post-with-author (id)
(for
@hallettj
hallettj / mori.markdown
Created September 10, 2013 23:26
Slides from my presentation on Mori, a library that makes data structures from the ClojureScript standard library available to plain JavaScript apps.
2013-09-16 07:21:40,143 INFO com.buddycloud.mediaserver.Main - buddycloud Media Server HTTP server started!
2013-09-16 07:21:41,481 ERROR com.buddycloud.mediaserver.Main - Media Server XMPP Component could not be started.
org.xmpp.component.ComponentException: java.io.EOFException: input contained no data
at org.jivesoftware.whack.ExternalComponent.connect(ExternalComponent.java:267) ~[whack.jar:na]
at org.jivesoftware.whack.ExternalComponentManager.addComponent(ExternalComponentManager.java:211) ~[whack.jar:na]
at org.jivesoftware.whack.ExternalComponentManager.addComponent(ExternalComponentManager.java:191) ~[whack.jar:na]
at com.buddycloud.mediaserver.Main.createXMPPComponent(Main.java:138) ~[buddycloud-media-server-0.1.jar:na]
at com.buddycloud.mediaserver.Main.startXMPPToolBox(Main.java:105) ~[buddycloud-media-server-0.1.jar:na]
at com.buddycloud.mediaserver.Main.main(Main.java:51) ~[buddycloud-media-server-0.1.jar:na]
Caused by: java.io.EOFException: in
@hallettj
hallettj / mori.markdown
Created October 25, 2013 21:57
Functional data structures in JavaScript with Mori

Functional data structures in JavaScript with Mori

http://swannodette.github.io/mori/

the basic immutable structure: list

var l0 = mori.list(3, 4, 5);

var l1 = mori.cons(2, l0);

@hallettj
hallettj / mkManifest.js
Last active December 28, 2015 09:39
Substack Rube Goldburg Challenge: runs some input through as many of substack's npm modules as possible.
var fs = require('fs');
var exec = require('child_process').exec;
var templ_ = fs.readFileSync('package.json.template', { encoding: 'UTF-8' });
var templ = JSON.parse(templ_);
var deps = {};
exec("npm search substack | grep '=substack' | awk '{ print $1 }'", function(err, stdout) {
var lines = stdout.toString('UTF-8');
lines.split("\n").forEach(function(line) {
import Control.Applicative ((<$>), (<*>))
import Control.Concurrent.Async (Concurrently(..), runConcurrently)
import Data.Monoid (Monoid, (<>), mappend, mempty)
instance (Monoid a) => Monoid (IO a) where
mappend x y = runConcurrently $ (<>) <$> Concurrently x <*> Concurrently y
mempty = return mempty
-- example:
action = getLine <> getLine
@hallettj
hallettj / 1. xmodmap .f90
Last active May 7, 2024 03:04
I inverted the number row on my keyboard - meaning that pressing the keys produces symbols by default, and I type numbers by holding shift. As a programmer I use symbols frequently, so I think that this will be advantageous. Here are the details of my configuration.
!
! Invert number row
!
! This changes the behavior of keys in the number row, but does not
! affect the number pad.
!
keycode 10 = exclam 1 1 exclam
keycode 11 = at 2 2 at
keycode 12 = numbersign 3 3 numbersign
keycode 13 = dollar 4 4 dollar
@hallettj
hallettj / tmux.conf .sh
Last active August 29, 2015 13:57
tmux key bindings to run common git commands in a new split
# open vim in a new split
bind e split-window -h -c "#{pane_current_path}" sensible-editor
# shortcuts for common git operations
bind g split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git lg'
bind D split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git diff'
bind C split-window -h -c "#{pane_current_path}" 'GIT_PAGER="less -+F" git diff --cached'
bind A split-window -h -c "#{pane_current_path}" 'git add -p'