Skip to content

Instantly share code, notes, and snippets.

View jacklynrose's full-sized avatar

Jacklyn Rose jacklynrose

  • Australia
View GitHub Profile
@jacklynrose
jacklynrose / uiview+controller_helper.rb
Created March 16, 2014 14:45
Monkey patch for finding the controller of a view
class UIView
def controller
if self.nextResponder.is_a? UIViewController
return self.nextResponder
elsif self.nextResponder.respond_to? :controller
return self.nextResponder.controller
end
end
end
@jacklynrose
jacklynrose / Rakefile
Last active August 29, 2015 13:57
Simple macro like functionality for RubyMotion
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
require './lib/preprocessor'
begin
require 'bundler'
Bundler.require
rescue LoadError
end
@jacklynrose
jacklynrose / keybase.md
Created April 16, 2014 23:55
keybase.md

Keybase proof

I hereby claim:

  • I am fluffyjack on github.
  • I am fluffyjack (https://keybase.io/fluffyjack) on keybase.
  • I have a public key whose fingerprint is 8203 E7C0 359A 6B05 1787 ED6E C1C5 3A42 6E34 5928

To claim this, I am signing this object:

@jacklynrose
jacklynrose / fib_calculator.rb
Created April 19, 2014 11:13
Fast and memory efficient fib calculation based off Ray Hightower's memoization method but with better memory usage (http://rayhightower.com/blog/2014/04/12/recursion-and-memoization/)
# Fibonacci numbers WITH memoization.
# Initialize the memoization hash.
@scratchpad = {}
@max_fibo_size = 1_000_000_000_000
# Calculate the nth Fibonacci number, f(n).
def fibo (n)
val = if n <= 1
n
@jacklynrose
jacklynrose / README.md
Last active August 29, 2015 14:01
How I run MiniTest tests in 50% of the time of Rake::TestTask

RESULTS

Rake::TestTask

time rake test
real	0m1.111s
user	0m0.962s
sys	0m0.133s

time rake test
@jacklynrose
jacklynrose / chooser.rb
Created May 13, 2014 07:46
How my girlfriend and I can make decisions from now on
#!/usr/bin/ruby
puts ARGV.sample
@jacklynrose
jacklynrose / openstruct.rb
Created May 23, 2014 09:55
Half implementation of OpenStruct
class OpenStruct < BasicObject
def initialize(hash)
@struct = ::Struct.new(*hash.keys.map { |k| k.to_sym })
@struct = @struct.new(*hash.values)
end
def ==(other)
to_h == other.to_h
end
@jacklynrose
jacklynrose / ex1.c
Last active August 29, 2015 14:01
Hello {{name}} in C
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char hello[80];
strcpy(hello, "Hello ");
if (argc > 1)
{
puts(strcat(hello, argv[1]));
@jacklynrose
jacklynrose / motion-kit-love.rb
Created December 18, 2014 10:31
I do love motion-kit
class ProfileLayout < MotionKit::Layout
def layout
add UIImageView, :profile_image
add UILabel, :name_label
add UILabel, :bio_label
background_color UIColor.whiteColor
end
def profile_image_style
@jacklynrose
jacklynrose / README.md
Last active August 29, 2015 14:13
Using self-invoking closures for tricky mutable dictionary values.

Swift Self-invoking Closures

While working on the iOS Development with Swift book I decided on this code for an example I'm using in the chapter that talks about composing views together. This is a silly little scroll view that displays a user's bio, and is actually used by a ProfileView that contains this and a UserDetailsView.

Profile View

Explaination

On line 19 I'm creating the setter for the text property that basically is meant to act as a way to apply default attributes to a plain string and assign it to the bio label's attributedText property.