Skip to content

Instantly share code, notes, and snippets.

.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 / 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) {
# 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
// 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
}
// 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)){
@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) ->
#!/bin/bash
# check for heartbleed.com vuln
# quick, dirty, grain of salt, etc
declare -a hosts=('api.example.com' 'www.google.com')
for host in "${hosts[@]}";
do
echo "Testing $host ..."
@michiel
michiel / replace.sh
Created April 25, 2014 14:00
bash for loop replace with sed in filenames with spaces
#!/bin/bash
# bash for loop replace with sed in filenames with spaces
STORED_IFS=$IFS
IFS=$(echo -en "\n\b")
for file in `find . | grep "md$"`; do
sed -i 's/X/Y"/g' "$file"
done

Quick and Dirty Integration of elasticsearch api with rails

Take the following with a grain of salt ...

We started prototyping with ES & Rails about 2 days ago and I quickly discovered that things became a bit unwieldy the more I utilized elasticsearch. For now I am running with this type of integration with rails 3.2.15 to assess elasticsearch.

While we have done preliminary reviews on how to set up a production environment (still scratching my head on how to handle the split brain bug) , there's certainly plenty of what I'm not aware of, so if you see a fault in this approach, please let me know.

I may update this later on with a couple of convenience methods on the data models ...

@michiel
michiel / cacert.sh
Created May 21, 2014 10:15
Import CACert root certs
#!/bin/bash
sudo apt-get install libnss3-tools
cd /tmp
wget -O cacert-root.crt "http://www.cacert.org/certs/root.crt"
wget -O cacert-class3.crt "http://www.cacert.org/certs/class3.crt"
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "CAcert.org" -i cacert-root.crt
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "CAcert.org Class 3" -i cacert-class3.crt