Skip to content

Instantly share code, notes, and snippets.

@saolsen
saolsen / number-to-binary.rkt
Created August 26, 2014 16:39
number to binary
#lang racket
(define (get-spaces-inner n spaces)
(define current-space (car spaces))
(if (> current-space n)
(cdr spaces)
(get-spaces-inner n (cons (* current-space 2) spaces))))
(define (get-spaces n)
(get-spaces-inner n '(1)))
#include <stdlib.h>
int main(int nargs, char * args[])
{
void* vp = malloc(sizeof(char) * 5);
const char* ip = (char*)(vp);
free(ip);
}
@saolsen
saolsen / gist:2661381
Created May 11, 2012 18:01
Auth Code
(ns jammer.crypto
(:import
(javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)
(java.math BigInteger)))
;; Functions used for authenticating pusher clients.
;; The crypto stuff is ripped out of the middle of the real clojure
;; pusher library by bblimke
;; https://github.com/bblimke/clj-pusher
@saolsen
saolsen / build_web
Created August 15, 2012 21:59
clojure apps on dotcloud
#!/bin/bash
lein upgrade
lein deps
lein uberjar my-main-namespace.core
cp ./*-standalone.jar ~/run.jar
@saolsen
saolsen / capturetheflag.py
Created November 28, 2012 15:32
My code to capture the flag on the last stripe ctf level
#!usr/bin/env python
# Stephen Olsen
# Script used to hack the stripe ctf level 8 PasswordDB.
# Captures the flag!
import requests
import re
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
# global
@saolsen
saolsen / addjquery.js
Created December 6, 2012 21:18
Add JQuery to the page (for when you need to hack stuff)
// paste into web console
s = document.createElement('script');
s.setAttribute("type", "text/javascript");
s.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js");
document.getElementsByTagName("head")[0].appendChild(s);
@saolsen
saolsen / core.clj
Last active December 14, 2015 09:29
markerbot
(ns markerbot.core
(:require [taoensso.timbre :as log]
[clojure.data.json :as json]
[clojure.string :as s]
[clj-http.client :as client])
(:import (java.net Socket)
(java.io PrintWriter InputStreamReader BufferedReader))
(:gen-class))
;; marksy
@saolsen
saolsen / gist:5305308
Last active December 15, 2015 18:39
reduce!
(defn reducer
;; Removes 5 and the item after it from a sequence.
[{:keys [flag seq]} item]
(cond
flag {:flag false :seq seq}
(= item 5) {:flag true :seq seq}
:else {:flag false :seq (conj seq item)}))
(:seq (reduce reducer {:flag false :seq []} [1 2 3 4 5 6 7 8 9 10]))
@saolsen
saolsen / profiling.clj
Last active December 15, 2015 23:29
ghetto profiler
(ns game.macros.profiling)
;; Must require this and also
;; (:use [game.profiling :only [start-time! stop-time!]])
(defmacro profile
"Wraps the body in the game.profiling calls"
[function-name & body]
`(let [profile# (start-time! ~function-name)
result# ~@body]
@saolsen
saolsen / particles-simulate.cljs
Last active December 30, 2015 07:59
particle simulation
(ns saolsen.particles-simulate
(:require [saolsen.draw-2d :as draw]))
;; Simple simulated neutonian physics.
(defn integrate-particle
"Moves the particle a distance based on it's velocity
P = P + V*dt
Simple collisions with walls reverse velocity.
Returns a new particle.
"