Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
@jarsen
jarsen / reddit_miner.rb
Created October 10, 2012 18:03
Script for data mining reddit and producing ARFF file
#!/usr/bin/env ruby -wKU
require 'net/http'
require 'json'
STOPWORDS = %w(
a about above after again against all am an and any are aren't as at be because been before
being below between both but by can't cannot could couldn't did didn't do does doesn't doing
don't down during each few for from further had hadn't has hasn't have haven't having he he'd
he'll he's her here here's hers herself him himself his how how's i i'd i'll i'm i've if in
@jarsen
jarsen / sieve.coffee
Created December 12, 2012 01:25
The sieve of Eratosthenes.
sieve = (n) ->
primes = (true for i in [3..n])
for i in [2..n]
continue if Math.pow(i,i) > n
for j in [Math.pow(i,i)-3..n] by i
primes[j] = no
(index + 3 for primality, index in primes when primality)
console.log sieve(1000000)
// old way
- (NSMutableArray *)sections {
if (!_sections) {
_sections = [NSMutableArray new];
}
return _sections;
}
// cool new way
- (NSMutableArray *)sections {
@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
@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 / example.rkt
Last active December 19, 2015 05:39
(module example racket
(define (my_print str)
(print str)))
(my_print "Hello, World!")
# 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
# 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
# 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
@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.