http://blog.bignerdranch.com/835-its-the-endian-of-the-world-as-we-know-it/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| def memstats | |
| size = `ps -o size= #{$$}`.strip.to_i | |
| end | |
| memstats #4900 | |
| CSV.open('visitors.csv', headers: true) do |csv| | |
| visitors = csv.each # Enumerator | |
| memstats # 5164 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def equi(arr) | |
| return 0 if arr.empty? | |
| left, right = 0, arr.inject{|sum, n| sum + n} | |
| equi_indices=[] | |
| arr.each_with_index do |val,i| | |
| left += val | |
| equi_indices << i if right == left |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TrafficLight | |
| class State | |
| def to_s | |
| name | |
| end | |
| def name | |
| self.class.name.split('::').last.downcase | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def Point(*args) | |
| respond_to_point = ->(arg){ arg.respond_to?(:to_point) } | |
| respond_to_ary = -> (arg){ arg.respond_to?(:to_ary) } | |
| case args.first | |
| when Integer then Point.new(*args) | |
| when String then Point.new(*args.first.split(':').map(&:to_i)) | |
| when respond_to_point | |
| args.first.to_point | |
| when respond_to_ary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| // Xcode_3_2_6/usr/bin/gcc -arch ppc -std=c99 -isysroot /Xcode_3_2_6/SDKs/MacOSX10.5.sdk -g -Wall -framework Foundation -o endian-ppc ~/Downloads/endian.m (thanks to Jeremy W. Sherman for the assist) | |
| // clang -arch x86_64 -g -Weverything -framework Foundation -o endian endian.m | |
| int main (void) { | |
| unsigned int values[] = { 1, 387, 8533937 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AuditLog | |
| def record(number, action, amount, balance) | |
| printf( | |
| "%<time>s #%<number>s %<action>s %<amount>.2f (%<balance>.2f)\n", | |
| time: Time.now, | |
| number: number, | |
| action: action, | |
| amount: amount / 100, | |
| balance: balance / 100) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <table> | |
| <thead> | |
| <tr> | |
| <th>Name</th> | |
| <th>Email></th> | |
| <th>Country</th> | |
| <th></th> | |
| </tr> | |
| </thead> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://martinfowler.com/articles/microservices.html |
$ cd `brew --prefix`
$ rm Library/<filename> (any file that shows up under git status as not being committed)
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew updateStackoverflow discussion: http://stackoverflow.com/questions/14113427/brew-update-failed