Skip to content

Instantly share code, notes, and snippets.

@jasoares
jasoares / better_mongos.js
Last active December 18, 2017 02:16
MongoDB Shell mongos helpers and custom prompt
/**
* MongoDB Shell mongos helper functions and custom prompt
*
* https://gist.github.com/jasoares/3b21af33a7d62263010f
*/
sh.getBalancerSummary = function(since) {
// 24 hours by default
since = since || new Date(ISODate().getTime() - 1000 * 60 * 60 * 24);
print("Printing Summary since " + since);
@jasoares
jasoares / balancer_scripts.js
Last active May 15, 2017 17:26
MongoDB Shard distribution and balancer scripts
var hugeCollections = db.chunks.aggregate([{ '$group': { _id: { ns: '$ns', shard: '$shard' }, count: { '$sum': 1 } } }, { '$match': { count: { '$gt': 100 } } }, { '$group': { _id: { ns: '$_id.ns' }, count: { '$max': '$count' } } }, { '$project': { _id: 0, coll: '$_id.ns', shard: '$_id.shard', count: '$count' } }, { '$sort': { count: -1 } }]); while(hugeCollections.hasNext()) { var coll = hugeCollections.next()['coll']; sh.enableBalancing(coll); }
var allCollections = db.collections.find(); while(allCollections.hasNext()) { var coll = allCollections.next()['_id']; sh.disableBalancing(coll); }
var allCollections = db.collections.find(); while(allCollections.hasNext()) { var coll = allCollections.next()['_id']; if(db.getSiblingDB('config').collections.findOne({ _id: coll }).noBalance == false) { print(coll + ': ' + db.getSiblingDB('config').collections.findOne({ _id: coll }).noBalance); } }
db.chunks.aggregate([{ '$match': { _id: /db_name/ } }, { '$group': { _id: { ns: '$ns', shard: '$shard' }, count: { '$sum':
@miguelcma
miguelcma / DeviceUID.m
Created May 25, 2015 15:09
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m
@O-I
O-I / weighted_random_sampling.md
Last active April 24, 2025 04:53
[TIx 8] Weighted Random Sampling in Ruby

One of the many reasons I love working with Ruby is it has a rich vocabulary that allows you to accomplish your goals with a minimal amount of code. If there isn't a method that does exactly what you want, it's usually possible to build an elegant solution yourself.

Let's take the example of simulating the rolling of a die.

We can represent a die as an array of its faces.

die = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
@jasoares
jasoares / mongodcfg.conf
Last active August 29, 2015 14:17
mongodcfg.conf
systemLog:
destination: file
path: '/usr/local/var/log/mongodb/mongodcfg.log'
logAppend: true
storage:
dbPath: '/usr/local/var/mongodcfg'
journal:
enabled: true
processManagement:
fork: true
@jasoares
jasoares / mongos.conf
Last active August 29, 2015 14:17
mongos.conf
systemLog:
destination: file
path: '/usr/local/var/log/mongodb/mongos.log'
logAppend: true
processManagement:
fork: true
pidFilePath: '/var/run/mongodb/mongos.pid'
net:
bindIp:
- 127.0.0.1
@jasoares
jasoares / mongod0.conf
Last active February 24, 2022 21:54
MongoDB config file template
systemLog:
destination: file
path: '/usr/local/var/log/mongodb/mongod0.log'
logAppend: true
storage:
dbPath: '/usr/local/var/mongodb0'
directoryPerDB: true
journal:
enabled: true
engine: wiredTiger
@miguelcma
miguelcma / ios_is_debug.m
Last active August 29, 2015 14:13
iOS is_debug?
+ (BOOL)isDebugMode
{
if ([HKDevice isSimulator]) return YES;
static BOOL isDebugMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {
@lmmendes
lmmendes / fake_email_validator.rb
Created May 13, 2014 14:58
Fake / Temp e-mail validator
# encoding: utf-8
# Validates that the specified attributes are fake e-mail from temp domains
#
# class Person < ActiveRecord::Base
# validates :email, :fake_email => true
# end
#
# class Person < ActiveRecord::Base
# validates :email, :fake_email => { :exclude => ['bobmail.info'] }
@akdetrick
akdetrick / rvm-to-rbenv.md
Last active March 23, 2025 14:51
Guide to switching to rbenv bliss from RVM hell

RVM to rbenv

Why? @sstephenson explains it best here.


1) remove RVM from your system

This should get rid of the rvm dir and any installed rubies:

$ rvm implode