This file contains 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
(function() { | |
/** | |
* Math utility. | |
* @static | |
* @constructor | |
*/ | |
tracking.Math = {}; | |
/** | |
* Euclidean distance between two points P(x0, y0) and P(x1, y1). | |
* @param {number} x0 Horizontal coordinate of P0. |
This file contains 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 | |
#... | |
# this method expects a class to be passed with the attributes @@per_page, | |
# @@:per_page_max defined | |
def prepare_pagination(paginable_class) | |
# STEP 1: Prepare values | |
# STEP 1a: Prepare page | |
# what the client wants or 1 per default | |
page = params[:page].nil?? | |
1 : params[:page].to_i |
This file contains 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
<?php | |
// Procedural | |
function example_new() { | |
return array( | |
'vars' => array() | |
); | |
} | |
function example_set($example, $name, $value) { | |
$example['vars'][$name] = $value; |
This file contains 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
<?php | |
// A library to implement queues in PHP via arrays | |
// The Initialize function creates a new queue: | |
function &queue_initialize() { | |
// In this case, just return a new array | |
$new = array(); | |
return $new; | |
} | |
// The destroy function will get rid of a queue | |
function queue_destroy(&$queue) { |
This file contains 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
# Regular Expression To Parse Ruby Log Messages | |
# parse ruby log message | |
# customize as needed | |
LOG_EXPRESSION = /([\w]+),\s+\[([^\]\s]+)\s+#([^\]]+)\]\s+(\w+)\s+--\s+(\w+)?:\s+(.+)/ | |
# sample log output from this call: | |
# logger.info("Ubiquitously") { "[dequeud] #{JSON.generate(params)}"} | |
string = 'I, [2010-08-15T16:16:46.142801 #81977] INFO -- Ubiquitously: {"title":"Google","url":"google.com","tags":"search, google, api","services":["meta_filter","mixx"],"description":"a search engine!"}' | |
string.gsub(LOG_EXPRESSION) do |match| |
This file contains 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 Lisp | |
Fs = { | |
:label => lambda {|name,value| Fs[name] = lambda { value } }, | |
:car => lambda {|sexp| sexp.first }, | |
:cdr => lambda {|sexp| sexp.slice(1, sexp.size) }, | |
:cons => lambda {|head,tail| [head] + tail }, | |
:atom => lambda {|sexp| !sexp.is_a?(Array) }, | |
:eq => lambda {|a,b| a == b }, | |
:if => lambda {|cnd,thn,els| cnd ? thn : els } | |
} |
This file contains 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 'uri' | |
myUri = URI.parse( 'http://www.mglenn.com/directory' ) | |
print myUri.host |