Skip to content

Instantly share code, notes, and snippets.

@theirix
theirix / listclosed.rb
Created December 4, 2010 15:45
Relocate rtorrent session file to another dl/watch location
#!/usr/bin/env ruby
require 'rubygems'
require 'xmlrpc/client'
require 'bencode'
require 'fileutils'
mode = :list if ARGV[0] == nil
if ARGV[0] == nil
mode = :list
import java.util.Collections;
import java.util.Iterator;
import java.util.Vector;
public class testClass {
public static void main(String[] args) {
System.out.println("Hello World");
weirdClass wc = new weirdClass();
@theirix
theirix / macsolutions-tracker.rb
Created May 19, 2011 15:34
Tracks a ticket in macsolutions.ru
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
require 'nokogiri'
unless ARGV.size == 2
STDERR.puts "$0 trackid last-four-phone-digits"
exit 1
end
@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`