Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
joeyAghion / mongodb_collection_sizes.js
Last active May 23, 2024 15:30
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
function loop(init, fnCondition, fnUpdate, fnRun, fnDone){
var index = 0;
index = (init.constructor.name === "function")?init():init;
function next(){
index = fnUpdate(index);
if(fnCondition(index)){
setTimeout(function(){
fnRun(index, next);
}, 0);
}else{
@nel
nel / gist:1186564
Created September 1, 2011 16:23
Memcache Store with controlled expiration
module ActiveSupport
module Cache
class AtomicMemCacheStore < MemCacheStore
ALREADY_STORED = "STORED\r\n"
cattr_accessor :grace_period
@@grace_period = 3.minutes
def read(key, options = nil)
result = super
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active May 16, 2024 16:51
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@andresgutgon
andresgutgon / Selector de Idioma con Rails 2.3.8
Created August 18, 2010 18:31
Desplegar los idiomas que estan disponibles en tu App y setear el valor para cada usuario
#Selector de idioma
#dependencias:
# 1 - Rack locale del paquete Rack-contrib [1]
# USO: Se usa para detectar el idioma definido por el usuario en su browser ['HTTP_ACCEPT_LANGUAGE']
# Esplicado aquí http://guides.rubyonrails.org/i18n.html#using-accept-language
# [1] http://github.com/rack/rack-contrib
# 2 - Routing-filter [1]
# USO: Establecer el locale en las URLs ej.: www.mysite.com/es/foo/bar
# NOTA: Si tambien quieres traducir las URL's usa la gema de Raul Murciano Translate_routes [2] (De momento sin cobertura para Rails3)