Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@ik5
ik5 / gist:0e10b413c6d9ae4dc712
Created June 20, 2012 18:53
human readable sizes
def human_size(size, si = false)
return '0' if size == 0
base = si ? 1000 : 1024
bytes = %w(B KB MB GB TB PB EB ZB YB)
cnt = Math.log(size, base).floor
size = size / (base * 1.0) ** cnt
fmt = size < 10 ? '%.1f %s' : '%i %s'
sprintf(fmt, size, bytes[cnt])
@ik5
ik5 / uname.rb
Created June 21, 2012 11:18
Using uname with FFI - Based on https://gist.github.com/895585
#!/usr/bin/env ruby
require 'rubygems'
require 'ffi'
module Uname
extend FFI::Library
ffi_lib FFI::CURRENT_PROCESS
@ik5
ik5 / case1.rb
Created July 31, 2012 11:06
case that does not work
a = {'one' => 1 }
puts "a.class = #{a.class}"
case a.class
when Hash
puts 'Hash'
else
puts 'not Hash'
end
@ik5
ik5 / case2.rb
Created July 31, 2012 11:09
case that works
a = {'one' => 1 }
puts "a.class = #{a.class}"
case a
when Hash
puts 'Hash'
else
puts 'not Hash'
end
@ik5
ik5 / sessoin.rb
Created August 1, 2012 08:09
redis_session example
require 'rubygems'
require 'redis_session'
session = Session::SessionClient.new(:prefix => 'add_test') # init the session
session.save('name', { 'name' => 'session'}) # Saving a content. Pure ruby content
restored = session.restore('name') # return to me a pure ruby content
puts restored.inspect
session.remove('name') # delete the key
@ik5
ik5 / gist:3549885
Created August 31, 2012 07:28
Here is part of the XML code from the Gtk3.gir file relating to the caption of the button:
<class name="Button"
c:symbol-prefix="button"
c:type="GtkButton"
parent="Bin"
glib:type-name="GtkButton"
glib:get-type="gtk_button_get_type"
glib:type-struct="ButtonClass">
<implements name="Atk.ImplementorIface"/>
<implements name="Actionable"/>
<implements name="Activatable"/>
@ik5
ik5 / gist:3549922
Created August 31, 2012 07:38
gir2pascal result
type
PGtkButton = ^TGtkButton;
TGtkButton = object(TGtkBin)
priv3: PGtkButtonPrivate;
function new: PGtkButton; cdecl; inline; static;
function get_label: Pgchar; cdecl; inline;
procedure set_label(label_: Pgchar); cdecl; inline;
property label_: Pgchar read get_label write set_label;
end;
@ik5
ik5 / gist:3549959
Created August 31, 2012 07:46
old gtk2 binding to pascal
type
PGtkButton = ^TGtkButton;
TGtkButton = record
bin : TGtkBin;
event_window : PGdkWindow;
label_text : Pgchar;
activate_timeout : guint;
flag0 : word;
end;
@ik5
ik5 / update.rb
Created September 14, 2012 23:16
updating my Lazarus 3rd party component directory
#!/usr/bin/env ruby
#
require 'rubygems'
require 'fileutils'
dirs = { 'bgracontrols' => { 'scm' => 'git', 'dir' => 'bgracontrols', 'levels' => 1},
'ccr' => { 'scm' => 'svn', 'dir' => 'ccr', 'levels' => 1},
'dcpcrypt' => { 'scm' => 'git', 'dir' => 'dcpcrypt', 'levels' => 1},
'fortres' => { 'scm' => 'svn', 'dir' => 'fortes4lazarus', 'levels' => 1},
@ik5
ik5 / gist:3874020
Created October 11, 2012 17:16
recursive rename file using bash, removing last 2 chars of the new name
recursivemv() {
for d in *; do
if [ -d $d ]; then
(cd $d; recursivemv);
else
mv "$d" ${d:0:-2}
fi
done
}