Skip to content

Instantly share code, notes, and snippets.

View hubertlepicki's full-sized avatar

Hubert Łępicki hubertlepicki

View GitHub Profile
@hubertlepicki
hubertlepicki / files.exs
Created June 23, 2015 09:54
Elixir pattern matching makes you stop using if-clauses or exceptions
defmodule Files do
def run do
process_file File.read("hello.txt")
end
def process_file({:ok, contents}) do
IO.puts "File contents are here:"
IO.puts contents
end
@hubertlepicki
hubertlepicki / setup.sh
Created May 12, 2015 06:32
PhantomJS 2.0.1 on codeship
# I am pasting that into setup steps
# binary provided by the amazing Codeship.io support
PHANTOMJS_URL="https://s3.amazonaws.com/codeship.io/checkbot/binaries/phantomjs_2.0.1"
set -e
rm -rf ~/.phantomjs
wget --continue "${PHANTOMJS_URL}" -O "${HOME}/cache/phantomjs"
ln -s "${HOME}/cache/phantomjs" "${HOME}/bin/"
chmod +x "${HOME}/bin/phantomjs"
@hubertlepicki
hubertlepicki / click_link_patch.rb
Created March 26, 2015 22:03
Allow Capybara to click on links without href
@hubertlepicki
hubertlepicki / putin.rb
Created March 15, 2015 13:07
Putin's absence from twitter in days starting at given date
["2013-08-01", 27],
["2014-03-21", 24],
["2014-09-05", 18],
["2013-07-05", 18],
["2014-08-02", 16],
["2014-01-22", 16],
["2013-11-07", 13],
["2012-12-29", 13],
["2013-12-06", 13],
["2015-01-01", 12],
@hubertlepicki
hubertlepicki / index.js
Created December 13, 2014 12:06
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
def create
session[:user_account_params].stringify_keys!.merge!(params[:user_account]) if params[:user_account]
session[:user_account_params]["browser_locales"] = request.env['HTTP_ACCEPT_LANGUAGE']
@user_account = UserAccount.new(session[:user_account_params])
@user_account.current_step = session[:user_account_step]
if @user_account.valid?
if params[:back_button]
@user_account.previous_step
elsif @user_account.last_step?
class ApplicationController < ActionController::Base
...
def intranet
@intranet ||= Intranet.for_employee(current_user)
end
helper_method :intranet
end
@hubertlepicki
hubertlepicki / gist:9245365
Created February 27, 2014 06:25
convert number of seconds to hour:min:sec
def seconds_to_units(t)
mm, ss = t.divmod(60)
hh, mm = mm.divmod(60)
"#{hh}:#{mm}:#{ss}"
end
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 4.0"
gem "railties", "~> 4.0"
gem "tzinfo"
# Let's use thin
@hubertlepicki
hubertlepicki / Gemfile
Last active December 16, 2015 21:49
Capistrano + rvm + foreman + upstart deployment script
gem 'foreman', require: false
gem 'rvm-capistrano', require: false