Skip to content

Instantly share code, notes, and snippets.

@spiffytech
spiffytech / import.rb
Last active October 31, 2023 18:44 — forked from evanwalsh/import.rb
Imports a Squarespace dump into Jekyll
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'nokogiri'
require 'fileutils'
require 'safe_yaml'
require 'time'
require 'uri'
require 'open-uri'
@czechboy0
czechboy0 / SwiftTerminalScript.swift
Last active March 5, 2021 01:33
Run Terminal Scripts from your Mac app
//
// Script.swift
// Buildasaur
//
// Created by Honza Dvorsky on 12/05/15.
// Copyright (c) 2015 Honza Dvorsky. All rights reserved.
//
import Foundation

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@myell0w
myell0w / externalKeyboard.m
Last active October 31, 2023 11:21
Detect if there's an external keyboard attached (iOS)
// direct check for external keyboard
+ (BOOL)_isExternalKeyboardAttached
{
BOOL externalKeyboardAttached = NO;
@try {
NSString *keyboardClassName = [@[@"UI", @"Key", @"boa", @"rd", @"Im", @"pl"] componentsJoinedByString:@""];
Class c = NSClassFromString(keyboardClassName);
SEL sharedInstanceSEL = NSSelectorFromString(@"sharedInstance");
if (c == Nil || ![c respondsToSelector:sharedInstanceSEL]) {
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@rentzsch
rentzsch / OmniFocus Selected Mail Messages.applescript
Created January 6, 2015 05:04
OmniFocus Selected Mail Messages.applescript
(*
OmniFocus Selected Mail Messages.applescript
Copyright (c) 2015 Jonathan 'Wolf' Rentzsch: http://rentzsch.com
Some rights reserved: http://opensource.org/licenses/mit
Pure AppleScript reimplementation of OmniGroup's Clip-o-Tron for OmniFocus.
Hopefully this implementation will be more resilient against OS X, Mail, and OmniFocus updates.
Successfully tested against OS X 10.10.1, OmniFocus 1.10.6, and OmniFocus 2.0.4.
@mattbischoff
mattbischoff / LCKIndexedFetchedResultsController.h
Last active August 29, 2015 14:10
LCKIndexedFetchedResultsController is a NSFetchedResultsController subclass that attempts to solve the problem of sorting a fetched collection into correctly alphabetized sections for every locale. It does things like making sure that the `#` character shows up at the bottom instead of the top of the section index titles.
//
// LCKIndexedFetchedResultsController.h
// Quotebook
//
// Created by Andrew Harrison on 7/26/14.
// Copyright (c) 2014 Lickability. All rights reserved.
//
@import CoreData;
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@pyrtsa
pyrtsa / Managing-optionals-in-Swift.swift
Last active March 7, 2017 18:39
Managing optionals in Swift
// Hello, fellow Swift programmer!
//
// Here's a demonstration of a few ways of cleaning up the unwrapping of
// optionals in Swift.
//
// Swift is known to have both OO and functional background. Thus, there is
// probably some middle ground programming style that is *more* functional than
// Objective-C, and probably less so than Haskell. This playground tries to
// compare their differences in the pretty common scenario of dealing with
// errors or missing input.
@kristopherjohnson
kristopherjohnson / pipe-forward-optional.swift
Last active November 28, 2015 22:12
F#-style pipe-forward chaining operators for Swift that unwrap Optional values
// Pipe-forward operators that unwrap Optional values
operator infix |>! { precedence 50 associativity left }
operator infix |>& { precedence 50 associativity left }
// Unwrap the optional value on the left-hand side and apply the right-hand-side function
public func |>! <T,U>(lhs: T?, rhs: T -> U) -> U {
return rhs(lhs!)
}
// If optional value is nil, return nil; otherwise unwrap it and