๐
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
| /sbin/ip route | grep 'docker' | grep -E '([\.0-9]{8,15}[^0]$)' -o |
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
| source 'https://rubygems.org' | |
| gem 'mini_magick' | |
| gem 'activesupport' |
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
| " | |
| ^ # Assert position at the beginning of a line (at beginning of the string or after a line break character) (line feed) | |
| \\d # Match a single character that is a โdigitโ (ASCII 0โ9 only) | |
| {4} # Exactly 4 times | |
| (?: # Match the regular expression below | |
| # Match this alternative (attempting the next alternative only if this one fails) | |
| # Match the regular expression below | |
| (?: # Match the regular expression below |
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 'drb/drb' | |
| main_pid = Process.pid | |
| f_proc_id = fork do | |
| puts "Started server fork with pid: #{Process.pid}, gpid: #{Process.getpgid(main_pid)}" | |
| class Front | |
| def initialize | |
| @global = [1,2,3,4] |
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
| # origin: http://thingsinabucket.com/2015/07/01/three_little_hacks/ | |
| module Digg | |
| def digg(*path) | |
| path.inject(self) do |memo, key| | |
| (memo.respond_to?(:[]) && (memo[key] || {})) || break | |
| end | |
| 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 'benchmark' | |
| a = ('a'..'zzzzz').to_a | |
| h = {} | |
| a.each {|e| h[e] = :ok} | |
| Benchmark.bmbm do |x| | |
| x.report("find z in array") { a.include? 'z' } | |
| x.report("find zz in array") { a.include? 'zz' } | |
| x.report("find zzz in array") { a.include? 'zzz' } |
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
| pids = [] | |
| (1..(ENV['CPUCORES'] || 3)).each do | |
| pids << fork do | |
| # do your stuff | |
| end | |
| end | |
| # hold your breath until all children finish |
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
| # Logic for forking connections | |
| # The forked process does not have access to static vars as far as I can discern, so I've done some stuff to check if the op threw an exception. | |
| def fork_with_new_connection | |
| # Store the ActiveRecord connection information | |
| config = ActiveRecord::Base.remove_connection | |
| pid = fork do | |
| # tracking if the op failed for the Process exit | |
| success = true |
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 safely | |
| begin | |
| unless ActiveRecord::Base.connected? | |
| ActiveRecord::Base.connection.verify!(0) | |
| end | |
| yield | |
| rescue => e | |
| status e.inspect | |
| ensure | |
| ActiveRecord::Base.connection_pool.release_connection |
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/ips' | |
| empty_array = [] | |
| small_array = [1] * 30 | |
| bigger_array = [1] * 300 | |
| Benchmark.ips do |x| | |
| x.report('empty !empty?') { !empty_array.empty? } | |
| x.report('small !empty?') { !small_array.empty? } | |
| x.report('bigger !empty?') { !bigger_array.empty? } |