Skip to content

Instantly share code, notes, and snippets.

View ierceg's full-sized avatar

Ivan Erceg ierceg

View GitHub Profile
@ierceg
ierceg / cleanDb.js
Last active August 29, 2015 14:09
Clean-up non-design-docs from a CouchDb at the beginning of each test
var db = require('nano');
var debug = require('debug')('cleanDb');
var async = require('async');
function cleanDb(callback) {
debug('Cleaning up db from all non-design documents');
db.list(function(err, body) {
if(err) {
@ierceg
ierceg / MutableDeepCopy.md
Last active August 29, 2015 14:08
Implementation of deep mutable copy categories for `NSDictionary` and `NSArray`

Based on this gist

For NSDictionary:

@implementation NSDictionary (MutableDeepCopy)

//  As seen here (in the comments): https://gist.github.com/yfujiki/1664847
- (NSMutableDictionary *)mutableDeepCopy

{

@ierceg
ierceg / UIView+LayerEdgeAntialiasing
Created July 30, 2014 04:42
UIView category which spreads antialiasing to layers
// Originally found at http://pastebin.com/kdUHWMZf
// Fixed the recursion not working on layers of subviews.
@interface UIView (LayerEdgeAntialiasing)
/** Uses the -setAllowsEdgeAntialiasing: method from CALayer prior to iOS 7, and also can applies it to every sublayers (and sublayers's of sublayers', and so on) if you want to. */
@property (nonatomic, assign) BOOL allowsLayerEdgeAntialiasing;
- (void)setAllowsLayerEdgeAntialiasing:(BOOL)allowsLayerEdgeAntialiasing applyToSublayers:(BOOL)applyToSublayers;
@end
@ierceg
ierceg / nockHelper.coffee
Last active August 29, 2015 14:01
pgte/nock automated recording/replaying
RESOURCES_TESTS_PATH = '<whatever works for you>'
pathToTestJson = (filename) ->
return path.join __dirname, RESOURCES_TESTS_PATH, filename
nockActionIsRecording = () ->
return not _.isUndefined process.env.NOCK_RECORDING and process.env.NOCK_RECORDING == '1'
# If we are recording (NOCK_ACTION == 'recording') then we start the recording and return the filename
# to which we will be saving them.
@ierceg
ierceg / connect-virtual-middleware
Created January 10, 2014 11:46
Virtual route, resource and subdomain middleware for Connect, based on connect.vhost. I'll make it a real (documented, commented, tested) module when I get some time. I use it on Heroku to have several express instances all connected together on a single dyno. It allows me to modularize the system but using just one dyno and not web + workers du…
// All these functions are literally based on connect.vhost which borders on unintelligible. I'll fix that when converting to module.
exports.vroute = function(route, server) {
if (!route) throw new Error('vroute route required');
if (!server) throw new Error('vroute server required');
var regexpString = '^\\/' + cleanForRegexp(route) + '(\\/.*)$';
var regexp = new RegExp(regexpString, 'i');
return function(req, res, next) {
if(!req || !req.url) return next();
var matches = req.url.match(regexp);
@ierceg
ierceg / APNS-in-webscript.lua
Created December 26, 2013 16:00
An example script for webscript.io platform that works with their persistent storage It's an an unfinished script that was meant as an implementation of a very simple push notification service with backend in Apple Push Notification Service (APNS). I didn't finish it as webscript.io promises unlimited storage but it's actually severely limited a…
-- Finds the index of the device token or -1 if the token doesn't exist in the devices.
function findDeviceIndexForToken(devices, deviceToken)
for i,v in ipairs(devices) do
if v.token == deviceToken then
return i
end
end
return -1