Skip to content

Instantly share code, notes, and snippets.

@johnrees
johnrees / hstore_accessor.rb
Created June 14, 2012 23:10 — forked from inopinatus/hstore_accessor.rb
hstore accessor class method for AR
# include from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
@johnrees
johnrees / image-link.scss
Created July 2, 2012 10:26
image-link (text-indent -9999px replacement) SASS mixin
@johnrees
johnrees / xhr_reload_hack.rb
Created July 19, 2012 17:47
Chrome/Webkit Ajax Back Button Fix
<% if request.xhr? %>
<script>
if (!document.getElementsByTagName("body")[0]){ location.reload(true); }
</script>
<% end %>
@johnrees
johnrees / xhr_reload_hack.html.erb
Created July 19, 2012 17:49
Chrome/Webkit Ajax Back Button Fix
<!-- put this inside your view that is not using a layout -->
<% if request.xhr? %>
<script>
if (!document.getElementsByTagName("body")[0]){ location.reload(true); }
</script>
<% end %>
@johnrees
johnrees / es.sh
Created September 15, 2012 00:30
Install ElasticSearch on Ubuntu 12.04
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.9.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@johnrees
johnrees / redis.erb
Created October 2, 2012 12:37
Monit template files
check process redis
start program = "/usr/bin/redis-server /etc/redis/redis.conf"
stop program = "/usr/bin/redis-cli -p 6379 shutdown"
with pidfile /var/run/redis.pid
@johnrees
johnrees / shuffle.as
Created November 28, 2012 10:55
Array Shuffle (AS3)
function shuffle(array:Array):Array {
var newArray:Array = new Array();
while(array.length > 0){
var obj:Array = array.splice(Math.floor(Math.random()*array.length), 1);
newArray.push(obj[0]);
}
return newArray;
}
@johnrees
johnrees / reserved_words.txt
Created December 5, 2012 09:29
Reserved username list (blacklist)
400
403
404
418
422
500
502
about
acces
account
@johnrees
johnrees / commands.sh
Created December 13, 2012 14:14
setting up minivps
# remove apache
sudo apt-get remove --purge $(dpkg -l apache* | grep ii | awk '{print $2}')
sudo apt-get autoremove
sudo apt-get remove apache2*
@johnrees
johnrees / gist:6160131
Created August 5, 2013 22:23
Delete all merged branches for current branch in git
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d