Skip to content

Instantly share code, notes, and snippets.

View iNecas's full-sized avatar
💭
Happy hacking 👨 ⌨️ 💻

Ivan Necas iNecas

💭
Happy hacking 👨 ⌨️ 💻
View GitHub Profile
@iNecas
iNecas / find_duplicities.rb
Created February 21, 2011 12:44
finding duplicities in array in one line
comps = ["PC", "MAC", "PC", "PC", "LINUX", "MAC", "DIDAKTIK"]
duplicities = comps.group_by{|x| x.first}.find_all{|k,v| v.size > 1}.map{|x| x.first}
duplicities # => ["MAC","PC"]
@iNecas
iNecas / files_tree_steps.rb
Created March 18, 2011 18:08
Cucumber step definition checking content of directory
# Usage:
#
# Then directory "tmp/sample" should have the following tree:
# """
# monday
# | beer.rb
# tuesday
# | vodka.php
# | wine.rb
# wednesday
@iNecas
iNecas / rescue_exception.rb
Created April 29, 2011 14:12
Why it is not a good idea to rescue without explicit exception type?
# Why it is not a good idea to rescue without explicit exception type?
# Because:
#
# begin
# "..."
# rescue
# end
#
# Handles only StandardError descendants (no Excpetion descendants catched)
def get_distribution env, id
self.repos(env).map do |repo|
repo.distributions.find_all {|d| d.id == id }
end
end
@iNecas
iNecas / 01-disable-ctrl-alt-backspace.conf
Created January 1, 2012 13:02
Disable ctrl-alt-backspace in X11
# Disable ctrl-alt-backpace (restart X11) server.
# Put into /etc/X11/xorg.conf.d
Section "ServerFlags"
Option "DontZap" "yes"
EndSection
@iNecas
iNecas / tmux.conf
Created April 14, 2012 21:57
tmux.conf
unbind C-b
set -g prefix F12
# Use vim-like keys for moving around
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind C-h select-pane -t :-
bind C-l select-pane -t :+
@iNecas
iNecas / .Xresources
Created April 14, 2012 22:03
Xresources for urxvt
*background: black
*foreground: white
xterm*background: #3c3c3c
urxvt*depth: 32
urxvt*background: rgba:1111/1111/1111/ffff
URxvt.scrollBar: false
URxvt.tabbed.tabbar-fg: 4
URxvt.tabbed.tabbar-bg: -1
@iNecas
iNecas / gist:2761470
Created May 21, 2012 09:27
More HEREDOCs at one line
[<<EOS1, <<EOS2, <<EOS3]
This is
an array
EOS1
of very very
very very
EOS2
long strings
EOS3
@iNecas
iNecas / align_indented.rb
Created May 28, 2012 15:08
Align indented
# shift indented text to the left as much as possible
def align_indented(text)
shift_left = text.lines.map { |l| l[/^\s*/].size }.min
text.lines.map { |l| l[shift_left..-1] }.join
end
puts align_indented(<<TEXT)
this is some
indented text
we would like to
@iNecas
iNecas / misused_meta.rb
Created June 27, 2012 20:03
Misusing ruby metaprogramming part I
%w[one two three].each do |method|
define_method method do |*args|
"My uebercool method #{method}"
end
end