Skip to content

Instantly share code, notes, and snippets.

View strager's full-sized avatar

strager strager

View GitHub Profile
@strager
strager / steam.js
Created October 9, 2011 23:40
Get Steam username from UID
var http = require('http');
var steamUidRe = /<steamID64>(.*)<\/steamID64>/;
function getSteamUid(username, callback) {
var callbackCalled = false;
var req = http.request({
host: 'steamcommunity.com',
port: 80,
// Why does this code sample hang client
// connections if ASYNC === true?
//
// # Start server
// node test.js --sync port
// node test.js --async port
//
// # Test
// curl http://host:port/
/* before */
#wrapper #content .post .copy {
color: #6e7173;
padding: 10px;
font-size: 13px;
line-height: 15px;
}
/* after */
#wrapper #content .post .copy {
@strager
strager / Map.as
Created March 22, 2012 19:09
AS3 Dictionary replacement
// AS3 Dictionary replacement
//
// Patterns to replace:
//
// import flash.utils.Dictionary;
// => import io.spaceport.util.Dictionary;
//
// var dict:Dictionary;
// => var dict:Map;
//
-- ghc -Wall -Werror -O2 test_java.hs -o test_java.exe && strip test_java.exe
import Control.Applicative
import Control.Monad (guard)
import Data.Bits
import Data.List (nub)
import Data.Maybe (catMaybes)
import System.Exit
import System.FilePath
import System.IO
@strager
strager / tictactoe.ktn
Created May 29, 2013 05:44
Tic-tac-toe CLI game in Kitten
def concat ([[a]] -> [a]): (a)[] ([a] [a] -> [a]){ + } foldDown
def ; ([a] a -> [a]): push
def show_board_cell (Char -> Char){ }
def cell_number_to_index (Int -> Int):
8 __swap -
def show_board_cell_at ([Char] Int -> Char):
$ cabal-dev build
Building b-0.1.0.0...
Preprocessing library b-0.1.0.0...
[14 of 14] Compiling Data.DynSetMR ( Data/DynSetMR.hs, dist/build/Data/DynSetMR.o )
Data/DynSetMR.hs:79:23:
My brain just exploded
I can't handle pattern bindings for existential or GADT data constructors.
Instead, use a case-expression, or do-notation, to unpack the constructor.
In the pattern: Dictionary
{-# LANGUAGE ScopedTypeVariables #-}
f :: forall a. Int => Int
f = undefined
@strager
strager / unhelpful-stack-trace.ghci
Created July 26, 2013 06:35
Unhelpful stack trace
ghci> :hist 1000
-1 : putState (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:(53,1)-(55,43))
-2 : getBuildRuleParallel (/Users/mg/Projects/b/B/Monad.hs:136:10-37)
-3 : get:getAnswer (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:(163,3)-(165,23))
-4 : get:getAnswer (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:(163,3)-(165,23))
-5 : get:getAnswer (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:(163,3)-(165,23))
-6 : getBuildRuleParallel (/Users/mg/Projects/b/B/Monad.hs:136:10-37)
-7 : == (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:82:7-20)
-8 : == (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:82:7-38)
-9 : == (/Users/mg/Projects/b/B/Oracle/InMemory/Pure.hs:(82,7)-(83,35))
@strager
strager / tuple.js
Last active December 20, 2015 09:29
function tuple(/* ... */) {
var args = arguments;
return function unpackTuple(f) {
return f.apply(this, args);
};
}
var t = tuple(1, 2, 3);
t(function (a, b, c) {