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
| # Runs exec inside the fork in order to capture the output of the subprocess | |
| pid = fork { exec('ssh 127.0.0.1') } | |
| _, status = Process.waitpid2(pid) | |
| puts status.success? |
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
| exports.first = function(l) { | |
| return l[0] | |
| }; | |
| exports.rest = function(l) { | |
| return l.reduce(function(accumulator, item, index) { | |
| if(index > 0) { | |
| accumulator.push(item); | |
| } | |
| return accumulator; |
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 SafeStruct | |
| def self.with_attributes(params) | |
| params.keys.map do |key| | |
| define_method(key) do |&block| | |
| ivar = instance_variable_get("@#{key}".to_sym) | |
| if block && !ivar.nil? | |
| block.call(ivar) | |
| end | |
| ivar | |
| 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 'rspec' | |
| require 'person' | |
| describe "descendants" do | |
| it "returns all its descendants" do | |
| sonny = Person.new('Sonny') | |
| pa = Person.new('Pa', sonny) | |
| grandpa = Person.new('Grandpa', pa) | |
| expect(Person.all_descendants_of(grandpa).map(&:name)).to eq ['Pa', 'Sonny'] |
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 has_foo? | |
| ->(thing) { thing == "foo" } | |
| end | |
| def has_bar? | |
| ->(thing) { thing == "bar" } | |
| end | |
| def has_baz? | |
| ->(thing) { thing == "baz" } |
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
| # System time zone is set to 'Australia/Sydney' | |
| # | |
| Time.zone = "Europe/Madrid" | |
| => "Europe/Madrid" | |
| Timecop.freeze(Time.zone.now) | |
| => 2015-02-06 23:36:46 +1100 # The "frozen" time. +1100 is Australia/Sydney. Oh dear. | |
| Time.zone.now | |
| => Fri, 06 Feb 2015 13:36:46 CET +01:00 # The time here is for the configured Time.zone; Europe/Madrid +01:00 |
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
| backend insights { | |
| .host = "insights.example.com" | |
| .port = "3000"; | |
| } | |
| backend help { | |
| .host = "help.example.com" | |
| .port = "80"; | |
| } |
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 jquery | |
| #= require jquery_ujs | |
| #= require turbolinks | |
| #= require bootstrap | |
| # | |
| #= require require-config | |
| #= require requirejs/require | |
| #= require_tree . | |
| # | |
| define "jquery", -> window.jQuery |
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
| timestamp() { | |
| date -j -f "%Y-%m-%d%H:%M:%S" $* +%s | |
| } | |
| extract_time_field(){ | |
| echo $* | awk '{print $1$2}' | awk -F',' '{print $1}' | |
| } | |
| for logfile in `ls *.log`; do | |
| starttime=$(extract_time_field $(cat $logfile | head -n1)) |
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
| # target listens for connection | |
| nc -l <port> > /path/to/target/destination/file | |
| # host sends file | |
| nc <listener_ip> <port> < /path/to/source/file |