Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / gist:1706229
Created January 30, 2012 19:41
parsing java class files with defbinstruct
(ql:quickload 'babel)
(defbinstruct class-file
(magic 4) ;; values are bytes when types aren't specified
(minor-version 2)
(major-version 2)
(constant-pool (:struct constant-pool))
(access-flags 2)
(this-class 2)
(super-class 2)
@osa1
osa1 / Main.hs
Created February 18, 2012 18:21
I wrote 103 lines of imperative code in Haskell :P
module Main where
{-
I wrote this to get a bettern understanding of Haskell way of doing
side effects, which turns out, is not much fun :)
-}
import Todo
@osa1
osa1 / gist:1861099
Created February 18, 2012 21:46
Utils for PRINTing and READing CL standard hash-tables, inspired by Haskell's fromList
(in-package :cl-user)
(defpackage :m-utils
(:use :cl)
(:export :from-list :print-ht))
(in-package m-utils)
(defmacro from-list (list &rest params)
"A hash-table generator inspired by Haskell's fromList."
@osa1
osa1 / gist:1892046
Created February 23, 2012 10:01
dummy app I'm using to see Graphics.UI.SDL.Event fired by some actions
import Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Events
quitHandler :: IO ()
quitHandler = do
e <- waitEvent
putStrLn $ show e
case e of
Quit -> return ()
otherwise -> quitHandler
@osa1
osa1 / DotUtils.hs
Created February 27, 2012 19:45
simple Trie and Trie Zipper implementation
module DotUtils where
{-
- Some helper functions to create graphviz representation of Trie structures.
-}
import Trie
import qualified Data.Map as Map
@osa1
osa1 / gist:1959252
Created March 2, 2012 15:45
my sublime text keybindings to get a more vim-like behavior
[
{ "keys": ["ctrl+u"], "command": "move", "args": {"by": "pages", "forward": false} },
{ "keys": ["ctrl+d"], "command": "move", "args": {"by": "pages", "forward": true} },
{ "keys": ["ctrl+h"], "command": "focus_group", "args": { "group": 0 } },
{ "keys": ["ctrl+l"], "command": "focus_group", "args": { "group": 1 } },
{ "keys": ["ctrl+w"], "command": "delete_word", "args": { "forward": false } },
@osa1
osa1 / gist:1977648
Created March 5, 2012 09:40
authentication decorator
def requires_authentication(f):
def df(request):
json_response = {"result": "fail"}
if request.user.is_authenticated and request.user.is_active:
json_response.update(f(request))
return HttpResponse(json.dumps(json_response), mimetype="application/json")
return df
@osa1
osa1 / gist:2000733
Created March 8, 2012 12:09
find lastfm artist recommendations based on top artists listened by an user
(ns lastfm
(:require [clojure.string :as str]
[clojure.java.io :as io]
[clj-http.client :as client]
[clojure.zip :as zip]
[clojure.xml :as xml])
(:use [clojure.data.zip.xml]))
(defn- parse-str [s]
@osa1
osa1 / gist:2021424
Created March 12, 2012 12:08
bencode decoder
;;; Bencode decoder. Converts bencoded strings/streams to CL data
;;; structures.
;;; Usage:
;;; (bencode:decode stream-or-string)
;;; Bencode dictionaries will be converted to alists and lists will be
;;; converted to CL lists.
;;; TODO: error handling.
class Reader:
def __init__(self, form):
self.form = form
self.index = 0
def seek_char(self):
if self.index >= len(self.form):
return None
return self.form[self.index]