Skip to content

Instantly share code, notes, and snippets.

michiel / sort-on-key.js
Created Aug 26, 2015
Sort array of objects on key
View sort-on-key.js
var key = 'name';
return objs.sort(function (a, b) {
if (a[key] > b[key]) {
return asc ? 1 : -1;
} else if (a[key] < b[key]) {
return asc ? -1 : 1;
} else {
return 0;
View underscoreAddon.js
// underscore addon with sum, mean, median and nrange function
// see details below
// Return sum of the elements
sum : function(obj, iterator, context) {
if (!iterator && _.isEmpty(obj)) return 0;
var result = 0;
if (!iterator && _.isArray(obj)){
michiel /
Last active Aug 29, 2015
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) ->
# check for vuln
# quick, dirty, grain of salt, etc
declare -a hosts=('' '')
for host in "${hosts[@]}";
echo "Testing $host ..."
michiel /
Created Apr 25, 2014
bash for loop replace with sed in filenames with spaces
# bash for loop replace with sed in filenames with spaces
IFS=$(echo -en "\n\b")
for file in `find . | grep "md$"`; do
sed -i 's/X/Y"/g' "$file"
View Quick & Dirty ES in

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 /
Created May 21, 2014
Import CACert root certs
sudo apt-get install libnss3-tools
cd /tmp
wget -O cacert-root.crt ""
wget -O cacert-class3.crt ""
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "" -i cacert-root.crt
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n " Class 3" -i cacert-class3.crt
View nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
michiel / isactive-component.js
Created Jun 5, 2014
bootstrap isActive link/li component
View isactive-component.js
// Bootstrap3
App.ActiveLiComponent = Ember.Component.extend({
tagName : 'li',
classNameBindings : ['isActive:active:inactive'],
router: function() {
return this.container.lookup('router:main');
isActive: function() {
View gist:013b5c54469e4707ea4f
curl -X DELETE "${host}/test"
curl -X PUT "${host}/test" -d '{
"settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 }}