Skip to content

Instantly share code, notes, and snippets.

View gregheo's full-sized avatar
🦊
puppies

Greg Heo gregheo

🦊
puppies
View GitHub Profile
@gregheo
gregheo / url components.swift
Created February 7, 2018 19:05
Fake URL + url encoded query paramaters
import Foundation
let encodedString = "data=%7B%0D%0A%22coffee%22%3A%20%22coffee%22%2C%0D%0A%22beer%22%3A%20%22beer%22%2C%0D%0A%22has_bylaws%22%3A%20true%0D%0A%7D%0D%0A"
guard let c = URLComponents(string: "http://fake.com/?" + encodedString) else {
fatalError("could not generate url components! :(")
}
for item in c.queryItems ?? [] {
print("Got key \(item.name) with value \(item.value)")
@gregheo
gregheo / objc-dispatch-demo.swift
Created December 5, 2017 04:27
Swift Unboxed: @objc and dynamic dispatch
/*
@objc and dynamic dispatch demo
From the article "@objc, Swift, and the Depths of Dynamic Dispatch"
https://swiftunboxed.com/interop/objc-dynamic/
*/
import Foundation
class ToObjcOrNotObjc {
@discardableResult
@gregheo
gregheo / remainder.c
Created July 27, 2016 22:12
remainder()
#include <stdio.h>
#include <math.h>
int main(void) {
double const number = 8.0;
for (double i = number; i < number * 2 + 1; ++i) {
printf("remainder(%2.0f, %2.0f) = %2.0f\n", i, number, remainder(i, number));
}

Keybase proof

I hereby claim:

  • I am gregheo on github.
  • I am gregheo (https://keybase.io/gregheo) on keybase.
  • I have a public key whose fingerprint is 1A52 D760 6FDD D32E 2B2A D269 F17C 8DA5 8AFF CE57

To claim this, I am signing this object:

import UIKit
import CoreImage
class CustomFilter : CIFilter {
var privateInputImage: CIImage?
var inputImage: CIImage? {
set {
privateInputImage = newValue
}
get {
@gregheo
gregheo / gist:4122880
Created November 21, 2012 03:40
FB upload example
-(void) uploadVideo {
NSMutableDictionary *fbParams = @{@"title": @"Video Title",
@"description": @"Video Description",
@"json", @"format"};
FBVideoUpload *faceBookVideoUpload = [[FBVideoUpload alloc] init];
faceBookVideoUpload.apiKey = APP_KEY;
faceBookVideoUpload.appSecret = APP_SECRET;
faceBookVideoUpload.accessToken = accessToken;
[faceBookVideoUpload startUploadWithURL:videoURL fbParams delegate:self];