Skip to content

Instantly share code, notes, and snippets.

@theirix
theirix / plot.rb
Created May 31, 2011 12:32
Plot unicode graph using gnuplot/svg
#!/usr/bin/env ruby
require 'fileutils'
def base_dir
File.dirname(File.expand_path(__FILE__))
end
def read_matrix path, file
IO.readlines(File.join(path, file))\
@theirix
theirix / gist:1031609
Created June 17, 2011 15:09
Split array to chunks
def chunks a, size
chunk_count = a.size/size
chunk_count -= 1 if (a.size % size) == 0
(0..chunk_count).map do |k|
a.slice(k*size, size)
end
end
chunks((1...100).to_a, 20).each { |x| puts x.inspect }
We couldn’t find that file to show.
@theirix
theirix / striplinks.rb
Created September 11, 2011 15:42
Strip specific wikipedia links from a HTML document
@theirix
theirix / renamesrt
Created October 17, 2011 16:57
Rename srt file by the movie episode name
#!/usr/bin/env ruby
require 'fileutils'
raise 'This is ruby 1.9 script' if RUBY_VERSION =~ /^1\.8/
def process file, simulate
raise 'Please point at movie file' if (File.extname(file) == '.srt' || !File.file?(file))
name = File.basename(file)
@theirix
theirix / magnet2uri.rb
Created February 8, 2012 11:26
magnet2uri [PROPER]
#!/usr/bin/env ruby
require 'uri'
magnet = URI.unescape ARGV.first
benc = "d10:magnet-uri#{magnet.size}:#{magnet}e"
exit(1) unless magnet =~ /xt=urn:btih:([a-zA-Z0-9]+)/
File.open("meta-#{$1}.torrent", 'w') { |f| f.write benc }
#[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
#echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"
# vim: ft=ruby
@theirix
theirix / unilabel.sh
Created March 1, 2012 21:15
Detect disk volume label
#!/bin/sh
VOL=$1
if [ -z "$VOL" ] ; then
echo Usage: $0 vol
exit 1
fi
LABEL=""
command -v e2label > /dev/null && [ -z "$LABEL" ] && LABEL=`e2label $VOL 2>/dev/null`
command -v dosfslabel > /dev/null && [ -z "$LABEL" ] && LABEL=`dosfslabel $VOL 2>/dev/null`
command -v ntfslabel > /dev/null && [ -z "$LABEL" ] && LABEL=`ntfslabel -f $VOL 2>/dev/null`
@theirix
theirix / 80-pmount.rules
Created March 1, 2012 21:49
pmount udev rule
# automounting usb flash drives
ACTION=="add", SUBSYSTEM=="block", KERNEL=="[sh]d[b-z][0-9]*",RUN+="/usr/bin/pmount --sync --umask 000 %k %c"
ACTION=="remove", SUBSYSTEM=="block", KERNEL=="[sh]d[b-z][0-9]*",RUN+="/usr/bin/pumount /dev/%k"
@theirix
theirix / tiff2djvu
Created May 14, 2012 10:47
Convert TIFFs to a DJVu file
#!/bin/sh
set -e
DJVUPATH=/usr/local/djvulibre/bin/
djvuname=$1
shift
for file in $* ; do
base=`echo $file | sed 's/\.[^\.]*$//'`
djvus="$djvus $base.djvu"
ppms="$ppms $base.ppm"
echo $base ...
@theirix
theirix / makefile
Created May 31, 2012 17:24
LaTeX + BibTeX universal makefile
NAME=report
BIBROOT=$(PWD)/../..
.PHONY: FORCE_MAKE
all: $(NAME).pdf
%.pdf: %.tex FORCE_MAKE
BIBINPUTS=$(BIBROOT) latexmk -pdf -dvi- -ps- $<