Skip to content

Instantly share code, notes, and snippets.

@redroot
redroot / gist:4473719
Created January 7, 2013 09:39
Weighted Mean - Ruby
# array of arrays
a = [[10, 1000], [9, 923], [8, 1230], [7, 10]] # [data,frequency]
mean = a.reduce(0) { |m,r| m += r[0] * r[1] } / a.reduce(0) { |m,r| m += r[1] }.to_f
@jschwertfeger
jschwertfeger / autocomplete_association.js
Created October 5, 2012 20:49
A jQuery autocomplete widget for forms where the underlying model references another model via ID
/*
* Unobtrusive autocomplete for model associations.
*
* For instance, assume you have a model `Task' and a model `User'. The task has
* an attribute user_id which associates the user who is assigned to the task.
* This widget allows you to build a form for tasks where the association is
* represented by a hidden user_id field that gets populated through an
* autocomplete text field.
*
* To use it you just have to include the tag attributes for the autocomplete
@johanmeiring
johanmeiring / gist:3002458
Created June 27, 2012 08:32
"git lg" alias for pretty git log
# From http://garmoncheg.blogspot.com/2012/06/pretty-git-log.html
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
@olistik
olistik / gist:2627011
Last active August 12, 2021 06:39
Ubuntu 12.10 setup (rbenv/RVM, Janus, PostgreSQL)

Ubuntu 12.10 setup (rbenv/RVM, Janus, PostgreSQL)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git curl
  • Copy/paste from the command line:
@comp615
comp615 / leaflet_numbered_markers.css
Created April 2, 2012 23:51
Numbered Markers in Leaflet (JS Mapping)
.leaflet-div-icon {
background: transparent;
border: none;
}
.leaflet-marker-icon .number{
position: relative;
top: -37px;
font-size: 12px;
width: 25px;