Skip to content

Instantly share code, notes, and snippets.

View siers's full-sized avatar
:octocat:

Raitis Veinbahs siers

:octocat:
View GitHub Profile
@siers
siers / trans-console-railway.rb
Created April 8, 2013 09:59
send serialized data from one ruby console to another
def _open name, mode
fn = "/tmp/.marshal.store.#{ name.to_s.gsub(/[^\w]/, '') }"
File.open(fn, mode)
end
# burry some_data => :significant_name
def b opts
data, name = opts.first
name = name.chr if name.is_a? Fixnum # in case of b stuff => ?a for 1.8.7
(f = _open(name, 'w')).write((m = Marshal.dump(data)))
@siers
siers / mixin.coffee
Created April 2, 2013 06:51
I want dem mixins in mai coffeescripts whenever I have jQuery.
importize = (mixin, module) ->
$.extend($.extend({}, mixin), module)
@siers
siers / digital.rb
Created March 30, 2013 18:57
answer to the question how do I draw digital numbers in ruby?
#!/usr/bin/env ruby
$, = ' '
class Digits
RAW = [
" 111 ",
"4 2",
"4 2",
" 333 ",
@siers
siers / rails-daemon-wrapper.sh
Created March 14, 2013 13:12
wrapper for rails -d functionality
r() {
if [ -z "$1" ]; then
rails
return
fi
case "$1" in
start)
shift
rails s -d "$@"
@siers
siers / fjzz
Created March 11, 2013 10:25
find me some jazz from reddit, requires ack, zsh
#!/bin/zsh
surl="http://www.reddit.com/r/jazz/search?q=%s&restrict_sr=on&sort=relevance&t=all"
url="http://www.reddit.com/r/jazz/"
find() {
curl -s $1 | ack -o "https?://(www.)?youtu[^'\"&]+"
}
parse() {
@siers
siers / update.rb
Created February 28, 2013 11:27
Fetches and assembles timetable from school's website into a more usable form.
#!/usr/bin/env ruby
require 'rubygems'
require 'pry'
require 'nokogiri'
require 'mini_magick'
require 'digest'
W = 412
H = 600
@siers
siers / mmap.c
Created January 19, 2013 12:26
mmap for darwin and linux(might work on some other platforms too)
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/mman.h>
#define SHMLEN sizeof(int) * 2
#define TIMES 30
@siers
siers / physics.rb
Created October 23, 2012 21:48
Catching object in orbit with variable catcher force
#!/usr/bin/env ruby
require 'matrix'
module Drawing
ZOOM = 0.5
SCALE = 40
def clear
@@clear ||= %x{clear}
@siers
siers / extract.rb
Created September 26, 2012 20:52
Savelk kompaktus pasaku HTMLus.
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
require 'pry'
def wrap(title, content)
<<-TEMPLATE
<!DOCTYPE html>
<html>
@siers
siers / backgammon-distribution.rb
Created August 28, 2012 13:13
Dice sum distribution
#!/usr/bin/env ruby
T = 50000
def n
rand(6) + 1
end
def title(x)
puts x
puts "*" * x.length