Skip to content

Instantly share code, notes, and snippets.

@michiel
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
_.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 Aug 29, 2015
observers in coffeescript
View observers.coffee
_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) ->
View bleedcheck.sh
#!/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 Apr 25, 2014
bash for loop replace with sed in filenames with spaces
View replace.sh
#!/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
View Quick & Dirty ES in Rails.md

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
Import CACert root certs
View cacert.sh
#!/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
View nginx.conf
# 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 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');
}.property(),
isActive: function() {
View gist:013b5c54469e4707ea4f
#!/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 }}
}'
You can’t perform that action at this time.