Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥

Andrew Sullivan sllvn

🔥
View GitHub Profile
View knight-random-walk.rb
knight = Knight.new(0, 0)
memo = Array.new
1.upto(100000) do |x|
knight.move
knight.move until knight.position == [0, 0]
puts x if x % 100 == 0
memo << knight.count
knight.count = 0
end
View gist:3249355
import arcpy
from arcpy import env
env.workspace = "C:\UtahAddressModel\SouthJordan_July2012"
rows = arcpy.UpdateCursor("SJC_AddressPts")
for row in rows:
if row.getValue("TYPE") == "CHURCH":
row.setValue("TYPE_D", "REL")
View gist:3267523
self.dateFormat = [[NSDateFormatter alloc] init];
[self.dateFormat setDateFormat:@"d MMMM YYYY"];
NSLog(@"now formatted = %@", [self.dateFormat dateFromString:@"5 August 2012"]);
View gist:4519904
p() { cd ~/projects/$1; }
_p() { _files -W ~/projects -/; }
compdef _p p
View contract.rb
class Contract < ActiveRecord::Base
belongs_to :contract_type
has_many :contract_terms
def display_name
"#{self.contract_type.name}: #{self.person_name}"
end
def person_name
# todo: this seems inefficient, do we want to throw important metadata in the
View contract.rb
class Contract < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :contract_type
has_many :contract_terms
def display_name
"#{self.contract_type.name}: #{self.person_name}"
end
View gist:4693484
def display_name
name = self.name
name = "N/A" if name.blank? or name.nil?
name
end
View gist:4726304
[83] pry(main)> reader.objects[2].instance_of? Hash
=> true
[84] pry(main)> reader.objects.select { |x| x.instance_of? Hash }
=> []
View cardioActivities.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
Date,Type,Route Name,Distance (mi),Duration,Average Pace,Average Speed (mph),Calories Burned,Climb (ft),Average Heart Rate (bpm),Notes,GPX File
2013-01-31 20:20:00,Running,,4.00,0:37:00,9:15,6.49,615.0,,,"4.0 @ 6.5, easiest 4 miles I've run yet. Didn't feel like running, but after first mile, pace was easy.",
2013-01-29 19:00:00,Running,,2.75,0:25:30,9:16,6.47,423.0,,,"2.75 @ 6.5",
2013-01-28 18:00:00,Running,,4.25,0:41:50,9:51,6.10,658.0,,,"1.25 @ 6.8, 0.25 @ 3.5, 1.25 @ 6.8, 0.25 @ 3.5, 1.25 @ 6.8",
2013-01-25 19:00:00,Running,,4.25,0:43:30,10:14,5.86,662.0,,,"2.5 @ 6.5, 0.25 @ 3.5, 0.75 @ 6.5, 0.25 @ 3.5, 0.5 @ 6.5",
2013-01-23 18:00:00,Running,,3.00,0:31:00,10:20,5.81,469.0,,,"1 @ 6.5, 0.25 @ 3.5, 1 @ 6.5, 0.25 @ 3.5, 0.5 @ 7.3",
2013-01-20 12:30:00,Running,,4.50,0:45:30,10:07,5.93,699.0,,,"1.25 @ 6.5, 0.25 @ 3.5, 1.25 @ 6.5, 0.25 @ 3.5, 1.5 @ 6.5",
2013-01-13 18:00:00,Running,,1.75,0:18:00,10:17,5.83,273.0,,,"Left shin pain cut run short.",
2013-01-10 12:40:00,Cycling,,2.90,0:10:00,3:27,17.40,207.0,,,"Co
View sort_routes.rb
unsorted = %w{11 17 2 200 201 205 209 21 213 217 218 220 223 227 228 232 240 248 2X 3 307 313 320 33 35 354 35M 39 41 45 451 453 454 455 456 460 461 462 463 47 470 471 472 473 477 500 501 509 513 516 517 519 520 523 525 527 534 54 550 6 603 604 606 608 612 613 616 62 625 626 627 630 640 645 667 670 675 701 703 704 72 750 805 806 807 809 811 821 822 830 831 832 833 834 836 842 850 853 862 880 9 901 902 919 920 951 952 954 960 962 990 992 F400 F401 F514 F518 F546 F547 F556 F570 F578 F590 F618 F628 F638 F868 F94}
sorted = %w{2 2X 3 6 9 11 17 21 33 35 35M 39 41 45 47 54 62 72 200 201 205 209 213 217 218 220 223 227 228 232 240 248 307 313 320 354 451 453 454 455 456 460 461 462 463 470 471 472 473 477 500 501 509 513 516 517 519 520 523 525 527 534 550 603 604 606 608 612 613 616 625 626 627 630 640 645 667 670 675 701 703 704 750 805 806 807 809 811 821 822 830 831 832 833 834 836 842 850 853 862 880 901 902 919 920 951 952 954 960 962 990 992 F400 F401 F514 F518 F546 F547 F556 F570 F578 F590 F618 F628 F638 F868