Skip to content

Instantly share code, notes, and snippets.

View cristianrasch's full-sized avatar
💭
I may be slow to respond.

Cristian Rasch cristianrasch

💭
I may be slow to respond.
View GitHub Profile
dir = ARGV.first || Dir.pwd
Dir.chdir dir unless dir == Dir.pwd
avi_files, srt_files = Dir.glob('*.avi'), Dir.glob('*.srt')
avi_files.each do |avi_file|
md = avi_file.match /s\d+e\d+/i
if md
srt_file = srt_files.find {|srt_file| srt_file =~ Regexp.new(md.to_s, true)}
@cristianrasch
cristianrasch / lacie-unlam_backup.rb
Created June 10, 2011 21:32
Script de backup del dominio lacie-unlam.org
# flesystem: http://www.lacie-unlam.org:2082/getbackup/backup-lacie-unlam.org-6-10-2011.tar.gz
# db : http://www.lacie-unlam.org:2082/getsqlbackup/lacieunl_mysql.sql.gz
require "date"
require "net/http"
today = Date.today
backup_dir = today.strftime("%d_%m_%Y")
Dir.mkdir(backup_dir) unless File.directory?(backup_dir)
user, passwd = ENV["hosting_user"], ENV["hosting_passwd"]
@cristianrasch
cristianrasch / iterators
Created December 5, 2011 17:46
A blast from the past
// c++
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(1);
@cristianrasch
cristianrasch / gist:2200542
Created March 25, 2012 22:48
Making fun of Python's OOP weirdness
#!/usr/bin/env python
class P(object):
def foo(self):
print "Called P's foo()"
# print "Called %s's foo()" % self.__class__.__name__
class C(P):
def foo(self):
# P.foo(self)
@cristianrasch
cristianrasch / queue.py
Created March 31, 2012 16:48
Python queue implementation
#!/usr/bin/env python
class Queue(object):
def __init__(self):
self.arr = []
def enqueue(self, val):
self.arr.insert(0, val)
def dequeue(self):
@cristianrasch
cristianrasch / queue.rb
Created March 31, 2012 16:49
Ruby queue implementation
#!/usr/bin/env ruby
class Queue
def initialize
@arr = []
end
def enqueue(val)
@arr << val
end
@cristianrasch
cristianrasch / re.py
Created April 2, 2012 01:43
Python's re#findall
import re
# returns a list of 2-tuples: [('a', 'b'), ('c', 'd'), ('e', 'f')]
re.findall(r'([a-z])\d([a-z])\s', 'a1b c2d e3f ')
# returns a list of strings: ['1', '2', '3']
re.findall(r'[a-z](\d)[a-z]\s', 'a1b c2d e3f ')
@cristianrasch
cristianrasch / loops.py
Created April 2, 2012 14:37
Python's for/while else loops
# 15-19 validate US telephone numbers with optional area code
# 800-555-1212, 555-1212, and also (800) 555-1212
regex = re.compile(r'(\d{3}-|\(\d{3}\)\s)?\d{3}-\d{4}')
for s in ['800-555-1212', '555-1212', '(800) 555-1212']:
match = re.match(regex, s)
if not match:
print 'Error! %s should be a valid telephone number' % s
break
else:
print 'All telephone numbers are valid, yey!'
@cristianrasch
cristianrasch / testing_on_debian_stable.sh
Created April 11, 2012 00:46
Install testing packages on Debian stable
# /etc/apt/apt.conf
APT::Default-Release "stable";
# add the testing repos' URLs to your /etc/apt/sources.list
apt-get update
apt-get -t testing install foo
@cristianrasch
cristianrasch / pianobar_debian.sh
Created April 19, 2012 19:19
Compiling pianobar from source on Debian Squeeze
# install the building dependencies
sudo aptitude install libevent-pthreads-2.0-5 libao-dev gnutls-dev libmad0-dev libfaad-dev libjson0-dev
rm -rf ~/Soft/pianobar
git clone git://github.com/PromyLOPh/pianobar.git ~/Soft/pianobar
cd ~/Soft/pianobar
make
# all set, you can run pianobar directly from the source directory, alternatively run this command to have it installed:
[sudo make install]