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
| f_data(){ | |
| tail -n $(expr $(wc -l $BASH_SOURCE | cut -d " " -f 1) - $(grep -ne '#\sDATA' $BASH_SOURCE|cut -d ":" -f 1)) $BASH_SOURCE | |
| } | |
| f_data | |
| # DATA | |
| # test data 1 | |
| # test data 2 | |
| # test data 3 |
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' | |
| puts <<desc | |
| Read the String | |
| Ruby: File.read | |
| Unix: cat | |
| desc | |
| Benchmark.bm do |bmark| | |
| bmark.report(:ruby) do |
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 MySexyClass | |
| def self.this_is_a_class_method | |
| "class method called" | |
| end | |
| def this_is_an_instance_method | |
| "instance method called" | |
| 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
| require 'jsondiff' # https://github.com/francois2metz/jsondiff | |
| require 'json/patch' # https://github.com/guillec/json-patch | |
| def test_1 | |
| hash_1 = {a: {b:"sexy key"}, c: [1,2,3], x: "gonna remove this one"} | |
| json_1 = JSON.generate(hash_1) | |
| hash_2 = {a: {b:"new key", b2: "sexier key"}, c: [2,3,4], d: "a new key entirely"} | |
| json_2 = JSON.generate(hash_2) |
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(recursive_functions). | |
| -export([ | |
| factorial/1, | |
| tail_fac/1, | |
| tail_fac/2, | |
| recursive_length/1, | |
| tail_len/1, | |
| tail_len/2, | |
| duplicate/2, | |
| tail_duplicate/2, |
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 AppConfig < ActiveRecord::Base # Or whatever, its a model | |
| attr_accessible :homepage_template, :connection_password, :i_dunno_whatever | |
| # bear with me, its all pseudo code | |
| validates :homepage_template, :presence => true, :inclusion => { :in => MagicalTemplateHelper.homepage_templates } | |
| validates_presence_of :connection_password | |
| # settings for arbitrary shit we need to set | |
| # these are way hard to validate | |
| # and require a lot of conditional b/s |
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
| #!/usr/bin/env ruby | |
| # I use this on Crunchbang and xubuntu systems. | |
| # May need to be modified depending on availability of notify-send as well as icons | |
| def time | |
| sleep 300 | |
| end | |
| def notify(urgency, icon, title, message) | |
| `notify-send -u #{urgency} -i #{icon} '#{title}' '#{message}'` |
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.9.3p385 :001 > $a = @a = A = a = "ah" | |
| => "ah" | |
| 1.9.3p385 :002 > "#$a #{$a} $a" | |
| => "ah ah $a" | |
| 1.9.3p385 :003 > "#@a #{@a} @a" | |
| => "ah ah @a" | |
| 1.9.3p385 :004 > "#A #{A} A" | |
| => "#A ah A" | |
| 1.9.3p385 :005 > "#a #{a} a" | |
| => "#a ah 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 'json' | |
| class Tracker | |
| def procs | |
| [ | |
| Proc.new { |i| i ** -3 }, | |
| Proc.new { |i| i ** -2 }, | |
| Proc.new { |i| i ** -1 }, | |
| Proc.new { |i| i ** 0 }, | |
| Proc.new { |i| i ** 1 }, | |
| Proc.new { |i| i ** 2 }, |
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 'rubygems' | |
| require 'net/ssh' | |
| # Run this on the machine (node) which needs to tunnel out to forward the UI to the remote system (console) | |
| Net::SSH.start("remote_host", "remote_user") do |ssh| | |
| # since we are running sinatra locally we will forward 43210 on the remote_host to our localhost 4567 | |
| # This is effectively the same as: | |
| # ssh -R 4567:localhost:43210 remote_user@remote_host | |
| ssh.forward.remote(4567, "localhost", 43210) | |
| ssh.loop { true } |