Skip to content

Instantly share code, notes, and snippets.

@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 '^#'
@johntyree
johntyree / OUTPUT
Last active November 24, 2023 08:27
C++ TRACE and LOG macros.
TRACE: /dev/shm/test.cpp(27): int main(int, char**)
TRACE: /dev/shm/test.cpp(20): void where_am_I(int)
LOG: /dev/shm/test.cpp(22): void where_am_I(int)
x(3) is odd.
LOG: /dev/shm/test.h(10): void where_are_you()
Here I am!
@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 / soundcloud
Created January 3, 2014 03:50
Add soundcloud streams to your mpd playlist
#!/usr/bin/env python3
# coding: utf8
# GistID: 8232376
import optparse
import sys
from subprocess import check_call
from urllib.parse import urlparse, quote, urlencode
@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(
#!/bin/bash
# Don't put duplicate lines in the history
export HISTCONTROL=ignoredups
# Store a lot history entries in a file for grep-age
shopt -s histappend
export HISTFILE=~/long_history
export HISTFILESIZE=50000
@johntyree
johntyree / splitpatch.rb
Created February 5, 2013 21:27
Ruby script for splitting a patch by file or into hunks.
#!/usr/bin/env ruby
# GistID: 4717831
#
# splitpatch is a simple script to split a patch up into multiple patch files.
# if the --hunks option is provided on the command line, each hunk gets its
# own patchfile.
#
# Copyright (C) 2007, Peter Hutterer <peter@cs.unisa.edu.au>
#
# This program is free software; you can redistribute it and/or modify
@johntyree
johntyree / pdf_split_by_bookmark.pl
Created February 3, 2012 14:09
Split PDF by bookmark (pdftk)
#!/usr/bin/env perl
use 5.013;
use warnings;
use Data::Dumper;
use File::Basename;
use File::Spec::Functions;
use File::Path qw(make_path);
my $pdftk = `/usr/bin/which pdftk`;
@johntyree
johntyree / history_vol.py
Last active February 26, 2020 04:24
Calculate annualized volatility from historical data.
#/usr/bin/env python
from pandas import np
from pandas.io.data import DataReader
def historical_volatility(sym, days):
"Return the annualized stddev of daily log returns of `sym`."
try:
quotes = DataReader(sym, 'yahoo')['Close'][-days:]
@johntyree
johntyree / a.pyx
Last active May 17, 2018 12:26
C vs. C++ in Cython.
# coding: utf8
# distutils: language = c++
# distutils: sources = b.cpp
# Using C calling convention works with "cdef extern ..." directly; no
# hpp header.
# Without it we need to use the cdef extern from "b.hpp": ... declaration.
# Implicitly forces C calling convenction?
cdef extern void c()