Skip to content

Instantly share code, notes, and snippets.

@dachev
dachev / simple_crontab_reboot_example.js
Created January 3, 2011 03:02
Simple reboot example
require('crontab').load(cronLoaded);
function cronLoaded(err, tab) {
if (err) { console.log(err); process.exit(1); }
var command = '/usr/bin/env echo "starting some service..."';
tab.remove(tab.findCommand(command));
var item = tab.create(command);
item.everyReboot();
@dachev
dachev / forever_crontab_reboot_example.js
Created January 3, 2011 03:05
Reboot example with forever
crontab.load(function(err, tab) {
require('npm').load(function (err, npm) {
if (err) { console.log(err); process.exit(1); }
var path = require('path');
var util = require('util');
var uuid = '322ed3d0-6869-11e1-b86c-0800200c9a66';
var npmPrefix = npm.config.get('prefix');
var npmBinRoot = path.join(npmPrefix, 'bin');
var nodePath = process.execPath.split('/').slice(0, -1).join('/');
require('./module')
console.log(test);
@dachev
dachev / measurable.js
Created June 8, 2011 04:47
Is Measurable
// Actually, this is not going to work. Please ignore it.
function isMeasurable(target, array) {
if (array.length < 1) { return false; }
if (array.indexOf(target) >= 0) { return true; }
var weights = array.concat(target);
var length = 1 << weights.length;
for (var i = 0; i < length; i++) {
@dachev
dachev / solutions.js
Created June 8, 2011 04:58
Greplin Solutions
// one
function palindrome(text) {
var longest = '';
for (var i = 0; i < text.length; i++) {
var charOne = text.charAt(i);
for (var j = text.length-1; j > i; j--) {
var charTwo = text.charAt(j);
@dachev
dachev / gist:1272673
Created October 8, 2011 18:32
Increase logical volume size on 1and1 dedicated server
lvextend -L 400G /dev/mapper/vg00-home
xfs_growfs /home
@dachev
dachev / map_reduce.js
Created December 30, 2011 10:31
Find games with duplicate GameTeamStat records
var m = function() {
var key = this.stat_module_id + '_' + this.game_id + '_' + this.team_id;
emit(key, 1);
};
var r = function(k,vals) {
var sum = 0;
for (var i in vals) {
sum += vals[i];
}
@dachev
dachev / apns.js
Created February 13, 2012 06:52
Payload
/*
* Replace device token with your own
*/
// News
{"aps":
{"badge":1,
"alert":"Breaking News",
"sound":"default"
},
@dachev
dachev / search.rb
Created March 2, 2012 03:49
Search
class << ActiveRecord::Base
def each(chunk_size=100)
(0..self.last.id / chunk_size).each do |offset|
self.find(:all, :limit => chunk_size, :conditions => ['id > ?', offset * chunk_size]).each do |i|
yield i
end
end
end
end
"America/Adak",
"America/Anchorage",
"America/Anguilla",
"America/Antigua",
"America/Araguaina",
"America/Argentina/Buenos_Aires",
"America/Argentina/Catamarca",
"America/Argentina/Cordoba",
"America/Argentina/Jujuy",
"America/Argentina/La_Rioja",