Skip to content

Instantly share code, notes, and snippets.

View nu7hatch's full-sized avatar

Krzysztof Kowalik nu7hatch

  • Warsaw, Poland
View GitHub Profile
require "rubygems"
require "sinatra/base"
require "padrino"
class Foo < Sinatra::Base
get("/bar") {
"Hello world!"
}
end
# Line size can be calculated with system stty command (it works on linux/unix
# and windows):
#
# `stty size`.split.last.to_i
#
def line_break(text, line_size, delim="\n")
words, result, sum = text.split, [], 0
words.each do |word|
result << delim and sum=0 if (sum+word.size) > line_size
result << word+" "
@nu7hatch
nu7hatch / helpers.rb
Created October 15, 2010 08:56
Simple links shortening
# It produces shorten version of given url.
#
# p truncate_url("http://example.com/hello.html")
# p truncate_url("http://example.com/yada-yada-yada/foobar/hello.html", :length => 40)
#
# will produce:
#
# "http://example.com/hello.html"
# "http://example.com/...foobar/hello.html"
def truncate_url(url, options={})
@nu7hatch
nu7hatch / spec_helper.rb
Created October 17, 2010 21:46
Testing standard input with RSpec
...
module Helpers
# Replace standard input with faked one StringIO.
def fake_stdin(*args)
begin
$stdin = StringIO.new
$stdin.puts(args.shift) until args.empty?
$stdin.rewind
yield
module Padrino::Foundation::Simple
# ... some core things
end
module Padrino::Foundation::Complex
self.registered(app)
app.register Padrino::Rendering
app.register Padrino::Routing
app.register Padrino::Helpers
# ...
class MyApp1 < Padrino::Application
register SassInitializer
register Padrino::Helpers
register Padrino::Mailer
register Padrino::Warden
enable :sessions
set :auth_use_referrer, true
set :auth_failure_path, "/login"
nu7hatch@abyss:/home/nu7hatch/dev/erl/rebar-test$ ./rebar create-app appid=rebar-test
==> rebar-test (create-app)
ERROR: 'create-app' failed while processing /home/nu7hatch/dev/erl/rebar-test: {'EXIT',{undef,[{escript,foldl,
[#Fun<rebar_templater.0.114075285>,[],
"/home/nu7hatch/dev/erl/rebar-test/rebar"]},
{rebar_templater,cache_escript_files,0},
{rebar_templater,create,2},
{rebar_core,run_modules,4},
{rebar_core,execute,4},
{rebar_core,process_dir,4},
@nu7hatch
nu7hatch / freenode.sh
Created November 13, 2010 21:55
Quick connect + authorize to irc.freenode.org
#!/bin/bash
stty -echo
read -p "Password: " passw
stty echo
irssi -c irc.freenode.org -n nu7hatch -w $passw
@nu7hatch
nu7hatch / gist:676193
Created November 14, 2010 23:06
The smallest workflow initializer!
#!/usr/bin/env python
# Probably the smallest script to initialize workflow of your projects. Usage:
#
# * copy script to your bin
# * make the $HOME/.workflow directory
# * write plain bash/sh bootstraper, eg:
#
# #!/bin/bash
# path=/path/to/your/project
@nu7hatch
nu7hatch / .conkyrc
Created December 5, 2010 22:52
My awesome conky rings :D
default_color white
own_window_colour white
alignment top_right
max_user_text 16384
max_specials 512
gap_x 0
gap_y 40
no_buffers yes
uppercase no
cpu_avg_samples 2