Skip to content

Instantly share code, notes, and snippets.

View mitchellporter's full-sized avatar

Mitchell Porter mitchellporter

  • Seattle, WA
View GitHub Profile
@mitchellporter
mitchellporter / bootstrap.js
Created October 8, 2016 22:20 — forked from Unitech/bootstrap
PM2 / Keymetrics for Heroku/Rackspace/Joyent/Amazon Elasticbeanstalk/Azure...
// Make sure you added pm2 as a dependency in your package.json
// Then in your Procfile, do a simple `node bootstrap.js`
var pm2 = require('pm2');
var MACHINE_NAME = 'hk1';
var PRIVATE_KEY = 'z1ormi9vomgq66';
var PUBLIC_KEY = 'oa0m7nuhdfibi16';
var instances = process.env.WEB_CONCURRENCY || -1; // Set by Heroku or -1 to scale to max cpu core -1
@mitchellporter
mitchellporter / after_res_hooks.js
Created October 10, 2016 01:02 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@mitchellporter
mitchellporter / genpass.swift
Created November 16, 2016 03:42 — forked from brennanMKE/genpass.swift
Generate a password with Swift
#!/usr/bin/env xcrun swift
import Foundation
public typealias CharactersArray = [Character]
public typealias CharactersHash = [CharactersGroup : CharactersArray]
public enum CharactersGroup {
case Letters
case Numbers
My thoughts on writing tiny reusable modules that each do just one
thing. These notes were adapted from an email I recently sent.
***
If some component is reusable enough to be a module then the
maintenance gains are really worth the overhead of making a new
project with separate tests and docs. Splitting out a reusable
component might take 5 or 10 minutes to set up all the package
overhead but it's much easier to test and document a piece that is
@mitchellporter
mitchellporter / contacts.js
Created January 7, 2017 19:30 — forked from benjamincharity/contacts.js
Create a downloadable file of VCARD formatted address for iOS from a JSON array.
var contacts =
[
{
"notes": [
{
"description": "Fugiat aute pariatur excepteur elit."
}
],
"tels": [
{
@mitchellporter
mitchellporter / makeAnimatedGif.m
Created January 9, 2017 22:23 — forked from mayoff/makeAnimatedGif.m
Example of creating an animated GIF on iOS, with no 3rd-party code required. This should also be easy to port to OS X.
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
static UIImage *frameImage(CGSize size, CGFloat radians) {
UIGraphicsBeginImageContextWithOptions(size, YES, 1); {
[[UIColor whiteColor] setFill];
UIRectFill(CGRectInfinite);
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
@mitchellporter
mitchellporter / CollectionViewDataSource.swift
Created January 30, 2017 18:17 — forked from andymatuschak/CollectionViewDataSource.swift
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@mitchellporter
mitchellporter / list.txt
Last active February 16, 2017 17:12
OOP / Design Patterns / Testing list
Books:
** Disclaimer: I've only read the first two. The second one is a little dry and I feel like most people might not like it,
but I enjoyed it **
** Was told by someone I respect that if he only had to choose one book it would be book #1 **
1. Design Patterns: Elements of Reusable Object-Oriented Software
https://www.amazon.com/dp/0201633612/
@mitchellporter
mitchellporter / server-part.js
Created March 12, 2017 03:09 — forked from nleush/server-part.js
Node.JS + MongoDB: automatic anonymous user creation
// This function implements anonymous creation logic.
function loadOrCreateAnonymousProfile(req, res, next) {
var sess = req.session,
auth = sess && sess.auth;
if (!auth || !auth.userId) {
dbCounter('anonymousUsers', function(err, counter) {
if (err) {
console.log('Error getting anonymous users counter', err);
next();
@mitchellporter
mitchellporter / Procfile
Created March 12, 2017 04:38 — forked from stephenlb/Procfile
Twitter / PubNub Bridge - Heroku Worker
tweetstream: node twitter-pubnub-stream.js