Skip to content

Instantly share code, notes, and snippets.

@jakecraige
jakecraige / SwiftMethodRetainCycle.swift
Created July 13, 2016 21:11
Swift retrain cycle passing method to closure argument. Throw this in a playground to play around with it.
class Controller {
var changed: (() -> Void)?
init() {
print("Allocate 'Controller'")
}
deinit {
print("Deallocate 'Controller'")
}
@jakecraige
jakecraige / typealias.swift
Last active November 25, 2015 04:59
Inferred typealias defined in protocol by implementing a function
protocol Action {
typealias StateType
func reduce(state: StateType) -> StateType
}
struct MyState { }
struct MyAction: Action {
// Note: We don't have to define the StateType alias, it infers it.
func reduce(state: MyState) -> MyState {
@jakecraige
jakecraige / sort.c
Last active October 26, 2015 23:19
A sorting algorithm
void sort(int values[], int n)
{
for (int i = 0; i < n - 1; i++)
{
int j = i + 1;
while (values[i] > values[j])
{
int temp = values[j];
values[j] = values[i];
values[i] = temp;
@jakecraige
jakecraige / circle.yml
Last active November 16, 2015 15:53
QT5 on CircleCI
machine:
post:
- ./$CIRCLE_PROJECT_REPONAME/bin/ci/install_qt5.sh
@jakecraige
jakecraige / migration_from_id_to_uuid.rb
Created August 7, 2015 22:46
Example migration migrating from integer IDs as a primary key to uuid IDs while maintaining existing associations.
class ChangeIdIntToUuid < ActiveRecord::Migration
def up
remove_foreign_key "business_debts", "loan_applications"
remove_foreign_key "guarantors", "loan_applications"
remove_foreign_key "guarantors", "users"
table_names = [
:loan_applications,
:business_debts,
:case_owners,
@jakecraige
jakecraige / RAC3_API.swift
Last active August 29, 2015 14:23
I'm unsure of what' the best way to dispatch requests in RAC 3. Whether or not using actions or methods is preferred and why. This code shows each way that I've implemented so far.
typealias RequestSignalProducer = SignalProducer<(NSData, NSURLResponse), NSError>
class ApiClient: ApiConnectable {
let apiURL = NSURL(string: "http://yardclub.github.io/mobile-interview/api")!
var getCategories: Action<Void, [Category], NSError>!
init() {
getCategories = Action {
let categoriesURL = self.apiURL.URLByAppendingPathComponent("catalog.json")
return self.getRequest(categoriesURL) |> map { parseJsonArray($0.0) }
@jakecraige
jakecraige / renamer.py
Last active November 15, 2015 15:50
Maya - Joint Hierarchy Alphabetical Renamer
import maya.cmds as mc
window = mc.window(title="Joint Hierarchy Renamer", widthHeight=(500, 55))
mc.columnLayout(adjustableColumn=True)
mc.text(label="Instructions: select top of joint hierarchy")
textField = mc.textFieldButtonGrp(label="New name prefix:", buttonLabel="Rename", buttonCommand="rename_joints()")
mc.showWindow(window)
def rename_joints():
@jakecraige
jakecraige / react-testing-in-rails.diff
Created April 7, 2015 17:19
Simple react component testing in rails + capybara
commit 074a79b95e66d999abe500051c5337805575ea3f
Author: Jake Craige <james.craige@gmail.com>
Date: Tue Apr 7 10:14:29 2015 -0700
Add testing infastructure for React components
diff --git a/app/controllers/components_controller.rb b/app/controllers/components_controller.rb
new file mode 100644
index 0000000..4ffc308
--- /dev/null

Keybase proof

I hereby claim:

  • I am jakecraige on github.
  • I am jakecraige (https://keybase.io/jakecraige) on keybase.
  • I have a public key whose fingerprint is 6EDA C229 FD51 90E5 3C89 550E 9B0F 3B8F 6A21 CE97

To claim this, I am signing this object:

@jakecraige
jakecraige / npm-log-level.json
Last active August 29, 2015 14:13
Silent `npm run`
{
"scripts": {
"test": "npm run --silent test-ci | node_modules/tap-spec/bin/cmd.js",
"test-ci": "node_modules/tape/bin/tape test/*.js"
}
}