Skip to content

Instantly share code, notes, and snippets.

View piemonte's full-sized avatar

patrick piemonte piemonte

View GitHub Profile
@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)
}
}
@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.

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);
@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/)
//
@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()
}
@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);
@domhofmann
domhofmann / onono.md
Last active August 23, 2020 11:59
onono

Onavo Protect is a free and popular VPN owned by Facebook.

Facebook ostensibly uses Onavo to monitor user network traffic, specifically to gain insight into what is and isn't working in competing apps. That kind of sucks if you're building a consumer app and aren't planning on selling it to Facebook.

Detecting if the people who use your app are also using Onavo and encouraging them to disable it might be helpful to you.

Here is some Swift code that does that:

func checkForBadIP (_ ip: String) -> Bool {
@elaughli
elaughli / obj2usdz.mm
Created December 12, 2018 22:33
function to convert a saved obj file to USDZ in objective-c
// path to documents directory to save our usdc file
NSString* usdcPath = [documentsDirectory stringByAppendingPathComponent:@"usdcExample.usdc"];
NSURL *usdcUrl = [NSURL fileURLWithPath: usdcPath];
// path to documents directory to save our final usdz file
NSString* usdzPath = [documentsDirectory stringByAppendingPathComponent:@"usdzExample.usdz"];
NSURL *usdzUrl = [NSURL fileURLWithPath:usdzPath];
// load the .obj file at filePath as an MDLAsset
NSURL *url = [NSURL fileURLWithPath:filePath];
import UIKit
struct Action {
let title: String
let style: UIAlertAction.Style
let action: () -> Void
}
extension Action {
static func `default`(_ title: String, action: @escaping () -> Void) -> [Action] {
# its dependencies are gifsicle and ffmpeg
gifify() {
if [[ -n "$1" ]]; then # if the input lengt≈h is non-zero
randomPlace=0 #lazy, i use it for filename regurdless if its needed or not
if [[ $2 != '--random' && $3 != '--random' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
else
#s=$(ffprobe -i $1 -show_entries format=duration -v quiet -of csv="p=0")
s=$(ffprobe -i $1 -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1)
seconds=$(echo "$s - 2" | bc)