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 Fuse | |
| module Helper | |
| def self.run_later(run_context, &blk) | |
| run_context.ruby_block("Run-later #{SecureRandom.uuid}") do | |
| block &blk | |
| end | |
| 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
| class Colour | |
| attr_reader :red, :green, :blue | |
| def initialize(red, green, blue, maxval) | |
| @red, @green, @blue, @maxval = red, green, blue, maxval | |
| end | |
| def ansii_24 | |
| "\033[48;2;#{@red};#{@green};#{@blue}m \033[39;49m" | |
| 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
| class Port | |
| def initialize(slot, port_spec) | |
| @slot = slot | |
| @spec = port_spec | |
| end | |
| end | |
| class Slot | |
| def self.create(slot_spec) | |
| @spec = slot_spec |
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 modal(title, &body) | |
| capture do | |
| concat(render "shared/modal-header", title: tile) | |
| concat(capture(&body)) | |
| concat(render "shared/modal-footer") | |
| 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
| source = ["NewsArticle", "NewsArticle", "NewsArticle", "NewsArticle", "Event", "Event", "Tweet", "Tweet", "Event"] | |
| sorted = [] | |
| %w(NewsArticle Event Tweet).cycle do |current_type| | |
| sorted << source.delete_at(source.index(current_type)) if source.include?(current_type) | |
| break if source.empty? | |
| 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' | |
| hsh = {} | |
| 1000.times {|i| hsh[i.to_s] = i.succ.to_s} | |
| Benchmark.bm do |x| | |
| x.report("Hash[]") {1000.times{Hash[hsh.values.zip(hsh.keys)]}} | |
| x.report("invert") {1000.times{hsh.invert}} | |
| x.report("each_with_object") {1000.times{hsh.each_with_object({}){|(k,v),h| h[v] = k}}} | |
| 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
| the path /etc/sv/service_name/env contains the environment, in the form of files. The name of the file is the variable name, the contents are the variable's value, e.g. | |
| file: /etc/sv/service_name/env/RUBY_VERSION | |
| contents: 2.1.5 |
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
| input = [ | |
| ['a', 'b', 'c'], | |
| ['d', 'e'], | |
| ['c', 'e'], | |
| ['f', 'g'], | |
| ['g', 'j'] | |
| ] | |
| outputs = input.each_with_object([]) do |ary, output| | |
| merge_with = output.find_all{|o| (o & ary).size > 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
| def foo(&block) | |
| block = ->{"c"} | |
| p block.call | |
| p yield | |
| 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
| def find_equality_bases(a,b,max_base=100) | |
| a_parts = a.to_s.split("").map{|i| i.to_i(36)}.reverse | |
| b_parts = b.to_s.split("").map{|i| i.to_i(36)}.reverse | |
| a_start_base = a_parts.max + 1 | |
| b_start_base = b_parts.max + 1 | |
| if a == b | |
| return [start_base, start_base] | |
| end | |
| (a_start_base..max_base).each do |a_base| | |
| (b_start_base..max_base).each do |b_base| |