Skip to content

Instantly share code, notes, and snippets.

@dynamicdispatch
dynamicdispatch / staticlibobjcabichecker.rb
Last active September 20, 2019 12:17
Simple ruby script to check that Objective-C static libraries are built with the latest ObjC ABI
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'open3'
# This tool checks an input path for all static libraries *.a files
# and makes sure they were built with the most modern ObjC ABI version.
# Parse command line options.
@JohnSundell
JohnSundell / Podfile
Last active September 4, 2019 15:20
A Podfile that demonstrates how to use dependencies that use an older Swift version
target 'MyTarget' do
use_frameworks!
# Post installation script that enables the Swift 4.2 compiler's
# legacy 4.1 mode for 4.2-incompatible pods
post_install do |installer|
incompatiblePods = ['PodA', 'PodB']
installer.pods_project.targets.each do |target|
if incompatiblePods.include? target.name
@banjun
banjun / MockAVCaptureDevice.swift
Last active July 13, 2023 14:53
mock AVCaptureDevice in Xcode 9
extension AVCaptureDevice {
class func swizzle() {
[(#selector(AVCaptureDevice.defaultDevice(withMediaType:)), #selector(AVCaptureDevice.mockDefaultDevice(withMediaType:)))].forEach {
let original = class_getClassMethod(self, $0)
let mock = class_getClassMethod(self, $1)
method_exchangeImplementations(original, mock)
}
[(#selector(AVCaptureDevice.hasMediaType(_:)), #selector(AVCaptureDevice.mockHasMediaType(_:))),
(#selector(AVCaptureDevice.supportsAVCaptureSessionPreset(_:)), #selector(AVCaptureDevice.mockSupportsAVCaptureSessionPreset)),
(#selector(AVCaptureDevice.isTorchModeSupported(_:)), #selector(AVCaptureDevice.mockIsTorchModeSupported)),
@radianttap
radianttap / wwdc17.sh
Created June 7, 2017 09:57
Bash script to download all HD videos + PDF slides for WWDC 2017
#!/bin/bash
#Setup the environnement
mkdir wwdc2017
cd wwdc2017
mkdir tmp_download
cd tmp_download
#Extract IDs
echo "Downloading the index"
@wojteklu
wojteklu / terminal_notification.md
Last active April 28, 2023 00:43
Show macOS notification when long running command finishes and your terminal is not in focus.

Add the following to your ~/.zshrc:

function notifyme {
  LAST_EXIT_CODE=$?
  CMD=$(fc -ln -1)
  osascript -e 'on run argv
  tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
 if frontApp is not "Terminal" then
@alskipp
alskipp / ignoreNil.swift
Created May 6, 2016 00:04
How to ignore `nil` values using RxSwift without using❗️
// Create an `Observable` of Optional<Int>
let values: Observable<Int?> = [1, 2, .None, 3, .None, 4, 5].toObservable()
// Method 1: using a free function
// Requires passing the function to `flatMap`
func ignoreNil<A>(x: A?) -> Observable<A> {
return x.map { Observable.just($0) } ?? Observable.empty()
}
@wojteklu
wojteklu / gitenv.md
Last active September 5, 2023 00:58
Perfect git environment on OS X

Perfect git environment on OS X

Global alias

Add the following to your ~/.bashrc:

alias g='git'

Branch auto-completion

@protrolium
protrolium / ffmpeg.md
Last active May 3, 2024 18:58
ffmpeg guide

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with:

@natecook1000
natecook1000 / OptionalBinding.swift
Created February 11, 2015 04:15
Some extremely contrived examples using Swift 1.2 if-let bindings
// OptionalBinding.swift
// as seen in http://nshipster.com/swift-1.2/
//
// (c) 2015 Nate Cook, licensed under the MIT license
let a: Int? = 10
let b: Int? = 5
let c: Int? = 3
let d: Int? = -2
let e: Int? = 0
@natecook1000
natecook1000 / CalculatorView.swift
Last active June 6, 2022 01:00
An IBInspectable Calculator Construction Set
// CalculatorView.swift
// as seen in http://nshipster.com/ibinspectable-ibdesignable/
//
// (c) 2015 Nate Cook, licensed under the MIT license
/// The alignment for drawing an String inside a bounding rectangle.
enum NCStringAlignment {
case LeftTop
case CenterTop
case RightTop