Skip to content

Instantly share code, notes, and snippets.

View brennanMKE's full-sized avatar

Brennan Stehling brennanMKE

View GitHub Profile
@brennanMKE
brennanMKE / NSString+Collate.h
Last active January 3, 2016 15:49
A string problem for collating 2 strings together. Strings "abcdef" and "123456" become "a1b2c3d4e5f6."
@interface NSString (Collate)
- (NSString *)collateWithOtherString:(NSString *)otherString;
@end
@brennanMKE
brennanMKE / backup.sh
Last active August 29, 2015 13:56
Backup to thumbdrive on a Mac which ignores folders which do not need a backup like Dropbox and GitHub
#!/bin/sh
# set the strict mode
set -e
if [ -d "/Volumes/Thumbdrive" ]; then
if [ ! -d "/Volumes/Thumbdrive/Backups" ]; then
mkdir "/Volumes/Thumbdrive/Backups"
fi
@brennanMKE
brennanMKE / Vagrantfile
Last active August 29, 2015 13:56
Vagrant Setup
# encoding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64.box"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# config.vm.box = "opscode-ubuntu-12.04_chef-11.4.0"
@brennanMKE
brennanMKE / server.sh
Created February 24, 2014 07:28
Node Server Script
#!/bin/sh
# Based On: https://github.com/chovy/node-startup/blob/master/init.d/node-app
# strict
set -e
NODE_ENV="development"
NODE_APP='app.js'
APP_DIR='.';
@brennanMKE
brennanMKE / login.sql
Last active February 28, 2016 03:22
Securing User Data with Postgres
-- See Magnus Hagander: Secure Your Web Webapp passwords in PostgreSQL
-- YouTube: http://youtu.be/MuLMIQBB4Ew
-- Below the SECURITY DEFINER directive makes the query run as the user which
-- created the stored procedure which is the only user which has access to the
-- user table. The app which uses this database would connect with a user which
-- does not have access to this table, preventing queries from pulling all of
-- the data in the table.
CREATE OR REPLACE FUNCTION login(_userid text,
@brennanMKE
brennanMKE / immediate.js
Last active August 29, 2015 13:56
JavaScript Promise with immediate response
var Promise = require('promise');
// Always return a promise for immediate or delayed responses
var doAsync = function(nbr) {
if (nbr === 1) {
// use static function to resolve with data immediately
return Promise.resolve('Success already!');
}
else if (nbr === 2) {
// use static function to reject with an error immediately
@brennanMKE
brennanMKE / chaining.js
Last active August 29, 2015 13:56
Chaining promises with just a single error handler
var Promise = require('promise');
var limit = 3;
var doAsync = function(nbr) {
var promise = new Promise(function (resolve, reject) {
setTimeout(function() {
if (nbr <= limit) {
// increment the given value by 1
resolve(nbr+1);
@brennanMKE
brennanMKE / package.json
Created March 2, 2014 19:04
Promise Package
{
"name": "promise-sample",
"description": "Promise Sample",
"version": "0.0.1",
"private": true,
"dependencies": {
"promise": "~4.0.0"
}
}
@brennanMKE
brennanMKE / textHeight.m
Created March 5, 2014 17:48
Text Height in Objective-C for NSString and NSAttributedString
- (CGFloat)heightForAttributedString:(NSAttributedString *)text maxWidth:(CGFloat)maxWidth {
if ([text isKindOfClass:[NSString class]] && !text.length) {
// no text means no height
return 0;
}
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
CGSize size = [text boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:options context:nil].size;
@brennanMKE
brennanMKE / CircleButton.podspec
Created March 14, 2014 16:50
CircleButton.podspec
Pod::Spec.new do |s|
s.name = "CircleButton"
s.version = "0.0.2"
s.summary = "Easy way to create buttons masked in a circle with colored border without the anti-aliasing distortion"
s.description = <<-DESC
When setting the corner radius, border color and border width there is often bleeding through to the
edges as is seen with the screenshot from the StackOverflow question below. This approach eliminates
the bleeding by embedding the masked view without a superview which can also be made circular.
DESC
s.homepage = "http://www.smallsharptools.com/"