Skip to content

Instantly share code, notes, and snippets.

View irace's full-sized avatar

Bryan Irace irace

View GitHub Profile
@IanKeen
IanKeen / Example.swift
Last active March 1, 2023 18:15
Lightweight styling setup using UIAppearance
import PlaygroundSupport
// using constrained static members on `Style` we can create presets
extension Style where T: UIButton {
static var global: Style<UIButton> {
return .init { button in
button.backgroundColor = .blue
button.setTitleColor(.red, for: .normal)
}
}
@kasparsd
kasparsd / index.html
Last active June 12, 2023 05:18
Get user timezones using Slack API
<!doctype html>
<html ng-app="timezoneApp">
<head>
<title>Team Timezones</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script>
var period = 172800; // 2 days in seconds
var now = new Date();
var utc = new Date( now.getTime() + now.getTimezoneOffset() * 60000 );
var seconds_today = utc.getSeconds() + ( 60 * ( utc.getMinutes() + ( 60 * utc.getHours() ) ) );
@rnapier
rnapier / gist:dbffbf54274a880a6ac7
Last active July 12, 2016 01:29
More exploration of guard/try and crazy operator idea
// This is pretty clean, but I often dislike chains of temporary variables
// They tend to lead to little bugs when you use the wrong one. Swift's warnings
// and 'let' reduce problems, though.
func pagesFromOpenSearchData(data: NSData) throws -> [Page] {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
guard let array = json as? [JSON] else { throw JSONError.BadArray(json) }
guard case let value = array[1] where array.count >= 2 else { throw JSONError.OutOfRange }
guard let titles = value as? [String] else { throw JSONError.BadStringList(json) }
@cspickert
cspickert / Box.m
Last active August 29, 2015 14:22
#import <Foundation/Foundation.h>
@interface Box<__covariant T: __kindof NSObject *> : NSObject
@property (nonatomic, readonly) __nonnull T value;
- (nonnull instancetype)initWithValue:(nonnull T)value;
@end
@carlfish
carlfish / gist:6b9761670a131f821ad5
Last active February 3, 2018 23:21
Why understanding monads is important.

Either and Promises/Futures are useful and I’ll use them next time they’re appropriate. But outside Haskell does their monad-ness matter?

(All code below is written in some made-up Java-like syntax, and inevitably contains bugs/typos. I'm also saying "point/flatMap" instead of "return/bind" because that's my audience. Any correspondance with anything that either be programatically or mathematically useful is coincidental)

What is a monad? A refresher.

A monad is something that implements "point" and "flatMap" correctly.

// Original implementation with multiple returns:
class func fromId(id: String) -> Office? {
let officesData = JSONData.load("offices") as? [[String: String]] ?? []
let officeData = officesData.filter { $0["id"] == id }.first
if let office = officeData {
return decode(JSONValue.parse(office))
}
@mbbischoff
mbbischoff / FetchedResultsControllerTableViewDataSource.h
Last active August 29, 2015 14:15
FetchedResultsControllerTableViewDataSource. Please stop writing this over and over again.
//
// FetchedResultsControllerTableViewDataSource.h
// Flock
//
// Created by Matthew Bischoff on 2/14/15.
// Copyright (c) 2015 Lickability. All rights reserved.
//
@import Foundation;
@import CoreData;

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).

# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
BOOL PSPDFSystemFunctionOverriddenInCategory(Class theClass, SEL selector, NSString *__autoreleasing* categoryName) {
NSCParameterAssert(theClass);
NSCParameterAssert(selector);
Dl_info info;
if (dladdr(class_getMethodImplementation(theClass, selector), &info)) {
// /System/Library/Frameworks is a common denominator, some methods are in /usr/lib/libobjc.A.dylib
// Custom app is in /private/var/mobile/Containers/Bundle/Application/<UID>/PSPDFCatalog.app/PSPDFCatalog
if (!strstr(info.dli_fname, "/System/Library") && !strstr(info.dli_fname, "/usr/lib")) {
if (categoryName) *categoryName = @(info.dli_sname);