Skip to content

Instantly share code, notes, and snippets.

View gfontenot's full-sized avatar
football

Gordon Fontenot gfontenot

football
View GitHub Profile
@gfontenot
gfontenot / 0_reuse_code.js
Created January 30, 2014 00:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
### Keybase proof
I hereby claim:
* I am gfontenot on github.
* I am gfontenot (https://keybase.io/gfontenot) on keybase.
* I have a public key whose fingerprint is FC96 877D E91A C0B4 381D D33A 0BF4 A6C7 2DA8 F9CE
To claim this, I am signing this object:
import Foundation
class DispatchGroup {
private var blocks: [dispatch_block_t] = []
private let dispatch_queue = dispatch_queue_create("com.dispatch_group.foo", DISPATCH_QUEUE_CONCURRENT)
private let dispatch_group = dispatch_group_create()
func andThen(block: dispatch_block_t) -> Group {
blocks += [block]
return self
import Foundation
infix operator >>- { associativity left precedence 150 }
public func >>-<T, U>(a: T?, f: T -> U?) -> U? {
return a.flatMap(f)
}
extension Optional {
func flatMap<U>(f: T -> U?) -> U? {
switch self {
// Original implementation with multiple returns:
class func fromId(id: String) -> Office? {
let officesData = JSONData.load("offices") as? [[String: String]] ?? []
let officeData = officesData.filter { $0["id"] == id }.first
if let office = officeData {
return decode(JSONValue.parse(office))
}
// stored property, no default value
let foo: String
// stored property, default value
let foo: String = "foo"
// or
let foo = "foo"
// computed property, no custom setter
var foo: String {
@gfontenot
gfontenot / Decoding.swift
Created July 22, 2015 15:40
Example of using partial application as a way to solve side loaded JSON with immutable value objects
// Returning a function here, instead of a fully realized object
extension Company: Decodable {
static func decode(j: JSON) -> Decoded<[People] -> Company> {
return create
<^> j <| "id"
<*> j <| ["attributes", "name"]
}
}
@gfontenot
gfontenot / CleanDB.py
Created June 3, 2010 17:15
Python script to crawl the contents of your dropbox folder for Conflicted Copies
#!/usr/bin/env python
# encoding: utf-8
"""
CleanDB.py
Created by Gordon on 2010-06-03.
Copyright (c) 2010 Gordon Fontenot. All rights reserved.
"""
import sys
@gfontenot
gfontenot / UIImageManipulator.m
Created June 10, 2010 00:13
UIImageManipulator actions
#import "UIImageManipulator.h"
@implementation UIImageManipulator
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight)
{
float fw, fh;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(context, rect);
@gfontenot
gfontenot / gist:442306
Created June 17, 2010 15:55
Modification for FBDialog.m to trash cookies before asking permissions
if ([url isEqualToString:@"http://www.facebook.com/login.php"]) {
[cookies setCookie:testCookie]; // Create the test_cookie as required by login.php
} else if ([url isEqualToString:@"http://www.facebook.com/connect/prompt_permission.php"]) {
NSArray *cookieJar = [cookies cookies];
for (id aCookie in cookieJar) {
[cookies deleteCookie:aCookie];
}
}