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 / gen.hs
Created May 29, 2014 03:11
gnuplot-sphere.hs
View gen.hs
import Numeric.Matrix hiding (map)
import Data.List.Split
import Text.Printf
type Rotation = Matrix D
rotMatrixX :: D -> Rotation
rotMatrixX rad = fromList . chunksOf 3 $
1 : 0 : 0 :
0 : cos rad : -sin rad :
@siers
siers / skittles.diff
Created August 13, 2014 03:26
A diff for coreutils/src/ls.c to add a purple-colored skittles to every directory listing, even in ls -R.
View skittles.diff
diff --git a/src/ls.c b/src/ls.c
index cd5996e..102599b 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2668,6 +2668,10 @@ print_dir (char const *name, char const *realname, bool command_line_arg)
process_signals ();
}
+ total_blocks += gobble_file ("skittles", sock,
+ 0,
@siers
siers / demo
Created June 28, 2015 22:36
Extracts paragraphs to lines in files to allow generic operations be used
View demo
demo % cat file
1. Chox4ez9
Oov5iedeiF
ea7eapheeR
2. tu0ahTho
sheit5Kash
aiHiewae1i
3. Gau2Jesu
@siers
siers / backgammon-distribution.rb
Created August 28, 2012 13:13
Dice sum distribution
View backgammon-distribution.rb
#!/usr/bin/env ruby
T = 50000
def n
rand(6) + 1
end
def title(x)
puts x
puts "*" * x.length
@siers
siers / extract.rb
Created September 26, 2012 20:52
Savelk kompaktus pasaku HTMLus.
View extract.rb
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
require 'pry'
def wrap(title, content)
<<-TEMPLATE
<!DOCTYPE html>
<html>
@siers
siers / physics.rb
Created October 23, 2012 21:48
Catching object in orbit with variable catcher force
View physics.rb
#!/usr/bin/env ruby
require 'matrix'
module Drawing
ZOOM = 0.5
SCALE = 40
def clear
@@clear ||= %x{clear}
@siers
siers / mmap.c
Created January 19, 2013 12:26
mmap for darwin and linux(might work on some other platforms too)
View mmap.c
#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 / plot
Created December 11, 2015 13:56
Plot the active hours of an IRC channel based on your own logs.
View plot
#!/bin/sh
# usage: n=$(pwd); cd ~/.weechat/logs; cp $n/{plot,activity} .; ./plot *math.weechatlog
# Be aware that if your client's not receiving messages 24/7,
# some hours will not receive coverage or some might be underrepresented.
# Furthermore, using a bouncer with a long scrollback will create pikes.
! [ -z "$1" ] && (tail -n100000 "$1" | ./activity > data)
[ -e data ] && gnuplot -p -e \
@siers
siers / send.c
Last active December 12, 2015 12:00
Obsoleted by xdotool at the time of its creation without me knowing for a couple of years.
View send.c
// gcc -Wall -Wextra -ggdb -o send send.c
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <X11/keysymdef.h>
@siers
siers / update.rb
Created February 28, 2013 11:27
Fetches and assembles timetable from school's website into a more usable form.
View update.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'pry'
require 'nokogiri'
require 'mini_magick'
require 'digest'
W = 412
H = 600