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
/* Utilities to benchmark code. Look at Benchmark.pbench */ | |
function Benchmark() { | |
} | |
// Install a global 'pbench' function for convenience | |
Benchmark.convenience = function convenience() { | |
window.pbench = Benchmark.pbench | |
} | |
/* |
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
# app/controllers/application_controller.rb | |
class ApplicationController | |
before_filter :setup_ews_client | |
private | |
def setup_ews_client | |
Thread.current[:ews_client] = proc { ews } | |
end | |
def ews | |
@ews ||= Ews.client(session.slice(:username, :password, :email).merge(endpoint: ews_endpoint)) |
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 Array | |
def remove(items_to_delete) | |
lut = Hash.new(0) | |
items_to_delete.each do |e| lut[e] += 1 end | |
result = [] | |
each do |e| | |
if lut[e] > 0 | |
lut[e] -= 1 | |
else | |
result << e |
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 Kernel | |
# Prints memory and cpu footprint of the server (uses ps in a subshell, | |
# portability is therefore limited) | |
def print_resource_usage | |
ps_out = `ps -o vsz,rss,%cpu,%mem -p #{$$}` | |
vsz, rss, cpu, pmem = ps_out.scan(/\d+(?:[.,]\d+)?/).map { |e| e.gsub(/,/,'.').to_f } # ps on 10.5.1 outputs ',' instead of '.' for MEM% | |
virtual, real = (vsz-rss).div(1024), rss.div(1024) | |
$stdout.printf "%dMB real, %dMB virtual, %.1f%% CPU, %.1f%% MEM\n", real, virtual, cpu, pmem | |
end | |
module_function :print_resource_usage |
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
require 'ostruct' | |
module Normalizer | |
extend self | |
def trim(str) | |
str.strip | |
end | |
end | |
obj = OpenStruct.new |
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
Moved to https://github.com/apeiros/available |
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
Moved to https://github.com/apeiros/available |
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 InheritableAttributes | |
def self.extended(klass) | |
klass.instance_variable_set(:@inheritable_attributes, []) | |
end | |
attr_reader :inheritable_attributes | |
def inheritable_attribute(*args) | |
@inheritable_attributes.concat(args) | |
singleton_class.send :attr_accessor, *args unless args.empty? |
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 Remplate < AbstractController::Base | |
include AbstractController::Rendering | |
include AbstractController::Layouts | |
include AbstractController::Helpers | |
include AbstractController::Translation | |
include AbstractController::AssetPaths | |
include Rails.application.routes.url_helpers | |
self.view_paths = "app/views" # TODO: get it from Rails.application if available |
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 Enumerable | |
unless method_defined?(:last) then | |
def last(n=nil) | |
reverse_each_method = method(:reverse_each) | |
has_reverse_each = reverse_each_method && reverse_each_method.owner != Enumerable # native reverse_each needed | |
if n then | |
return_value = [] | |
if has_reverse_each then | |
reverse_each { |val| | |
return_value.unshift(val) |