Skip to content

Instantly share code, notes, and snippets.

View ParkinT's full-sized avatar

Thom Parkin ParkinT

View GitHub Profile
@ParkinT
ParkinT / Ruby Hash Example
Created March 10, 2011 01:37
I would expect the 'key' only in the second case
Try this in the IRB console.
>> testhash = { :key1 => 'val1', :key2 => 'val2', :key3 => 'val3' }
>> testhash.each { | key, value | p key.to_s }
>> testhash.each { | key | p key.to_s }
My expectation was for the output to be the same in both cases.
Why the difference?
Why are the key and value concatenated?
@ParkinT
ParkinT / Rakefile (RubyMotion)
Created June 5, 2012 00:02
RubyMotion Rakefile simplified
Working with RubyMotion, I find myself repeating some tasks. In an attempt to develop (for myself) some standards and scripts to simplify the repetitive tasks, I decided to leverage RUBY syntax.
Here is my "template" for the Rakefile I use in RubyMotion
============
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'killerApp'
@ParkinT
ParkinT / alert.rb
Created June 24, 2012 02:24
RubyMotion generic Alert class
# A generic class to encapsulate the simple UIAlertView capability in iOS
# usage:
# @alert = Alert.new { :title => "IMPORTANT ALERT", :message => "It is bad luck to be superstitious!"}
# @alert.show
class Alert
attr_reader :dialog, :alert_message, :alert_title, :alert_acknowledge
def initialize(params = {})
@ParkinT
ParkinT / uilabel_adjustable.rb
Created July 8, 2012 04:28
RubyMotion class to auto-size font for text in a multi-line UILabel
class UILabel_Adjustable
# Borrowed and modified the excellent example at http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/
# adapting it for RubyMotion
# This applies only to a multi-line label. You can use '.adjustsFontSizeToFitWidth = true' for a single-line label
# usage is:
# text = "It's bad luck to be superstitious"
# text_label = UILabel.alloc.initWithFrame([[20, 20], [70, 120]])
# text_label.numberOfLines = 0 # set 0 for word wrap
# text_label.lineBreakMode = UILineBreakModeWordWrap
@ParkinT
ParkinT / Rakefile
Last active October 7, 2015 07:18
RubyMotion Rakefile - improved workflow
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
# custom rake tasks
require '../raketasks/gemerator.rb'
desc "Open latest crash log"
task :log do
app = Motion::Project::App.config
@ParkinT
ParkinT / Collatz Random Number.md
Created August 12, 2012 16:44
Random Number generator using Collatz Conjecture

When I first uncovered Collatz conjecture it made perfect sense to me. You are simply dividing an even number in half until you reach one and, if the number is not even you coerce it to be so.

This created a flash of inspiration for me to devise this simple routine.

{This could be used as the basis of a program to prove the "unsolved problem" of whether Collatz conjecture applies to ALL numbers greater than one.}

@ParkinT
ParkinT / Article for RubySource.com
Last active December 24, 2015 01:19
"Nitrous.IO: Rails Development in the Cloud" article for RubySource.com (http://www.sitepoint.com/nitrous-io-rails-development-cloud/) Supporting code
Supporting code for "Nitrous.IO: Rails Development in the Cloud" which demonstrates Nitrous.io for Ruby on Rails development without regard to hardware or physical location.
Full article at http://www.sitepoint.com/nitrous-io-rails-development-cloud/
@ParkinT
ParkinT / JoeYourchisin.pdf
Last active December 28, 2015 06:49
The purpose of a Resume is to demonstrate skill, experience and ability to fill the required role. A software developer should demonstrate skill and experience with the Tools of The Trade.Additionally, a Highly-Creative software developer (read: me) will find a unique and endearing way to present himself; further illustrating the desirable skill…
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
print 'Github Username: '
username = gets.chomp
# get gists
puts 'Downloading gists list'
gists_str = open("https://api.github.com/users/#{username}/gists").read