Skip to content

Instantly share code, notes, and snippets.

View funky-monkey's full-sized avatar

Sidney de Koning funky-monkey

View GitHub Profile
@funky-monkey
funky-monkey / ios-cell-registration-swift.md
Last active June 15, 2017 09:46 — forked from gonzalezreal/ios-cell-registration-swift.md
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@funky-monkey
funky-monkey / mogen.sh
Created June 14, 2016 14:15
Mogenerator for Swift. Can also be used as a Build Phase
# Build this target to update the mogenerator generated files after changing xcdatamodel!
PROJECT_NAME="iFleat"
cd "$SRCROOT"/"$PROJECT_NAME"/Model
mogenerator --model "$SRCROOT"/"$PROJECT_NAME"/Model/"$PROJECT_NAME".xcdatamodeld/ --machine-dir _Machine --swift
@funky-monkey
funky-monkey / SSLPin.swift
Last active October 6, 2016 08:22 — forked from mdelete/gist:d9dbc320d5de347c2a85
Swift iOS SSL public key pinning
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) {
if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
var localTrust: Unmanaged<SecTrust>?
let serverTrust = challenge.protectionSpace.serverTrust!
let serverPublicKey = SecTrustCopyPublicKey(serverTrust).takeRetainedValue();
let certificateData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("pinning-certificate", ofType: "der")!)
let localCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, certificateData).takeRetainedValue();
let policy = SecPolicyCreateBasicX509().takeRetainedValue()
if SecTrustCreateWithCertificates(localCertificate, policy, &localTrust) == errSecSuccess {
@funky-monkey
funky-monkey / Snippets.md
Last active November 1, 2016 09:22
Xcode Code Snippets sharing

Sharing of Xcode code snippets

0. Create new git repo on disk

mkdir ~/XcodeSnippets/
cd XcodeSnippets/; git init
git remote add origin https://github.com/[you]/my_snippets.git
cp -a ~/Library/Developer/Xcode/UserData/CodeSnippets/*.codesnippet ~/XcodeSnippets/ push to your repo to fill it with snippets

1. Checkout snippets repo somewhere on disk

git clone [email protected]:me/my_snippets.git ~/MyRepos/

@funky-monkey
funky-monkey / diff.mdown
Created November 17, 2016 10:34 — forked from ndarville/diff.mdown
Paul Heckel's Diff Algorithm

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

>The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.

@funky-monkey
funky-monkey / Tutorial.md
Created November 18, 2016 21:03 — forked from RF-Nelson/Tutorial.md
Using the Multipeer Connectivity Framework to Create the Open Source Selfie Stick iOS App

Using the iOS Multipeer Connectivity Framework to Create Open Source Selfie Stick

In this gist, I will discuss how I used the Multipeer Connectivity framework to create Open Source Selfie Stick. Open Source Selfie Stick is a free open-source iOS app that allows users to sync two devices over WiFi or Bluetooth and allows one to act as a remote control for the other's camera.

This tutorial assumes some knowledge of the Swift programming language and iOS development with Xcode.

Feel free to comment and point out any errors or improvements. If you'd like to help improve the app itself, make a fork from dev branch of the git repo. I plan on updating this document and explaining any newly added features or refactoring. As this gist w

@funky-monkey
funky-monkey / optparse-template.rb
Created November 28, 2016 12:00 — forked from rtomayko/optparse-template.rb
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@funky-monkey
funky-monkey / nginx.conf
Created December 21, 2016 08:37 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@funky-monkey
funky-monkey / mp3concat.rb
Created January 5, 2017 15:29 — forked from janpaul/mp3concat.rb
generate an ffmpeg command that converts a directory full of MP3's to one large MP3
# copy-and-paste the output of this script into a shell, and rejoice.
files=Dir.glob('*.mp3').sort.join('|')
puts "ffmpeg -i \"concat:#{files}\" -acodec copy output.mp3"