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
// old way
- (NSMutableArray *)sections {
if (!_sections) {
_sections = [NSMutableArray new];
}
return _sections;
}
// cool new way
- (NSMutableArray *)sections {
@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)
@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 / gist:3796144
Created September 27, 2012 20:01
strange.rb
foo = %w{cat dog dog cat cat cat dog cat dog dog cat cat dog dog}
bar = %w{yes no yes yes yes no no yes no yes no no yes yes}
puts "Foo: #{foo}"
puts "Bar: #{bar}"
histogram = foo.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
puts histogram
@jarsen
jarsen / gist:3739144
Created September 17, 2012 19:05
brew install netpbm output
~ % brew install netpbm
==> Downloading http://sourceforge.net/projects/netpbm/files/super_stable/10.35.86/netpbm-10.35.86.tgz
Already downloaded: /Library/Caches/Homebrew/netpbm-10.35.86.tgz
/usr/bin/tar xf /Library/Caches/Homebrew/netpbm-10.35.86.tgz
==> cp Makefile.config.in Makefile.config
cp Makefile.config.in Makefile.config
==> make
make
/private/tmp/brew-netpbm-10.35.86-LQva/netpbm-10.35.86/Makefile.common:560: Makefile.depend: No such file or directory
cat /dev/null >Makefile.depend
@jarsen
jarsen / blahblah.m
Created July 11, 2012 16:50
UIAppearance Crap
// UISegmented control
UIImage *segSelected = [[UIImage imageNamed:@"sel.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
UIImage *segUnselected = [[UIImage imageNamed:@"uns.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
UIImage *segSelectedUnselected = [UIImage imageNamed:@"sel-uns"];
UIImage *segUnselectedSelected = [UIImage imageNamed:@"uns-sel"];
UIImage *segUnselectedUnselected = [UIImage imageNamed:@"uns-uns"];
[[UISegmentedControl appearance] setBackgroundImage:segUnselected
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
@jarsen
jarsen / usageExample.m
Created June 21, 2012 18:32
Creating Custom UIBarButtonItems Usage
[self.fullscreenButton customViewButtonWithImage:@"fullscreenButton" target:self action:@selector(toggleFullScreen:)];
@jarsen
jarsen / UIBarButtonItem+Custom.m
Created June 21, 2012 18:12
Creating Custom UIBarButtonItems
// UIBarButtonItem+Custom.h
// Created by Jason Larsen on 6/21/12.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Custom)
- (void)customViewButtonWithImage:(NSString *)imageName target:(id)target action:(SEL)selector;
@end
@jarsen
jarsen / pinhack.m
Created March 21, 2012 07:01
A snippet showing how to pin something to pinterest from your iOS app
NSURL *url = [NSURL URLWithString:@"pinit12://pin/create/bookmarklet/?media=http%3A%2F%2Fimages.apple.com%2Fhome%2Fimages%2Fipad_hero.jpg&url=http%3A%2F%2Fwww.apple.com%2F&title=Apple&is_video=false&description=Test"];
[[UIApplication sharedApplication] openURL:url];
@jarsen
jarsen / cookie_catcher.rb
Created November 15, 2010 06:06
A simple cookie catcher written in ruby.