Skip to content

Instantly share code, notes, and snippets.

View rnapier's full-sized avatar

Rob Napier rnapier

View GitHub Profile
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
uint8_t *signature, UInt16 signatureLen)
{
OSStatus err;
SSLBuffer hashOut, hashCtx, clientRandom, serverRandom;
uint8_t hashes[SSL_SHA1_DIGEST_LEN + SSL_MD5_DIGEST_LEN];
SSLBuffer signedHashes;
uint8_t *dataToSign;
size_t dataToSignLen;
@rnapier
rnapier / Curryinate.swift
Last active August 29, 2015 14:05
Curry and flip with ~~ postfixing. I wonder if this is a good idea…
// Based on https://gist.github.com/kristopherjohnson/adde22d2c53adfb756a1
// Warning, this is insanely slow to compile in Beta6 (can take several minutes)
// Remove some of the |> lines to speed things up
// For more on |>, see http://undefinedvalue.com/2014/07/13/fs-pipe-forward-operator-swift
infix operator |> { precedence 50 associativity left }
// "x |> f" is equivalent to "f(x)"
public func |> <T,U>(lhs: T, rhs: T -> U) -> U {
return rhs(lhs)
@rnapier
rnapier / result.swift
Last active August 29, 2015 14:06
The ever-important Result type (without methods)
enum Result<A> {
case Success(Box<A>)
case Failure(NSError)
}
// Due to current swift limitations, we have to include this Box in Result.
// Swift cannot handle an enum with multiple associated data (A, NSError) where one is of unknown size (A)
final class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
@gngrwzrd
gngrwzrd / fix-xcode.py
Last active December 23, 2015 11:28 — forked from rnapier/fix-xcode
#!/usr/bin/python
#original script by Rob Napier <robnapier@gmail.com>
#updates by github.com/gngrwzrd
#Script to link in all your old SDKs every time you upgrade Xcode
#Create a directory somewhere to store older SDKs in
#Under it, put all the platform directories:
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform
#Under those, store the SDKs:
@benlodotcom
benlodotcom / MyAVController.h
Last active February 3, 2016 17:45
A little demo snippet that you can use to access directly the camera video in IOS4
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CoreVideo/CoreVideo.h>
#import <CoreMedia/CoreMedia.h>
/*!
@class AVController
@author Benjamin Loulier
@jessesquires
jessesquires / generics_playground.swift
Last active June 27, 2018 02:19
Swift optional generic parameters?
protocol FactoryAType {
typealias Product
}
protocol FactoryBType {
typealias Product
}
@andymatuschak
andymatuschak / gist:2b311461caf740f5726f
Created December 28, 2014 18:17
A pragmatic and intentionally non-abstract solution to JSON decoding / initialization that doesn't require learning about five new operators.
struct User {
let id: Int
let name: String
let email: String?
}
extension User: JSONDecodable {
static func create(id: Int, name: String, email: String?) -> User {
return User(id: id, name: name, email: email)
}
@sambatyon
sambatyon / rgb2yuv.cc
Created February 13, 2012 16:02
Transforms a bitmap int RGB 8:8:8 24bpp into an equivalent YUV420p 4:2:0 12bpp
void Bitmap2Yuv420p(boost::uint8_t *destination, boost::uint8_t *rgb,
const int &width, const int &height) {
const std::size_t image_size = width * height;
boost::uint8_t *y = destination;
boost::uint8_t *u = destination + image_size;
boost::uint8_t *v = destination + image_size + image_size / 4;
boost::uint8_t *r = rgb;
boost::uint8_t *g = rgb + 1;
boost::uint8_t *b = rgb + 2;
@ShamylZakariya
ShamylZakariya / debounce.swift
Created September 4, 2014 21:01
Simple Swift Debouncer
func debounce( delay:NSTimeInterval, #queue:dispatch_queue_t, action: (()->()) ) -> ()->() {
var lastFireTime:dispatch_time_t = 0
let dispatchDelay = Int64(delay * Double(NSEC_PER_SEC))
return {
lastFireTime = dispatch_time(DISPATCH_TIME_NOW,0)
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
@h12w
h12w / goclean.sh
Last active August 24, 2021 03:13
golcean.sh does automatic checking on a Go package and its sub-packages.
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. goimports (https://github.com/bradfitz/goimports)
# 3. golint (https://github.com/golang/lint)
# 4. go vet (http://golang.org/cmd/vet)
# 5. race detector (http://blog.golang.org/race-detector)
# 6. test coverage (http://blog.golang.org/cover)
set -e