Skip to content

Instantly share code, notes, and snippets.

@ncweinhold
ncweinhold / Learning gevent
Created April 16, 2011 22:06
quick 5 minute script to simple serve a hard coded page
from gevent import monkey
from gevent import wsgi
monkey.patch_all()
PORT = 8080
SIMPLE_PAGE = """<html><head><title>Simple Page</title></head><body><h1>Hello World</h1><p>Simple Gevent Page</p></body></html>"""
def application(env, start_response):
@ncweinhold
ncweinhold / gist:924369
Created April 17, 2011 19:11
Quick concurrent f7u12 image downloader - learning gevent
import gevent
from gevent import monkey
from BeautifulSoup import BeautifulSoup
import os
import urllib2
monkey.patch_all()
front_page = "http://www.reddit.com/r/fffffffuuuuuuuuuuuu/"
@ncweinhold
ncweinhold / gist:945139
Created April 27, 2011 20:33
First exercises from The Little Schemer using Common Lisp
(defun atom? (x)
(not (listp x)))
(defun lat? (x)
(cond
((null x) t)
((atom? (car x)) (lat? (cdr x)))
(t nil)))
(defun member? (a lat)
@ncweinhold
ncweinhold / gist:985749
Created May 22, 2011 18:55
Getting started with lispbuilder-sdl
(defpackage #:hello-world-sdl
(:use :cl)
(:export :main))
(in-package :hello-world-sdl)
(defparameter *screen-width* 640)
(defparameter *screen-height* 480)
(defparameter *bg-color* sdl:*black*)
(defparameter *text-color* sdl:*white*)
@ncweinhold
ncweinhold / main.c
Created May 25, 2011 20:44
Calling Gambit-C scheme functions from C
#include <stdio.h>
#define ___VERSION 406001
#include "gambit.h"
#include "somescheme.h"
#define SCHEME_LIBRARY_LINKER ____20_somescheme__
___BEGIN_C_LINKAGE
@ncweinhold
ncweinhold / snake.py
Created May 30, 2011 19:53
curses snake WIP
import curses
import time
class Direction(object):
NORTH=0
EAST=1
SOUTH=2
WEST=3
class Position(object):
@ncweinhold
ncweinhold / gist:1011280
Created June 6, 2011 22:45
different ways of summing lists of numbers
#lang racket
(define (my-sum-1 lst)
(cond
((null? lst) 0)
(else (+ (car lst) (my-sum-1 (cdr lst))))))
(define (my-sum-2 lst)
(define (my-sum-iter res lst)
(cond
@ncweinhold
ncweinhold / gist:1062572
Created July 3, 2011 20:18
Dabbling with Tornado
import sqlite3
import os.path
import tornado.httpserver
import tornado.ioloop
import tornado.web
class TestApplication(tornado.web.Application):
def __init__(self):
handlers = [
@ncweinhold
ncweinhold / main.go
Created June 10, 2012 19:48
Dabbling with Go
package main
import (
"net/http"
"fmt"
)
func main() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/about", aboutHandler)
;; This is based on the solution given here http://programmingpraxis.com/2009/04/21/probabilistic-spell-checking/2/
;; just ported to common lisp
(defvar *k* 7)
(defvar *m* 1000000)
(defvar *bloom* (make-array *m* :initial-element nil))
(defun key (i word)
(let* ((c (string (code-char (+ i 96))))