Skip to content

Instantly share code, notes, and snippets.

@johntyree
johntyree / arr.c
Created December 19, 2012 13:02
3D array indexing.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
int main(int argc, char* argv[]) {
int idim = 3;
int jdim = 4;
@johntyree
johntyree / ansi-attributes.py
Created December 19, 2012 12:27
ANSI attributes in Python
'''
Set ANSI Terminal Color and Attributes.
'''
from sys import stdout
esc = '%s['%chr(27)
reset = '%s0m'%esc
format = '1;%dm'
fgoffset, bgoffset = 30, 40
for k, v in dict(
@johntyree
johntyree / pymode.vim
Created December 13, 2012 19:26
Pass by 'reference' in VimL
fun! pymode#Toggle(toggle, msg) "{{{
let {a:toggle} = {a:toggle} ? 0 : 1
if {a:toggle}
echomsg a:msg." enabled"
else
echomsg a:msg." disabled"
endif
endfunction "}}}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def crank(V, L1, R1x, L2, R2x, dt, n, crumbs=[], callback=None):
V = V.copy()
dt *= 0.5
L1e = flatten_tensor(L1)
L1i = L1e.copy()
R1 = np.array(R1x).T
L2e = flatten_tensor(L2)
L2i = L2e.copy()
@johntyree
johntyree / AD_Greeks.hs
Last active October 12, 2015 02:18
Using Auto Differentiation to compute the Greeks.
module Main where
import Control.Comonad.Cofree
import Control.Lens
import Numeric.AD
import Numeric.AD.Types
import Text.Printf (printf)
function webview.init_funcs.mailto_hook (view, w)
view:add_signal("navigation-request", function (v, uri)
if string.match(string.lower(uri), "^mailto:") then
luakit.spawn(string.format("%s %q", "urxvtc -title mutt -e mutt", uri))
return false
end
end)
end
@johntyree
johntyree / codepad.py
Created October 17, 2012 16:54
Post to codepad.org from file or stdin.
#!/usr/bin/env python
import urllib
import urllib2
import sys
if len(sys.argv) > 1:
lang = sys.argv[1]
else:
@johntyree
johntyree / DrSyzygy_and_category_theory.txt
Created September 15, 2012 20:55
DrSyzygy and Category Theory
<hiptobecubic> @src Maybe
<lambdabot> data Maybe a = Nothing | Just a
<hiptobecubic> @src Monad
<lambdabot> class Monad m where
<lambdabot> (>>=) :: forall a b. m a -> (a -> m b) -> m b
<lambdabot> (>>) :: forall a b. m a -> m b -> m b
<lambdabot> return :: a -> m a
<lambdabot> fail :: String -> m a
<hiptobecubic> @src [] (>>)
<lambdabot> xs >> ys = concatMap (const ys) xs
@johntyree
johntyree / getBlockLists.sh
Last active March 9, 2024 12:32
Make one large blocklist from the bluetack lists on iblocklist.com
#!/usr/bin/env sh
# Download lists, unpack and filter, write to stdout
curl -s https://www.iblocklist.com/lists.php \
| sed -n "s/.*value='\(http:.*=bt_.*\)'.*/\1/p" \
| xargs wget -O - \
| gunzip \
| egrep -v '^#'