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
| # Blueprint for Installing Rails | |
| # ============================== | |
| # | |
| # Makes Ruby 2 and Rails 4 | |
| Ruby: | |
| RVM: | |
| - 'apt-get install curl' | |
| - 'curl -L https://get.rvm.io | bash' | |
| - 'rvm install 2.0' |
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
| function pk-install { | |
| url="$1" | |
| wget $url | |
| file_name=`echo $url | sed 's/^.*\/\(.*\)\.tar\.gz$/\1/'` | |
| tar -zxvf "$file_name.tar.gz" | |
| cd $file_name | |
| make && make install | |
| } |
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
| /\([+-]?((?=9)90(\.0+)?|[1-8]?\d(\.\d+)?), [+-]?((?=1\d{2})((?=18\d)180(\.0+)?|1[0-7]\d(\.\d+)?)|\d{2}(\.\d+)?)\)/ |
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
| [9] pry(main)> n = 1_000 | |
| => 1000 | |
| [10] pry(main)> Benchmark.bm { |bm| | |
| [10] pry(main)* bm.report { n.times { :foo }} | |
| [10] pry(main)* bm.report { n.times { 'foo'}} | |
| [10] pry(main)* } | |
| user system total real | |
| 0.000000 0.000000 0.000000 ( 0.000192) | |
| 0.000000 0.000000 0.000000 ( 0.000396) | |
| => [#<Benchmark::Tms:0x0000000263dfd8 |
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 my_function(n); n / 2; end | |
| prove x.will eq(5).when { x = my_function(10) } | |
| when { x = my_function(10) }.prove_that_it_will eq(5) | |
| my_context = ->{ x = my_function(10) } | |
| prove(x).will eq(5).when my_context |
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
| # Skyforge | |
| Forge mock objects for your test with immense power! This one is currently in development, | |
| and not close to being done. So what are we planning to do here? | |
| ## !!! THIS IS THEORETICAL, UNDER CONSTRUCTION !!! | |
| ## Trace | |
| Using Mockingjay, trace a ruby hash to make a generator for more objects like 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
| [1] pry(main)> hash = {a: 1, b: 2, c: 3} | |
| => {:a=>1, :b=>2, :c=>3} | |
| [2] pry(main)> class Hash | |
| [2] pry(main)* def retrieve_keys(*keys) | |
| [2] pry(main)* self.reduce({}) { |h, (k, v)| | |
| [2] pry(main)* keys.include?(k) ? h.merge!({k => v}) : h | |
| [2] pry(main)* } | |
| [2] pry(main)* end | |
| [2] pry(main)* end | |
| => nil |
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 prompt(name: '', matches: '') | |
| while true | |
| print "#{name}: "; answer = gets.chomp | |
| return answer if Array(matches).all? { |match| match === answer } | |
| puts "Invalid!" | |
| end | |
| 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
| # Playing off of my prompt idea, let's take it one step further: | |
| name = prompt for: 'Name', validate: { with: /\w+/, or: 'Invalid name given!' } | |
| # Where if given invalid input it will say: | |
| # Error: Invalid name given | |
| # Name: |
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
| module Kernel | |
| def defn name, &block | |
| define_method name, block | |
| end | |
| end |
OlderNewer