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 Rubage | |
| (def foo a, b, c | |
| puts a | |
| puts b | |
| puts c | |
| (puts a.gsub /A/, 'B') | |
| end) | |
| end | |
| (if $0 == __FILE__ |
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
| #!/bin/env ruby | |
| ENV['RAILS_ENV'] = 'production' | |
| require 'fileutils' | |
| def sudo(cmd, as = 'root') | |
| puts "sudo: #{cmd}" | |
| system("sudo -u #{as} #{cmd}") | |
| 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
| #include <iostream> | |
| template <int N> | |
| void pr(const std::string &msg) | |
| { | |
| std::cout << msg << std::endl; | |
| pr<N-1>(msg); // would be nice to do tail call optimization here... | |
| } | |
| template <> |
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 Foo | |
| class << self | |
| attr_accessor :a, :b | |
| end | |
| def self.register(args = {}) | |
| args.each do |k,v| | |
| self.send(:"#{k}=", v) | |
| 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
| Rehearsal ------------------------------------------------------ | |
| proc wrapped eval: 1.020000 0.030000 1.050000 ( 0.605000) | |
| instance_eval: 2.950000 0.030000 2.980000 ( 2.273000) | |
| --------------------------------------------- total: 4.030000sec | |
| user system total real | |
| proc wrapped eval: 0.200000 0.000000 0.200000 ( 0.204000) | |
| instance_eval: 1.800000 0.010000 1.810000 ( 1.767000) |
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
| #include <iostream> | |
| using namespace std; | |
| class A | |
| { | |
| public: | |
| virtual void Hello() { cout << "Hello from A" << endl; } | |
| virtual ~A() {} | |
| }; |
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 'benchmark' | |
| ordered_array = (0..10_000).map { |p| [p,p,p,p,p] }.flatten | |
| random_array = ordered_array.dup.shuffle | |
| Benchmark.bm do |b| | |
| b.report('index') do | |
| random_array.map { |n| ordered_array.index(n) } | |
| end |
OlderNewer