This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def seconds_to_units(t) | |
| mm, ss = t.divmod(60) | |
| hh, mm = mm.divmod(60) | |
| "#{hh}:#{mm}:#{ss}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| ... | |
| def intranet | |
| @intranet ||= Intranet.for_employee(current_user) | |
| end | |
| helper_method :intranet | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ["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], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module XPath | |
| module HTML | |
| def link(locator) | |
| locator = locator.to_s | |
| link = descendant(:a) #[attr(:href)] | |
| link[attr(:id).equals(locator) | string.n.is(locator) | attr(:title).is(locator) | descendant(:img)[attr(:alt).is(locator)]] | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-- | |
| # 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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 || {}; |
OlderNewer