Skip to content

Instantly share code, notes, and snippets.

@miguelcma
miguelcma / 0_reuse_code.js
Created December 18, 2015 19:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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
A Mongoid::Criteria instance should not respond_to :reject! or any other in place changing iterators
it should also be forced to run after calling #inspect mimicking an ActiveRecord::Relation
@miguelcma
miguelcma / mongod.yml
Created March 17, 2015 17:27
MongoDB 3.0 Config skeleton YAML
systemLog:
destination: file
path: '/usr/local/var/log/mongodb/mongod1.log'
logAppend: true
storage:
dbPath: '/usr/local/var/mongodb1'
directoryPerDB: true
journal:
enabled: true
engine: wiredTiger
@miguelcma
miguelcma / redis_pipelined_multi.rb
Last active August 29, 2015 14:15
redis: pipelined (multi) atomic get and del
r.pipelined do
keys.each do |k|
r.multi do
values << r.get(k)
r.del(k)
end
end
end
@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) {
@miguelcma
miguelcma / monit.cron
Last active August 29, 2015 14:11
Manual monit using a crontab
* * * * * /bin/ps aux | grep [q]ueue_manager:start || (cd /var/www/lqd.io/current ; RAILS_ENV=staging /home/deployer/.rvm/gems/ruby-2.1.1@global/bin/bundle exec rake queue_manager:start &)
@miguelcma
miguelcma / gist:c9a4043daa5a3f73d363
Created July 10, 2014 11:57
MongoDB primary node duplicate key errors
2014-07-10T11:55:23.225+0000 [slaveTracking] processing update : query: { _id: ObjectId('53445ccb8e0ae053848b25c6'), config: { _id: 1, host: "10.0.0.11:27017", priority: 0.4 }, ns: "local.oplog.rs" } updated: { $set: { syncedTo: Timestamp 1404993323000|4 } } god: 0 upsert: 1 multi: 0 callLogOp: 1 fromMigration: 0 fromReplications: 0
2014-07-10T11:55:23.225+0000 [slaveTracking] Relevant index 0 is kp: { _id: 1 } io: { v: 1, name: "_id_", key: { _id: 1 }, ns: "local.slaves" }
2014-07-10T11:55:23.225+0000 [slaveTracking] Only one plan is available; it will be run but will not be cached. query: { _id: ObjectId('53445ccb8e0ae053848b25c6'), config: { _id: 1, host: "10.0.0.11:27017", priority: 0.4 }, ns: "local.oplog.rs" } sort: {} projection: {}, planSummary: IXSCAN { _id: 1 }
2014-07-10T11:55:23.225+0000 [slaveTracking] update validate options -- updatedFields: Fields:[ ] immutableAndSingleValueFields.size:0 fromRepl: 0 validate:1
2014-07-10T11:55:23.225+0000 [slaveTracking] update validate options -- updatedFi
@miguelcma
miguelcma / serial_killer.sh
Last active August 29, 2015 14:01
Serial killer a.k.a. "killall"
kill $(ps aux | grep [m]ongod | awk '{ print $2 }')
<?php
if (in_array($name, array_keys($this->calls))) {
if ($this->$name($data)) {
return $this->dialIn($name, $data);
}
} else {
return "Non-existent call";
}