Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile

Keybase proof

I hereby claim:

  • I am seanlilmateus on github.
  • I am mateus (https://keybase.io/mateus) on keybase.
  • I have a public key whose fingerprint is E743 5955 91BF 409E 8E63 C31A DFCB 4F92 E6CD BAD2

To claim this, I am signing this object:

@seanlilmateus
seanlilmateus / tap.swift
Last active August 29, 2015 14:02
`tap:` method for Swift borrowed from Ruby. ( a little broken, Cast needed)
import Cocoa
extension NSObject {
func tap(blk:(AnyObject) -> Void) -> Self {
blk(self as NSObject)
return self
}
}
// Alternative, you will need to specify the type :: view:NSView = ...
@seanlilmateus
seanlilmateus / gist:b40298896be3a66c7148
Created July 25, 2014 08:52
I created my own Range literals that make more sense than N..<M in Swift, inspired by Gosu
operator infix |⋅⋅ {}
@infix func |⋅⋅ (lhs: Int, rhs: Int) -> Range<Int> {
return Range(start: lhs + 1, end: rhs)
}
operator infix |⋅⋅| {}
@infix func |⋅⋅|(lhs: Int, rhs: Int) -> Range<Int> {
return Range(start: lhs+1, end: rhs-1)
}
@seanlilmateus
seanlilmateus / from_str.swift
Last active August 29, 2015 14:04
FromStr Protocol the power of Swift Type System...
#!/usr/bin/env xcrun swift -i
import Foundation
// MARK: From String Protocol
protocol FromStr {
class func fromStr(value: String) -> Self?
}
extension Bool : FromStr {
static func fromStr(str: String) -> Bool? {
#!/usr/bin/env xcrun swift
// http://learnyouahaskell.com/functionally-solving-problems
enum Label : String { case A = "A", B = "B", C = "C" }
typealias Section = (Int, Int, Int)
typealias RoadSystem = [Section]
typealias Path = [(name:Label, price:Int)]
// Helpers, A little bit of F# in my life
infix operator |> { associativity left }
@seanlilmateus
seanlilmateus / factorial.rs
Created March 11, 2015 20:17
Rust (rustc 1.0.0-nightly) generic factorial
use std::num::Int;
fn factorial<T: Int>(num: &T) -> T {
if *num == T::zero() || *num == T::one() {
T::one()
} else {
*num * factorial(&(*num - T::one()))
}
}
@seanlilmateus
seanlilmateus / frp.md
Last active August 29, 2015 14:23 — forked from ohanhi/frp.md

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Foreword

class StatusBarView < NSView
attr_reader :progressIndicator, :statusBarItem
def initWithStatusBarItem(item)
bar = item.statusBar
if initWithFrame([[0,0], [bar.thickness, bar.thickness]])
@statusBarItem = item
@highlight = false
origin, size = frame.origin, frame.size
@seanlilmateus
seanlilmateus / gist:974340
Created May 16, 2011 12:16
Using Obj-C Blocks from MacRuby with Ruby 1.9.2 Syntax
# 1 # Processing enumerated arrays using two blocks
area = "Europe"
timeZoneNames = NSTimeZone.knownTimeZoneNames
areaArray = NSMutableArray.arrayWithCapacity 1
areaIndexes = timeZoneNames.indexesOfObjectsWithOptions NSEnumerationConcurrent,
passingTest: -> (obj, idx, stop) {
tmpStr = obj
tmpStr.hasPrefix area
}
tmpArray = timeZoneNames.objectsAtIndexes areaIndexes
class ForwardError
attr_accessor :pointer
def self.new
@pointer = Pointer.new_with_type('@')
self
end
def self.to_pointer
@pointer
end
def self.method_missing(method, *args)