Skip to content

Instantly share code, notes, and snippets.

@michiel
michiel / sort-on-key.js
Created August 26, 2015 14:17
Sort array of objects on key
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;
}
// 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
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@michiel
michiel / isactive-component.js
Created June 5, 2014 07:02
bootstrap isActive link/li component
// Bootstrap3
App.ActiveLiComponent = Ember.Component.extend({
tagName : 'li',
classNameBindings : ['isActive:active:inactive'],
router: function() {
return this.container.lookup('router:main');
}.property(),
isActive: function() {
#!/bin/sh
host=localhost:9200
curl -X DELETE "${host}/test"
curl -X PUT "${host}/test" -d '{
"settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 }}
}'