Skip to content

Instantly share code, notes, and snippets.

View piemonte's full-sized avatar

patrick piemonte piemonte

View GitHub Profile
@beesandbombs
beesandbombs / slicedCube.pde
Created April 30, 2018 20:52
sliced cube
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@reitzig
reitzig / Camelizer.swift
Created February 22, 2018 17:26
Convert Swift strings to camel case
fileprivate let badChars = CharacterSet.alphanumerics.inverted
extension String {
var uppercasingFirst: String {
return prefix(1).uppercased() + dropFirst()
}
var lowercasingFirst: String {
return prefix(1).lowercased() + dropFirst()
}
@piemonte
piemonte / NextLevelGLContext.swift
Created February 13, 2018 17:58
OpenGLES + SceneKit render context for planar frame buffers
//
// NextLevelGLContext.swift
// NextLevel
//
// Created by Patrick Piemonte on 9/26/16.
//
// The MIT License (MIT)
//
// Copyright (c) 2016-present patrick piemonte (http://patrickpiemonte.com/)
//
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@erica
erica / bangbang.md
Last active November 9, 2017 19:17

Introducing the !! "Unwrap or Die" operator to the Swift Standard Library

Introduction

This proposal introduces an annotated forced unwrapping operator to the Swift standard library, completing the ?, ??, and ! family with !!. The "unwrap or die" operator provides text feedback on failed unwraps, to support defensive programming. This operator is commonly implemented in the larger Swift Community and should be considered for official adoption.

@mminer
mminer / MyService.swift
Last active April 23, 2024 23:00
Components of XPC service.
import Foundation
class MyService: NSObject, MyServiceProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
reply(response)
}
}
@rootulp
rootulp / export_foursquare_checkins.py
Last active June 13, 2020 01:38 — forked from dlo/export_foursquare_checkins.py
Download all your Foursquare checkins with Python.
# Before running this script execut the following command:
# $ pip install requests
# To run this script execute:
# $ python export_foursquare_checkins.py
import requests
import json
url_template = 'https://api.foursquare.com/v2/users/self/checkins?limit=250&oauth_token={}&v=20131026&offset={}'
# If you navigate to https://developer.foursquare.com/docs/explore, Foursquare
// Evaluates the given closure when two `Optional` instances are not `nil`,
// passing the unwrapped values as parameters. (Thanks, Mike Ash, Tim Vermeulen)
// Following the example of IEEE754 with NAN, any comparison involving
// .None is false
//
// See also: http://stackoverflow.com/questions/1565164/what-is-the-rationale-for-all-comparisons-returning-false-for-ieee754-nan-values
// Brent RG has a really interesting take here: https://gist.github.com/brentdax/60460ad4578d5d8d52a9d736240cfea6
fileprivate func _flatMap2<T, U, V>(_ first: T?, _ second: U?, _ transform: (T, U) throws -> V?) rethrows -> V? {
@kennwhite
kennwhite / 1944_OSS_Simple_Sabotage_Field_Manual.md
Last active May 17, 2024 09:58
1944 OSS Simple Sabotage Field Manual
@LuizZak
LuizZak / retry.swift
Last active February 12, 2018 10:27
PromiseKit retrying functions using encapsulated blocks that return promises
/// Retries the given throwing `block` as a promise `tries` times,
/// re-calling `block` another time until exhausting the tries.
func retry<T>(tries count: Int, block: () throws -> T) -> Promise<T> {
return Promise().thenRetry(tries: count, block: block)
}
/// Retries the given promise-returning `block` as a promise `tries` times,
/// re-calling `block` another time until exhausting the tries.
func retry<T>(tries count: Int, block: () -> Promise<T>) -> Promise<T> {
return Promise().thenRetry(tries: count, block: block)