Skip to content

Instantly share code, notes, and snippets.

@jaseg
jaseg / bcsucks.sh
Last active August 29, 2015 14:13
gnu bc flakiness
newton~ <3 bc -l
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
# thanks to matti for this
*1
(standard_in) 1: syntax error
*1
1
@jaseg
jaseg / test.c
Created January 9, 2015 01:06
Extremely simple ctypes example
// compile with $ gcc -o test.so -shared test.c
int fnord(int a, int b){
return a+4*b-1;
}
@jaseg
jaseg / luapy.py
Created January 9, 2015 01:02
How to run some lua from python via ctypes
import ctypes as ct
lua = ct.CDLL('liblua.so.5.2')
lua.luaL_newstate.restype = ct.c_void_p
lua.lua_tolstring.restype = ct.c_char_p
st = lua.luaL_newstate()
def foo(st):
print(lua.lua_tolstring(st, 1, 0).value.decode())
/*
* Copyright (c) 1997-2006 Motoyuki Kasahara
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
@jaseg
jaseg / gist:3e0c29b635f969ab46cd
Created September 28, 2014 11:51
Number of global variables in the ZSH source tree
newton~/d/z/Src <3 egrep -in 'mod_export.*;' **.c|wc -l
191
@jaseg
jaseg / gist:b6bc71d7e857260dded2
Created September 27, 2014 10:59
BBC Radio 3 international 320k AAC+ streams
# The following command will give you a list of BBC streams that can be accessed from anywhere since BBC only does their geoIP filtering on access of the stream *playlist*, not on access of the stream itself.
curl -sx http://[INSERT UK HTTP PROXY HERE]/ 'http://www.bbc.co.uk/radio/listen/live/r3_aaclca.pls'|egrep -o 'http://.*$'
# Low-bitrate international stream URLs look like this:
# http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio3_q?foobarbaz
# Notice the "intl" there.
# High-bitrate domestic stream URLs look like this:
# http://bbcmedia.ic.llnwd.net/stream/bbcmedia_lc1_radio3_p?foobarbaz
# Notice the lack of "intl" there.
@jaseg
jaseg / mpv.py
Last active August 29, 2015 14:05
mpv python interface using ctypes
from ctypes import *
import threading
import os
import asyncio
# vim: ts=4 sw=4
backend = CDLL('libmpv.so')
@jaseg
jaseg / gist:83d65e81729a45608770
Last active August 29, 2015 14:05
Interfacing with mpv from python via ctypes
newton~ <3 ipython3
Python 3.4.1 (default, May 19 2014, 17:23:49)
Type "copyright", "credits" or "license" for more information.
IPython 2.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
@jaseg
jaseg / gist:26f770d9e8c309e8f5ae
Last active August 29, 2015 14:04
Automatically log in to the shittiest of all shitty hotel wifis
#!/usr/bin/env python
import time
import bs4
import requests
def log(*args):
print(time.strftime('\x1B[93m[%m-%d %H:%M:%S]\x1B[0m'), *args+('\x1B[0m',))
def logon(res):
@jaseg
jaseg / gist:ef83d89b39ae69fad07a
Created July 23, 2014 23:54
Doing 3D projection in a few lines of python to render a rotating tetraeder to SVG
#!/usr/bin/env python3
import numpy as np
from math import sin, cos, pi, sqrt
import svgwrite
import itertools
def cam(f):
""" Returns a camera matrix for the given focal length """
return np.array(((1,0,0,0),
(0,1,0,0),