Skip to content

Instantly share code, notes, and snippets.

@michiel
michiel / observers.coffee
Last active August 29, 2015 13:58
observers in coffeescript
_watch = (prop, fn) ->
subs[prop] = [] unless subs[prop]
subs[prop].push fn
_notify = (prop, val) ->
if subs[prop]
subs[prop].forEach (cb) ->
cb val
_compare = (a, b) ->
// underscore addon with sum, mean, median and nrange function
// see details below
_.mixin({
// Return sum of the elements
sum : function(obj, iterator, context) {
if (!iterator && _.isEmpty(obj)) return 0;
var result = 0;
if (!iterator && _.isArray(obj)){
// The API accepts the page parameter and returns the pagination info in meta
{
"messages": [ ... ],
"meta": {
"pagination": {
"total_pages": 3,
"current_page": 1,
"total_count": 55
}
# Public: A module to be mixed in another class with common methods to index
# records in ElasticSearch.
#
# The host object needs to respond to 'indexed_attributes', which will return
# an array of the attributes names to be indexed.
#
# It's also recommended to override the 'save?' method to make sure only
# records that match some specifications are indexed.
#
# The type used for the ElasticSearch index will be extracted from the name of
@michiel
michiel / lat_lng_jitter.js
Last active March 7, 2023 16:51
Add jitter to latitude/longitude
//
// Make a few assumptions and add noise to latitude/longitude position
// Ex, console.log(jitter(-26.4853429150483, -49.072945734375, 5));
//
var rad_Earth = 6378.16;
var one_degree = (2 * Math.PI * rad_Earth) / 360;
var one_km = 1 / one_degree;
function randomInRange(from, to, fixed) {
.ring {
width: 300px;
height: 300px;
border-radius: 50%;
position: absolute;
background-color: transparent;
border: 15px gray solid;
-webkit-animation-name: ani;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease;
@michiel
michiel / pulse.css
Created November 14, 2013 15:05
CSS3 pulsating rings
.outer-ring {
border: 3px solid #999;
-webkit-border-radius: 30px;
height: 22px;
width: 22px;
position: absolute;
left:20px;
top:214px;
-webkit-animation: pulsate 1s ease-out;
-webkit-animation-iteration-count: infinite;
@michiel
michiel / test_mechanize.rb
Last active December 26, 2015 12:28
Testing Mechanize apps
require 'rubygems'
require 'mechanize'
require 'test/unit'
require 'fakeweb'
def find_links
Mechanize.new.get('http://www.google.com').links
end
class TestGoogle < Test::Unit::TestCase
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# you need an updated simple_form gem for this to work, I'm referring to the git repo in my Gemfile
config.input_class = "form-control"
config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.use :input