Skip to content

Instantly share code, notes, and snippets.

View hubertlepicki's full-sized avatar

Hubert Łępicki hubertlepicki

View GitHub Profile
@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
class ApplicationController < ActionController::Base
...
def intranet
@intranet ||= Intranet.for_employee(current_user)
end
helper_method :intranet
end
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?
@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")
@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 / click_link_patch.rb
Created March 26, 2015 22:03
Allow Capybara to click on links without href
@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
#--
# Copyright (c) 2009 Hubert Lepicki <hubert.lepicki@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
lat, lng = [53, 21]
conditions = { :page => 1, :per_page => 20 }
map = "function() { emit(this._id, {lat: this.lat, lng: this.lng}); }"
reduce = <<BEGIN
function(key, values) {
distance = 0;
values.forEach(function(doc) {
distance = (doc.lat - #{lat})*(doc.lat - #{lat}) + (doc.lng - #{lng})*(doc.lng - #{lng});
});
return distance;
/* Client side pagination with jQuery by Hubert Łępicki / AmberBit
License: MIT
Usage:
- HTML:
<div class='paginated' per-page='4'><div class='i'>Item 1</div><div class='i'>Item 2</div>....<div class='i'>Item 100</div></div>
- JS:
$('.paginated').clientSidePagination();
*/
$.fn["clientSidePagination"] = function(options) {
options = options || {};