Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

  • Salt Lake City, Utah
View GitHub Profile
@jarsen
jarsen / NSURLStringCrap.swift
Last active August 29, 2015 14:02
Add string literal to NSURL
extension NSURL : StringLiteralConvertible {
public class func convertFromStringLiteral(value: String) -> Self {
return self(string: value)
}
public class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self {
return self(string: value)
}
}
extension Array {
func each (block : (T) -> ()) {
for item in self {
block(item)
}
}
}
animals.each(println)
var animals = ["cow", "dog", "pig"]
var emoji = ["🐮", "🐶", "🐷"]
for (animal, pic) in Zip2(animals, emoji) {
println("\(animal) \(pic)")
}
@jarsen
jarsen / gist:8887833
Last active August 29, 2015 13:56
Cool AppCode Keymappings
My stuff is all based off the Xcode keymap—it helps you start with a little bit of familiarity.
Run is weird in appcode, cause it doesn't hit the breakpoints like Xcode's run does. What you want is Debug.
I have mapped Debug to ⌘+R, and Debug... to ⌘+⇧+R (Debug... is awesome!) (Also if you hold shift when you are in the Debug... menu you can run instead of debug)
I have remapped ⌘+T to Class... Effectively this allows me to open new tabs a la Sublime style where you hit command t for a new tab, and then enter the class name you want to open in that tab.
I don't like a lot of the ⌘+1 through ⌘+9 windows the way they are. I picked the ones I like and then remapped them to the lower keys for the ones I like to use a lot. I also hid all the tool window bars.
# 1) open irb
# 2) `load "code_knight.rb"`
# 3) `knights = Marshal::load(Marshal::dump($knights))`
# 4) do the problems using your variable `knights`
# armor types - :light, :medium, :heavy
# ethical_alignment - :chaotic, :neutral, :lawful
# moral_alignment - :good, :neutral, :evil
class CodeKnight
# TOP SECRET
# CodeNight CodeKnight Answer Key!!!
# Problem 0
# Use Enumerable.each to print out a string for each knight in the format of "Jason prefers a sword"
knights.each {|knight| puts "#{knight.name} prefers a #{knight.preferred_weapon}"}
# Problem 1
# Use Enumerable.find_all to find all knights with 50 or more health
# example of incrementing all elements across a list
Enum.map [1,2,3], fn(x) -> x + 1 end
Enum.map [1,2,3], &1 + 1
@jarsen
jarsen / example.rkt
Last active December 19, 2015 05:39
(module example racket
(define (my_print str)
(print str)))
(my_print "Hello, World!")
@jarsen
jarsen / example.exs
Last active December 19, 2015 05:39
defmodule Example do
def my_puts str do
IO.puts str
end
end
Example.my_puts "Hello, World!"
@jarsen
jarsen / NSArrayMagic.m
Last active July 24, 2018 09:22
How to do lots of cool things with NSArray. Inspired by NSHipster and WWDC 2013 Session 228 - "Hidden Gems in Cocoa and Cocoa Touch"
NSArray *albums = @[[Album albumWithName:@"Random Access Memories" price:9.99f],
[Album albumWithName:@"Clarity" price:6.99f],
[Album albumWithName:@"Weekend in America" price:7.99f],
[Album albumWithName:@"Weekend in America" price:7.90f],
[Album albumWithName:@"Bangarang EP" price:2.99f]];
// Reversing an Array
__unused NSArray *reversed = albums.reverseObjectEnumerator.allObjects;
// PREDICATES