Skip to content

Instantly share code, notes, and snippets.

View jdelStrother's full-sized avatar
👋

Jonathan del Strother jdelStrother

👋
View GitHub Profile
function secondsToHoursMinutesSeconds(totalSec) {
totalSec = Math.round(totalSec)
var hours = Math.floor(totalSec / 3600) % 24
totalSec -= hours * 3600
var minutes = Math.floor(totalSec / 60) % 60
totalSec -= minutes * 60
return padToTwo(hours) + ':' + padToTwo(minutes) + ':' + padToTwo(totalSec)
}
// 3000 -> "50:00"
var Promise = require('bluebird')
var a = Promise.reject(new Error('load failed')).delay(100)
var b = Promise.resolve(123).delay(50)
var queue = [a,b]
function processQueue() {
var next = queue.shift()
if (next) {
return next.catch(processQueue)
} else {
@jdelStrother
jdelStrother / gist:0a80ba4b0c928d00eb2b
Created January 30, 2015 10:08
Gems lost while migrating to jruby
# Stuff with obvious replacements:
image_science, rmagick => mini_magick (not a drop-in replacement)
mysql2 => activerecord-jdbc-adapter, jdbc-mysql
unicorn => puma
# Stuff that we only use because they're optimized:
hiredis
yajl-ruby => json
int main(int argc, char * argv[])
{
DrawInfo* info = AcquireMagickMemory(sizeof(*info));
GetDrawInfo(NULL, info);
DestroyDrawInfo(info);
return 0;
}
$ gcc -I/ec/include/ImageMagick-6/ -L/ec/lib -lMagickCore-6.Q16 ./magick.c
$ UMEM_DEBUG=default,audit,verbose ./a.out
umem allocator: redzone violation: write past end of buffer
buffer=8103bc0 bufctl=8106a58 cache: umem_alloc_640
previous transaction on buffer 8103bc0:
thread=1 time=T-0.000636133 slab=8105f98 cache: umem_alloc_640
libumem.so.1'umem_cache_alloc_debug+0x1fe
libumem.so.1'umem_cache_alloc+0x18f
libumem.so.1'umem_alloc+0x50
libumem.so.1'malloc+0x36
DrawInfo* info = malloc(sizeof(*info));
GetDrawInfo(NULL, info);
DestroyDrawInfo(info);
@interface Person : NSObject
@property NSString* firstName, *lastName;
-(NSString*)fullName;
@end
@implementation Person
+ (NSSet *)keyPathsForValuesAffectingFullName {
return [NSSet setWithObjects:@"lastName", @"firstName", nil];
}
__block NSManagedObjectID objectID = nil;
[moc performBlockAndWait: ^{
NSManagedObject* object = findOrCreateSomethingSpecial(moc);
objectID = object.objectID;
}];
dispatch_async(dispatch_get_main_queue(), ^{
doSomethingWith(objectID);
});
Master:
[69165] 05 Mar 15:19:02.664 * DB saved on disk
[38026] 05 Mar 15:19:06.211 * Background saving terminated with success
[38026] 05 Mar 15:19:06.483 * Slave ask for synchronization
[38026] 05 Mar 15:19:06.483 * Starting BGSAVE for SYNC
[38026] 05 Mar 15:19:07.178 * Background saving started by pid 71219
[71219] 05 Mar 15:19:47.809 * DB saved on disk
[38026] 05 Mar 15:19:51.126 * Background saving terminated with success
[38026] 05 Mar 15:19:51.497 * Slave ask for synchronization
[38026] 05 Mar 15:19:51.497 * Starting BGSAVE for SYNC
# Redis configuration file example
#slaveof 10.12.86.71 6379
daemonize yes
pidfile /ec/var/redis/redis_6379.pid
timeout 300
loglevel notice
logfile /home/audioboo/logs/redis_6379.log