Skip to content

Instantly share code, notes, and snippets.

View ianpreston's full-sized avatar

Ian Preston ianpreston

View GitHub Profile
var sys = require("sys"),
http = require("http"),
querystring = require("querystring"),
htmlparser = require("htmlparser"),
soupselect = require("soupselect"),
irc = require("irc");
/**
* Wrapper for making an HTTP request, reading the data, instantiating a htmlparser.Parser
* and parsing the page. htmlparserHandlerFunction will be passed to htmlparser.DefualtHandler.
@ianpreston
ianpreston / fabfile.py
Created December 10, 2012 04:57
Tiny, fabric-based static site generator
from fabric.api import local
import jinja2
import sys
import os
import os.path
import webbrowser
proj_base_path = sys.path[0]
pages_path = os.path.join(proj_base_path, 'pages')
build_path = os.path.join(proj_base_path, 'build')
@ianpreston
ianpreston / gist:5629463
Created May 22, 2013 17:48
Pyramid Sort
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] elements = { 1, 8, 9, 13, 2, 7 };
@ianpreston
ianpreston / bayes.hs
Last active August 29, 2015 14:02
Naive Bayes Classifier in Haskell. Does it work? No idea.
data FeatureVec =
FeatureVec { cls :: Int, feat :: [Bool] }
deriving (Show)
data ValueVec =
-- TODO: Need a better name for vals
ValueVec { cnt :: Int, vals :: [Int] }
deriving (Show)
type ProbVec = [Float]
; Assembly hello world for OSX
; So I can remember how to do basic shit in OSX
;
; $ nasm -g -f macho -o test.o test.asm
; $ ld -o a.out -e _main test.o -lSystem
bits 32
section .data
message db "Hello, world!", 10, 0
@ianpreston
ianpreston / hellogl.rkt
Created January 10, 2015 17:27
OpenGL Hello World
#lang racket/gui
(require sgl)
(require sgl/gl-vectors)
(define (render canvas dc)
(send canvas with-gl-context
(lambda ()
(gl-matrix-mode 'projection)
(gl-load-identity)
(gl-ortho -10 10 -10 10 -1 1)
@ianpreston
ianpreston / example0.ipy
Last active August 29, 2015 14:15
Memory leak examples
In [1]: import sys
In [2]: def test():
...: foo = "Hello, world!"
...: try:
...: raise Exception()
...: except Exception, e:
...: trace = sys.exc_info()[2]
...: return trace
...:
ian@dreadnought > virtualenv venv; . venv/bin/activate.fish
New python executable in venv/bin/python
Installing setuptools, pip...done.
(venv)ian@dreadnought > pip install urllib3
Downloading/unpacking urllib3
Downloading urllib3-1.10.2-py2-none-any.whl (77kB): 77kB downloaded
Installing collected packages: urllib3
Successfully installed urllib3
Cleaning up...
(venv)ian@dreadnought > mkdir foobar
#!/bin/sh
set -e
# Build the bootloader
cd src/bootloader
nasm -f bin main.asm -o ../../build/bootloader.bin
cd ../..
# Build the kernel
cd src/kernel/asm
import threadpool, math, os
randomize()
proc setRand(k: int, vals: var seq[int]) =
vals[k] = k * 2
if k < 7:
sleep(random(1000))
vals[k+1] = k * 2