Skip to content

Instantly share code, notes, and snippets.

View ierceg's full-sized avatar

Ivan Erceg ierceg

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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) {

Keybase proof

I hereby claim:

  • I am ierceg on github.
  • I am ierceg (https://keybase.io/ierceg) on keybase.
  • I have a public key whose fingerprint is C9B1 7A0F 4DAB F632 DE37 FC67 D13E 8FC6 ACE6 74FC

To claim this, I am signing this object:

@ierceg
ierceg / supergit
Created September 23, 2015 17:41 — forked from spiderr/supergit
#!/bin/bash
# Shell Script for super-respositores that executes git on all sub-repositories
# Homepage at http://www.bitweaver.org/wiki/supergit
# Licensed under the GPL
# Authors: github.com/spiderr
function usage {
appName=`basename $0`
echo "Welcome to $appName. It acts on all directories in your project as if they were sub-respositories. For most commands, you simply type what you would normally for git, however you simply type $appName with desired parameters in the super-repository root of your project. For example:"
echo "-- To clone, type '$appName git@github.com:bitweaver/bitweaver.git -b DEV testbw' which will clone, then intiliaze + update submodules and checkout the master branch for each submodule"
@ierceg
ierceg / dump.js
Last active March 25, 2016 05:23
Dump installed, referenced and dev referenced npm packages
// Run this script from a directory above the packages you are analyzing
/* global process */
'use strict';
var _ = require('lodash');
var glob = require('glob');
var path = require('path');
@ierceg
ierceg / export_envvars.sh
Created July 11, 2016 03:53
Export envvars from docker-like envvar file
#!/bin/bash
# As seen here https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
if [[ $0 == $BASH_SOURCE ]]; then
echo 'You must run this script as `source export_envvars.sh` for it to export the envvars.'
else
if [[ -z $1 ]]; then
echo 'You must provide name of the envvars file.'
else
# As seen here http://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable