Skip to content

Instantly share code, notes, and snippets.

Which thinkpad should I buy?

New Kbd Old Kbd
Small X230/X230t X220/X220t
Large T430/T430s T420/T420s
Station W530 W520/W510

#40 series (T440, X240, W540, etc)

@jaseg
jaseg / Makefile
Created May 2, 2014 05:43
How to write a signal handler in amd64 assembly
all:
gcc -Wall -o foo main.c test.S
@jaseg
jaseg / setup.py
Created May 19, 2014 14:41
Install npm with pip
#!/usr/bin/env python3
from distutils.core import setup
from setuptools.command.install import install
script = """#!/bin/sh
# A word about this shell script:
#
# It must work everywhere, including on systems that lack
# a /bin/bash, map 'sh' to ksh, ksh97, bash, ash, or zsh,
@jaseg
jaseg / fade.py
Created May 25, 2014 12:40
Rainbow terminal cursors
#!/usr/bin/env python
from colorsys import hsv_to_rgb
from time import sleep
from itertools import cycle
for i in cycle(range(100)):
print('\033]12;#{:02x}{:02x}{:02x}\007'.format(*map(lambda x: int(x*255), hsv_to_rgb(i/100, 1, 1))), end='', flush=True)
sleep(0.05)
@jaseg
jaseg / addall.py
Last active August 29, 2015 14:02
Pipe new releases from torrent index RSS feeds into transmission
#!/usr/bin/env python3
import time
import sys
from datetime import datetime
import feedparser
import requests
import json
import sqlite3
import ast
@jaseg
jaseg / gist:cce6a9d250c2d9a120bc
Created July 12, 2014 17:24
Play music links on a subreddit using ipython
In [1]: %rehashx
In [2]: import praw
In [3]: urls = [e.url.replace('https', 'http') for e in praw.Reddit('ipython').get_subreddit('indie_rock').get_hot(limit=30) if 'youtu' in e.url or 'soundcloud' in e.url]
In [4]: for url in urls:
!mpv --no-video "$url"
....:
Playing: http://www.youtube.com/watch?v=sXfLPNv-Axs
[quvi] Checking URL...
[stream] Video --vid=1 (vp8)
[stream] Audio (+) --aid=1 (*) (vorbis)
@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: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 / 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: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.