Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / glt.zsh
Last active December 17, 2015 10:18
Get latest named tag in your local git repo
alias glt="git describe --tags | sed -n 's/^v\([0-9]*.[0-9]*.[0-9]*\)/\1/p'"
@jameswomack
jameswomack / CFBundleShortVersionString_versioning.sh
Created May 16, 2013 17:59
Use the latest versioned tag in your Xcode project repo to set the CFBundleShortVersionString on release builds
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
appVersion=$(cd $PROJECT_DIR && git describe --tags | sed -n 's/^v\([0-9]*.[0-9]*.[0-9]*\)/\1/p')
buildNumber=$appVersion
echo $buildNumber
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
@jameswomack
jameswomack / NSUserDefaultsStub.mm
Created May 16, 2013 19:18
Stubbing NSUserDefaults using NSMutableDictionary, using Kiwi for iOS.
describe(@"appVersion", ^{
beforeAll(^{
NSMutableDictionary *testDefaults = @{}.mutableCopy;
[NSUserDefaults stub:@selector(standardUserDefaults) andReturn:testDefaults];
});
it(@"should return what ABApplicationVersionKey is set to", ^{
[NSUserDefaults.standardUserDefaults setObject:FOO forKey:ABApplicationVersionKey];
[[ABConfiguration.appVersion should] equal:FOO];
});
@jameswomack
jameswomack / gist:5602102
Created May 17, 2013 21:29
Four-char UInt32 type codes to NSString and back
NSString *ABTypeCodeToString(UInt32 typeCode)
{
char string[5] = {*(((char*)&typeCode)+3), *(((char*)&typeCode)+2), *(((char*)&typeCode)+1), *(((char*)&typeCode)+0),0};
NSString *codeWithDot = @(string);
return [codeWithDot stringByTrimmingCharactersInSet:NSCharacterSet.punctuationCharacterSet];
}
UInt32 ABStringToTypeCode(NSString *typeString)
{
@jameswomack
jameswomack / equalizing_image_widths_column_height_constraint.js
Last active December 22, 2015 04:29
A theoretical first hack at equalizing the width of three images within a column, while maintaining a set column height.
function Image(width, height) {
this.width = width;
this.height = height;
}
function createImageTriplet() {
var imageTriplet = [];
imageTriplet.push(new Image(1000, 500));
imageTriplet.push(new Image(600, 800));
@jameswomack
jameswomack / Application.java
Created November 13, 2013 19:13
Piping JSON requests into an HTML template as JavaScript. Far less code than loading a JSON file.
package controllers;
import play.mvc.Result;
import play.libs.F.Function;
import play.libs.WS;
import play.mvc.*;
public class Application extends Controller {
public static Result index() {
global.Frei = {} if typeof global.Frei is 'undefined'
Frei = global.Frei
path = require 'path'
express = require 'express'
assets = require 'connect-assets'
sugar = require 'sugar'
request = require 'request'
fs = require 'fs'
passport = require('passport')
var CookieJar, Frei, LocalStrategy, Mack, RedisStore, Routes, UserController, app, asset_helper, assets, ensureAuthenticated, express, expressUglify, fs, mack, passport, path, request, sugar, __assets, __lib, __public, __uploads,
_this = this;
if (typeof global.Frei === 'undefined') {
global.Frei = {};
}
Frei = global.Frei;
path = require('path');
@jameswomack
jameswomack / npm_publish.sh
Created January 13, 2014 21:52
If you receive `npm ERR! publish Failed PUT response undefined` when publishing an NPM package. Through some combination of a failed `npm adduser` and a malfunctioning publish module (https://npmjs.org/package/npm-release), my npmrc became corrupted.
rm ~/.npmrc
npm adduser
# follow prompts...
npm publish --verbose
@jameswomack
jameswomack / proxy_switch.sh
Last active September 4, 2018 20:59
Bash/ZSH for changing git/npm/global proxy info based on current Wifi SSID on Mac
alias airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
CURRENT_WIFI_SSID=$(eval airport -I | grep '^[[:space:]]*SSID' | sed -e 's/^.*SSID: //g')
proxy() {
export addy='http://www-west.sony.com:80'
git config --global http.proxy $addy
git config --global https.proxy $addy
npm config set http-proxy $addy
npm config set https-proxy $addy