This file contains 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
# frozen_string_literal: true | |
# rubocop:disable Style/GlobalVars | |
$CPU = 4 | |
$chruby_version = '0.3.9' | |
$ruby_install_version = '0.7.0' | |
$default_ruby_version = '2.7.1' | |
$ruby_versions = %w[ |
This file contains 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 | |
require 'ostruct' | |
class LinuxProcess < OpenStruct | |
def initialize(args) | |
super | |
read_status! | |
end |
This file contains 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/ruby | |
require 'zlib' | |
require 'stringio' | |
require 'oj' | |
puts ARGV.inspect | |
Dir.chdir(ARGV[0]) | |
def idling_unicorn?(line) |
This file contains 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
/********************************************************************** | |
gc.c - | |
$Author$ | |
$Date$ | |
created at: Tue Oct 5 09:44:46 JST 1993 | |
Copyright (C) 1993-2003 Yukihiro Matsumoto | |
Copyright (C) 2000 Network Applied Communication Laboratory, Inc. | |
Copyright (C) 2000 Information-technology Promotion Agency, Japan | |
**********************************************************************/ |
This file contains 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 level(hash, index) | |
if level == 1 | |
return if block_given? | |
yield hash.values | |
else | |
hash.values | |
end | |
end | |
# or hash.values.reduce(Set.new) .... | |
hash.values.map { |subhash| level(subhash, index-1) }.flatten.uniq |
This file contains 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
h1 = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }.with_indifferent_access | |
h2 = h1.dup | |
h1['x']['y']['a'] = 5 | |
h1['x']['y']['arr'] = [1,2,3] | |
h2['x']['y']['arr'] = [2,3,4] | |
h1['h'] = [1,2] | |
h2['f'] = [3,4] | |
h1.deep_merge!(h2) { |key, old_value, new_value| (Array(old_value) + Array(new_value)).uniq } |
This file contains 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 X | |
attr_accessor :x | |
def f | |
self.x = 2 | |
if false | |
# try commenting out x=0 to see what happens. | |
x = 0 | |
end |
This file contains 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 Maybe | |
def initialize(item, &block) | |
@item = item | |
@block = block || proc { |item| !item.nil? } | |
end | |
def just | |
yield(@item) if @block.call(@item) | |
end | |
end | |
Maybe.new(5).just { |x| puts x } |
This file contains 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 'active_record' | |
require 'sqlite3' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: ':memory:' | |
) | |
ActiveRecord::Schema.define do |
This file contains 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_column_in_tables(filter) | |
tables = ActiveRecord::Base.connection.tables.map { |tname| tname.singularize.camelize.constantize rescue nil }.compact | |
column_names_by_table = tables.reduce({}) { |hash, table| hash.merge( table.name => table.column_names ) } | |
column_names_by_table.select { |key,value| value.any? { |column_name| column_name =~ filter } } | |
end |
NewerOlder