Skip to content

Instantly share code, notes, and snippets.

@EarlGray
EarlGray / mexp.lisp
Created September 12, 2012 13:14
Infix expressions in Lisp
;; M-expression to S-expression macro converter
;; Author: Dmytro Sirenko
;; License: BEERWARE
;;
;; Examples of usage:
;; (@ 2+2) => 4
;; (@ (98 + 11 + 17)/sqrt(9)) => 42.0
(defvar bin-ops '(+ - * /) )
@EarlGray
EarlGray / ukr.lisp
Created September 12, 2012 14:11
A small snippet translating lisp keywords into Ukrainian :)
; this is just an exercise, I don't want to use it in any serious code :)
(defmacro макрос (&body x)
`(defmacro ,@x))
(макрос переклад (англ укр)
`(макрос ,укр (&body параметри) `(,',англ ,@параметри)))
(макрос переклад-розкритого (англ укр)
(let ((розкрите укр))
@EarlGray
EarlGray / tone.py
Created September 12, 2012 14:13
A small WAV visualisation using PyQt
#! /usr/bin/python
from PyQt4 import QtCore
from PyQt4 import QtGui
import sys
import math
import struct
import wave
@EarlGray
EarlGray / week1.py
Created September 12, 2012 14:17
Standford Cryptography courses online - homeworks
'''
Question 1
Many Time Pad
Let us see what goes wrong when a stream cipher key is used more than once. Below are eleven
hex-encoded ciphertexts that are the result of encrypting eleven plaintexts with a stream
cipher, all with the same stream cipher key. Your goal is to decrypt the last ciphertext,
and submit the secret message within it as solution.
Hint: XOR the ciphertexts together, and consider what happens when a space is XORed with
@EarlGray
EarlGray / tar-patch.sh
Created July 20, 2013 13:48
Patching binary files with bash and xxd
#!/bin/bash
export CHECKSUM_AT=148
function joinlines {
while read line ; do
echo -n "$line"
done
}
@EarlGray
EarlGray / hellohapp.hs
Created September 30, 2013 15:06
Happstack logging snippets for a wordpress blog
import Happstack.Server
import System.Environment
import Control.Monad (when)
main = do
args <- getArgs
when (length args < 2) $ error "Usage: ./HelloHTTP "
simpleHTTP nullConf $ serveDirectory EnableBrowsing ["index.htm"] (head args)
@EarlGray
EarlGray / bmpdiff.hs
Created October 6, 2013 09:42
A very primitive motion detection system using `fswebcam` utility for capturing images from webcam on Linux Dependencies: fswebcam, ImageMagic, GHC.
import Data.Binary.Get as BG
import Data.Binary.Put as BP
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Internal as BI
import qualified Data.ByteString.Lazy as BL
import Data.Word
import Data.Int
@EarlGray
EarlGray / cleverptr.cpp
Last active January 1, 2016 13:19
C++ overloading
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
template <typename T>
class clever_ptr {
string log;
@EarlGray
EarlGray / SleepSort.hs
Last active August 29, 2015 14:12
sleepsort
module SleepSort (sleepsort) where
import Control.Concurrent
import Control.Concurrent.STM
worker chan timefun val = do
threadDelay $ timefun val
atomically $ writeTChan chan val
sleepsort :: (a -> Int) -> [a] -> IO [a]
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <iterator>
#include <algorithm>
int main() {
std::string s;
std::getline(std::cin, s);