Skip to content

Instantly share code, notes, and snippets.

View stephencelis's full-sized avatar

Stephen Celis stephencelis

View GitHub Profile
// gem install cocoapods-playgrounds
// pod playgrounds LibYAML
// Update: @floriankugler had a great idea to use UnsafeBufferPointer
// Paste in the following:
import LibYAML
public struct YAMLError: ErrorType {
@DrBoolean
DrBoolean / mcft.js
Created December 30, 2015 04:44
Monoidal Contravariant Functors and Transducers
const daggy = require('daggy');
const {foldMap} = require('pointfree-fantasy')
const {concat, toUpper, prop, identity, range, compose} = require('ramda');
// Contravariant functors usually have this shape F(a -> ConcreteType).
// In other words, some type holding a function which is parametric on its input, but not output.
// They don't always have that shape, but it's a good intuition
// Covariant functors are what we're used to, which are parametric in their output
//================================================================
import Cocoa
enum CoroutineState {
case Fresh, Running, Blocked, Canceled, Done
}
struct CoroutineCancellation: ErrorType {}
class CoroutineImpl<InputType, YieldType> {
let body: (yield: YieldType throws -> InputType) throws -> Void
@natecook1000
natecook1000 / NSTimer+Closure.swift
Last active January 6, 2024 07:23
Scheduled NSTimer with a Swift closure
extension NSTimer {
/**
Creates and schedules a one-time `NSTimer` instance.
- Parameters:
- delay: The delay before execution.
- handler: A closure to execute after `delay`.
- Returns: The newly-created `NSTimer` instance.
*/
@CodaFi
CodaFi / Sections.swift
Last active August 29, 2015 14:10
Operator sections for the Swift STL.
/// Sectional Sale
prefix operator >> {}
postfix operator >> {}
public prefix func >>(rhs: UInt16) -> UInt16 -> UInt16 {
return { lhs in lhs >> rhs }
}
public postfix func >>(lhs: UInt16) -> UInt16 -> UInt16 {
@peeblesjs
peeblesjs / gist:9288f79322ed3119ece4
Last active February 11, 2016 23:31
A naive "valueForKey:" operator in Swift
operator infix --> {}
func --> (instance: Any, key: String) -> Any? {
let mirror = reflect(instance)
for index in 0 ..< mirror.count {
let (childKey, childMirror) = mirror[index]
if childKey == key {
return childMirror.value
}
}
@davidcelis
davidcelis / not_class.rb
Last active February 27, 2020 22:31
NotClass
class Object
def not
NotClass.new(self)
end
end
class NotClass < BasicObject
instance_methods.grep(/^[^_]/).each { |m| undef_method m }
def initialize(object)
@stephencelis
stephencelis / emoji.txt
Created April 3, 2012 18:38
iOS 6 / Mountain Lion Emoji
2139 ℹ INFORMATION SOURCE
23EB ⏫ BLACK UP-POINTING DOUBLE TRIANGLE
23EC ⏬ BLACK DOWN-POINTING DOUBLE TRIANGLE
23F0 ⏰ ALARM CLOCK
23F3 ⏳ HOURGLASS WITH FLOWING SAND
26C5 ⛅ SUN BEHIND CLOUD
26D4 ⛔ NO ENTRY
2705 ✅ WHITE HEAVY CHECK MARK
2753 ❓ BLACK QUESTION MARK ORNAMENT
2757 ❗ HEAVY EXCLAMATION MARK SYMBOL
@marcel
marcel / gist:2100703
Created March 19, 2012 07:24
giftube – Generates an animated gif from a YouTube url.
#!/usr/bin/env ruby
# giftube – Generates an animated gif from a YouTube url.
#
# Usage:
#
# giftube [youtube url] [minute:second] [duration]
#
# ex.
#
@sethbro
sethbro / test_helper.rb
Created January 13, 2012 18:19
MiniTest::Spec with Rails setup
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
require 'capybara/rails'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown