Skip to content

Instantly share code, notes, and snippets.

@NachoSoto
NachoSoto / AnyValidator.swift
Last active December 3, 2015 14:21
Type-erased ValidatorType
protocol ValidatorType {
typealias ValidatedType
func isValid(object: ValidatedType) -> Bool
}
// You might want to make it a reference type, depending on your case.
struct AnyValidator<T>: ValidatorType {
private let validatorBlock: (T) -> Bool
init<V: ValidatorType where V.ValidatedType == T>(validator: V) {
@nevyn
nevyn / GFASLProxy.m
Created November 30, 2015 23:41
Capturing ASL on Mac/iOS
// See also https://github.com/CocoaLumberjack/CocoaLumberjack/blob/master/Classes/DDASLLogCapture.m
#import "GFASLProxy.h"
#include <asl.h>
#include <notify.h>
#include <notify_keys.h>
#include <sys/time.h>
@implementation GFASLProxy
@celoyd
celoyd / hi8-anim-howto.md
Last active August 1, 2022 15:37
A way to make Himawari-8 animations

Himawari-8 animation tutorial

Here’s how to make animations like this one. It requires intermediate Unix command-line knowledge, to install some tools and to debug if they don’t work. You’ll need these utilities:

  • curl (or you can translate to wget)
  • convert and montage, part of ImageMagick
  • ffmpeg, plus whatever codecs
  • parallel, for iteration that’s nicer than shell for loops or xargs
  • run everything in zsh for leading 0s in numerical ranges to work
@rnystrom
rnystrom / RN3DTouchGestureRecognizer.swift
Last active February 3, 2018 22:58
RN3DTouchGestureRecognizer
//
// RN3DTouchGestureRecognizer.swift
//
// Created by Ryan Nystrom on 10/10/15.
// Copyright © 2015 Ryan Nystrom. All rights reserved.
//
import UIKit.UIGestureRecognizerSubclass
class RN3DTouchGestureRecognizer: UIGestureRecognizer {
@AndrewHoos
AndrewHoos / shell.py
Last active November 26, 2019 15:09
A shell function that can read and echo both stdout and stderr (works with bash)
'''A simple utility for running UNIX shell commands'''
KEEP_STDOUT = 0x1
KEEP_STDERR = 0x1 << 1
ECHO_STDOUT = 0x1 << 2
ECHO_STDERR = 0x1 << 3
def shell(command, input_=None, output_=(KEEP_STDOUT | KEEP_STDERR | ECHO_STDOUT | ECHO_STDERR), wait=True):
'''
@loderunner
loderunner / 01-mac-profiling.md
Last active May 21, 2025 14:14
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@JacobNinja
JacobNinja / pipeline.clj
Last active April 6, 2022 09:14
Clojure core.async pipeline example
(require '[clojure.core.async :as async]
'[clj-http.client :as client]
'[clojure.data.json :as json])
(def concurrency 5)
(let [in (async/chan)
out (async/chan)
request-handler (fn [url out*]
(async/go
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@JadenGeller
JadenGeller / Swift Coalesce Function.swift
Last active August 29, 2015 14:16
Swift Coalesce Function
/*
* coalesce takes in a list of optional values
* and returns the first one that is not nil
*/
func coalesce<T>(all: @autoclosure () -> T? ...) -> T? {
for f: () -> T? in all {
if let x = f() { return x }
}
return nil
@thinkclay
thinkclay / Keychain.swift
Last active August 30, 2016 12:13
Dead simple keychain access
import Security
public class Keychain
{
public class func set(key: String, value: String) -> Bool
{
if let data = value.dataUsingEncoding(NSUTF8StringEncoding)
{
return set(key, value: data)
}