Skip to content

Instantly share code, notes, and snippets.

View basilfx's full-sized avatar

Bas Stottelaar basilfx

View GitHub Profile
@basilfx
basilfx / gist:3147003
Created July 19, 2012 21:37
Massive Music Quiz ft. Google Search
jQuery("body").append('<div><div id="google_search" style="width: 400px;margin-right: 0px;;margin-left: 1000px; border: 1px solid #000; background-color: white;"></div>');
jQuery("#container").css({ margin : "inherit"});
(function(e){e.fn.gSearch=function(h){var a=e.extend({},e.fn.gSearch.defaults,h);if(a.search_text==undefined)return this;if(a.search_text=="")return this;return this.each(function(){var f=e(this);f.addClass("google-search-results");a.pagination=a.pagination=="false"||a.pagination==false?false:true;f.html('<span style="text-decoration: blink;">Loading...</span>');_google_search=new google.search.WebSearch;var d="";a.count*1>4&&_google_search.setResultSetSize(google.search.Search.LARGE_RESULTSET);if(a.site.length> 0){a.site=a.site.substring(0,4)=="www."?a.site.substring(4,a.site.length):a.site;a.site.length>0&&_google_search.setSiteRestriction(a.site)}_google_search.setSearchCompleteCallback(this,function(){d="";if(_google_search.results&&_google_search.results.length>0){var c=_google_search.
@basilfx
basilfx / gist:5070834
Created March 2, 2013 12:41
ZMQStream with multiprocessing.
from multiprocessing import Process
import zmq, random
from zmq.eventloop import ioloop, zmqstream
ioloop.install()
def child(port, i):
def on_message(message):
print message
@basilfx
basilfx / grub
Last active August 29, 2015 13:57
Ubuntu 14.04 Powersave NAS
GRUB_CMDLINE_LINUX_DEFAULT="drm.vblankoffdelay=1 intel_pstate=enable"
@basilfx
basilfx / latex.py
Created May 13, 2014 14:18
Matplotlib LaTeX look
import matplotlib
TEXT_WIDTH = 452.9679 #pt
FONT_NORMAL_SIZE = 10.0 #pt
PT_TO_INCH = 0.01388888889
# Configure matplotlib to render LaTeX style
matplotlib.rc("font", family="serif", size=FONT_NORMAL_SIZE)
matplotlib.rc("text", usetex=True)
@basilfx
basilfx / cache.start
Created May 14, 2014 09:16
Flashcache Upstart script
#!/bin/sh
# $2 is the /dev/mapper/IDENTIFIER
# $3 is the name of the cache, as specified by Flashcache
# Tune parameters
sysctl -w "dev.flashcache.$3.fallow_delay=3600"
sysctl -w "dev.flashcache.$3.dirty_thresh_pct=80"
# Verify disk structure
@basilfx
basilfx / utils.py
Created May 18, 2014 20:56
Gevent download, cache and stream
import os
import shutil
import gevent
def download_and_cache(remote_fd, target_file, on_error=None, on_completed=None):
"""
"""
temp_file = "%s.temp" % target_file
@basilfx
basilfx / GUIDE.md
Last active July 23, 2019 17:46
Install MT7601U WiFi adapter driver for OpenELEC (Raspberry Pi)

I bought (a few) Wireless-N WiFi adapters from Ebay to enable WiFi on my OpenELEC-featured Raspberry Pi. I was hoping it would work out-of-the-box, but that wasn't true. Some attempts such as modprobe rt2x00usb did not work as expected because it's a totally different chipset.

The output of lsusb:

...
Bus 001 Device 004: ID 148f:7601 Ralink Technology, Corp.
...
@basilfx
basilfx / tmux-notify.pl
Last active November 29, 2021 11:01
Irssi and tmux-notify
use strict;
use warnings;
use vars qw($VERSION %IRSSI);
use Irssi;
# Script info
$VERSION = '0.1';
%IRSSI = (
authors => 'Bas Stottelaar',
@basilfx
basilfx / mycaption.sty
Last active August 29, 2015 14:06
Captions in the margin of a two-sided book, including wide (margin) images.
%!TEX root=test.tex
%%
%% This is file `mycaption.sty',
%% generated with the docstrip utility + positioning modifications.
%%
%% The original source files were:
%%
%% mcaption.dtx (with options: `package')
%%
@basilfx
basilfx / toc.js
Created December 28, 2014 13:36
Github Markdown TOC generator
var sections = $("h2");
var output = "";
for (var i = 0; i < sections.length; i++) {
var link = $(sections[i]).find("a").prop("href");
var text = $(sections[i]).text().trim()
output = output + "* [" + text + "](" + link + ")\n";
}