Skip to content

Instantly share code, notes, and snippets.

View benvds's full-sized avatar
😀

Ben van de Sande benvds

😀
View GitHub Profile
@benvds
benvds / test.rb
Last active December 10, 2015 15:18
Sequel dataset extension. For a reporting page query params can be given. These are used for the selects, joins, filters etc. I tried an approach where methods (like: apply_joins, apply_filters, etc.) passed the dataset around but this is cumbersome. Thinking you can also extend dataset it would prevent passing the dataset around. But now im hav…
module Stats
def select_metrics(metrics)
metrics.inject(self) do |ds, metric|
ds.select_metric(metric)
end
end
def select_metric(metric)
case metric
when 'total'
@benvds
benvds / deparam.js
Created October 22, 2012 09:51
Gets the params from the url and creates an object with the key/value pairs.
(function($) {
// Source: https://github.com/cowboy/jquery-bbq/blob/master/jquery.ba-bbq.js
//
// Section: Deparam (from string)
//
// Method: jQuery.deparam
//
// Deserialize a params string into an object, optionally coercing numbers,
// booleans, null and undefined values; this method is the counterpart to the
@benvds
benvds / bootstrap-datepicker-dutch.js
Created July 4, 2012 12:12
Configure Bootstrap DatePicker for Dutch
(function() {
/* Update date_input plugin so that DD-MM-YYYY format is used. */
$.extend($.fn.datepicker.defaults, {
parse: function (string) {
var matches;
if ((matches = string.match(/^(\d{2,2})\-(\d{2,2})\-(\d{4,4})$/))) {
return new Date(matches[3], matches[2] - 1, matches[1]);
} else {
return null;
}
@benvds
benvds / postgres-gem-install.sh
Created March 22, 2011 08:30
install postgres gem on os x 10.6
env ARCHFLAGS="-arch x86_64" gem install pg
→ rspec spec/models/profile_match_spec.rb
F*
Pending:
ProfileMatch.match matches all motives
# cant spec query chain
# ./spec/models/profile_match_spec.rb:46
Failures:
1) ProfileMatch.match matches against all companies
# football
sm_home_win:
name: "1"
pick_type_category: sm
position: 1
sm_away_win:
name: "2"
pick_type_category: sm
/**
* @brief Splits an address string containing a street, number and number addition
*
* @param $streetStr string An address string containing a street, number (optional) and number addition (optional)
*
* @return array Data array with the following keys: street, number and numberAddition.
*/
private function split_street($streetStr) {
$aMatch = array();
@benvds
benvds / gist:285849
Created January 25, 2010 13:03
array_trim - trims given array recursively from empty values
// trims given array recursively from empty values
function array_trim($array) {
foreach ($array as $key => $value):
if(is_array($value)) {
$array[$key] = array_trim($value);
if(!count($array[$key])) unset($array[$key]);
} else {
if (empty($value)) unset($array[$key]);
}
endforeach;
/* as described on: http://perishablepress.com/press/2009/12/06/new-clearfix-hack/ */
/* new clearfix */
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
@benvds
benvds / Controller test for default resource using Shoulda and Factory_Girl
Created August 26, 2009 07:41
Controller test for default resource using Shoulda and Factory_Girl
# posts_controller_test.rb
require 'test_helper'
class PostsControllerTest < ActionController::TestCase
context "on GET to :index" do
setup do
@first_post = Factory(:post, :title => "My first post")
@second_post = Factory(:post, :title => "My second post")
get :index