Skip to content

Instantly share code, notes, and snippets.

View jamestyj's full-sized avatar

James Tan jamestyj

  • Confluent
  • Singapore
View GitHub Profile
function makeEmail() {
var strValues="abcdefghijklmnopqrstuvwxyz";
var strEmail = "";
var strTmp;
for (var i=0;i<10;i++) {
strTmp = strValues.charAt(Math.round(strValues.length*Math.random()));
strEmail = strEmail + strTmp;
}
strTmp = "";
strEmail = strEmail + "@";
@jamestyj
jamestyj / batchRemove.js
Created March 28, 2014 19:55
Remove documents in batches
// Note: Ensure there's an existing index, e.g.:
// db.assets.ensureIndex({ assetExpiration: 1 })
// Since remove() doesn't support limit(), we can't do the following directly:
// db.assets.remove({ assetExpiration: { $lt: newDate() } }).limit(batchSize)
// So we do the following instead:
batchSize = 100
removeMe = []
@jamestyj
jamestyj / usePowerOf2Sizes.java
Created March 28, 2014 18:59
Enable usePowerOf2Sizes on a collection with Java
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.MongoClient;
import java.net.UnknownHostException;
public class powerOf2Sizes {
public static void main(String[] args) throws UnknownHostException {
MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB("myDB");
@jamestyj
jamestyj / rails_check.sh
Created September 27, 2011 20:35
Simple script that ensures Rails processes stay within specific memory limit.
#!/bin/bash
#
# This script is triggered by crontab every 5 minutes.
# Logs to /var/log/ui-server/<host>-rails_check.log.
log_dir=/var/log/my_rails_app
mkdir -p $log_dir
log_file=$log_dir/$(hostname)-rails_check.log
# Limits in MB