Skip to content

Instantly share code, notes, and snippets.

View kakra's full-sized avatar
🏠
Let's inject fun into Linux Gaming

Kai Krakow kakra

🏠
Let's inject fun into Linux Gaming
View GitHub Profile
@kakra
kakra / with_statement.rb
Created August 2, 2009 05:55
A ruby implementation of python's with statement
# A ruby implementation of python's with statement
#
# not sure if this is semantically identical, it was meant as a small excercise
module WithStatement
def with(*objs)
raise "no block given" unless block_given?
options = objs.unshift! if objs.last.is_a? Hash
@kakra
kakra / mp4creator.rb
Created November 11, 2008 11:56
RVideo Extensions
module RVideo
module Tools
class Mp4creator
include AbstractTool::InstanceMethods
attr_reader :raw_metadata
def tool_command
'mp4creator'
end
@kakra
kakra / shorten-mp3-names.rb
Created September 28, 2008 22:22
Useful if your mp3 player doesn't like fancy long filenames
#!/usr/bin/env ruby
#
# Useful if your mp3 player doesn't like fancy long filenames
#
require 'digest/sha1'
Dir.glob("*.mp3") do |f|
name = f.downcase.split(".");
next if name.length < 2
@kakra
kakra / gist:11975
Created September 22, 2008 12:21
AdoDBRecord usage example
<?php
require('adodbrecord/init.php'); # v0.5 or higher required
# CREATE TABLE cars (id INTEGER PRIMARY KEY,
# brand VARCHAR(50),
# color VARCHAR(50),
# destination VARCHAR(50)
# )
require_once("AdoDBRecord://Car_Base");
@kakra
kakra / weekday.rb
Created September 22, 2008 12:15
How to apply case-when on lambdas
#!/usr/bin/env ruby
class Proc
def ===(*parameters)
self.call(*parameters)
end
end
sunday = Proc.new { |time| time.wday == 0 }
monday = Proc.new { |time| time.wday == 1 }