Skip to content

Instantly share code, notes, and snippets.

View nu7hatch's full-sized avatar

Krzysztof Kowalik nu7hatch

  • Warsaw, Poland
View GitHub Profile
@nu7hatch
nu7hatch / example.html
Created September 7, 2010 14:20
Simple banner rotator with jQuery
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<link href="rotate.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="rotate.js"></script>
<script type="text/javascript">
$(window).load(function() {
startRotator("#rotator");
})
</script>
@nu7hatch
nu7hatch / app.rb
Created April 21, 2011 03:05
OmniAuth login in popup
require 'rubygems'
require 'sinatra'
require 'omniauth/oauth'
set :sessions, true
set :layout, true
use OmniAuth::Builder do
provider :twitter, 'key', 'secret'
end
@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
@nu7hatch
nu7hatch / vagrant.md
Created October 30, 2012 21:11
Vagrant boxes

What is Vagrant? It's a neat command line interface and toolchain at top of VirtualBox, which allows you to create and manage virtual "boxes" - vm instances with stuff configured for your project.

Why is it awesome?

Because you don't have to setup everything for the project every time when hop in, you do it once using one of the base boxes, you package it and populate *.box file across all project members. When you need to add some software (new database, cache soft, etc), you just have to add it once, and ping everyone to update their boxes. Briliant, isn't it?

It works great also with designers and non-technical people, download and setup of a box takes few minutes and they don't have to polute their machines with all the project related software.

Above all, no more excuses "works for me", or "works on development, but not on the production" - as boxes are made to simulate production environment as much as possible.

var fillSocialCounters = function() {
$('a.socialBtn').fillSocialCounter()
}
$(document).ready(function() {
var text = $('.post h1.title').text()
, url = document.location.href
$('a[rel="facebook"]').facebookButton({ text: text, url: url })
$('a[rel="twitter"]').twitterButton({ text: text, url: url, via: "nu7hatch" })
@nu7hatch
nu7hatch / bench
Last active December 19, 2015 11:09
chris@abyss · 1.9.3 · /tmp/bench_list
$ time go run slice.go
real 0m0.858s
user 0m0.732s
sys 0m0.112s
chris@abyss · 1.9.3 · /tmp/bench_list
$ time go run list.go
real 0m1.556s
module Hashifiable
def hashify(*args)
hashified = {}
args.each do |arg|
case arg
when Symbol
hashified[arg] = lambda { |obj| obj.send(arg) }
when Hash
arg.each do |key, proc|
@nu7hatch
nu7hatch / _utils.bash
Last active December 18, 2015 16:29
Bash utilities for setup scripts.
# _utils.bash --- Utilities used across all the scripts.
ERROR_FILE="/tmp/setup_script_error.msg"
# Checks if user has cowsay installed, and if it does
# then uses it to display the message.
cowsay_or_echo()
{
cowsay=`which cowsay`
cowsay_eyes=$1; shift
int numberOfSheeps = 0;
for (; numberOfSheeps < sheeps.length; numberOfSheeps++) {
if (me.asleep) break;
}
@nu7hatch
nu7hatch / _utils.bash
Created April 15, 2013 04:44
Utilities for setup scripts.
# _utils.sh --- Utilities used across all the scripts.
set -e
set -o pipefail
# Prints spaces as a prefix to the command's output.
function prefixed {
sed -e "s/^/ /"
}