Skip to content

Instantly share code, notes, and snippets.

View killerswan's full-sized avatar

Kevin Cantú killerswan

View GitHub Profile
@killerswan
killerswan / scrypt.diff
Created May 11, 2012 09:43
Add crypto_scrypt to the Python script package
diff -ru scrypt-0.5.3/src/scrypt2.c scrypt-mod/src/scrypt2.c
--- scrypt-0.5.3/src/scrypt2.c 2011-02-19 06:56:07.000000000 -0800
+++ scrypt-mod/src/scrypt2.c 2012-05-12 01:19:06.933753937 -0700
@@ -27,6 +27,7 @@
#include <Python.h>
#include "scryptenc/scryptenc.h"
+#include "crypto/crypto_scrypt.h"
static PyObject *ScryptError;
@killerswan
killerswan / ff.py
Created May 10, 2012 01:15
more Python for GDB debugging
# (gdb) python execfile ("/home/kcantu/Desktop/gdbScripts/ff.py")
# given address as string
def contentOfStr (addy):
return gdb.parse_and_eval ('({nsIContent} ' + addy + ')')
# given content as gdb.Value
def nameOfContent (content):
# Ramanujan's PI algorithm, per Think Python
#
# >>> execfile("C:/[snip]/Desktop/ramanujan.py")
# >>> rpi()
import math
def rpi ():
k = 0
estimate = 0.0
@killerswan
killerswan / status-vs-image-attrs.hs
Created May 2, 2012 09:16
Haskell namespaces seem weak
-- snip
updateStatus :: Token -> String -> IO ()
updateStatus token status = runOAuthM token $ do
_ <- doRequest POST "statuses/update" [("status",status)]
return ()
data StatusAttr = ReplyTo String
| LatLon Double Double
| PlaceID String
@killerswan
killerswan / pip.hs
Created April 27, 2012 09:11
Test for a point within a polygon
-- Test for a point within a polygon
-- http://rosettacode.org/wiki/Ray-casting_algorithm#Haskell
import Data.Ratio
type Point = (Rational, Rational)
type Polygon = [Point]
data Line = Sloped {lineSlope, lineYIntercept :: Rational} |
Vert {lineXIntercept :: Rational}
@killerswan
killerswan / count.hs
Created April 26, 2012 07:22
Haskell back in awk's order of magnitude <_<
-- Kevin Cantu
-- April 2012
import Control.Monad (when)
import Data.Map (Map)
import Data.List
import Data.List.Split
import qualified Data.Map as M
import System.Environment
import System.IO
sed -e 's/,/;/' $1 | awk '{FS=";"; count[$2]++} END {for (jj in count) print ""count[jj]";",jj }'
@killerswan
killerswan / csv-freq-count.hs
Created April 25, 2012 23:06
Haskell BLOWS UP
-- Kevin Cantu
-- April 2012
-- Count location
--
-- runtime: 16s on one million lines of CSV
-- infinity secs on 3 million lines (RAM blows up)
-- (ip,lat.000,lon.000)
import Control.DeepSeq
import Control.Monad (when)
@killerswan
killerswan / filt.hs
Created April 25, 2012 08:50
CSV filtering
import Text.CSV
loadCSV =
do
eitherRecs <- parseCSVFromFile "sample.csv"
let records = case eitherRecs
of Left e -> error . show $ e
Right recs -> recs
return records
@killerswan
killerswan / map-of-lists.hs
Created April 25, 2012 08:17
Map of (total, list)
import Data.Map (Map)
import Data.List
import qualified Data.Map as M
newMap :: Map (Int, Int) (Int, [Int])
newMap = M.fromList []
updateMap key size =
M.insertWith' ins key (fromSingleVal size)
where