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 Dryer = Struct.new(:file_path, :super_class, :blk) do | |
def self.def_class(file_path, super_class=Object, &blk) | |
new(file_path, super_class, blk).def_class | |
end | |
def def_class | |
constant_names.each.with_index.inject(Object) do |const, (next_const, index)| | |
if constant_names.length == index + 1 |
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
# boring var technique | |
x = nil | |
[1,2,3,4].each do |y| | |
if x | |
puts x + y | |
end | |
x = y | |
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 address_method(city: "Bloomington", state: "IN", street: "123 fake st") | |
print x,y,z,"\n" | |
end | |
input = {city: "Indianapolis", street: "321 faux st", zip: "12345"} | |
address_method(input_address) # => ArgumentError: unknown keyword: zip | |
addr_mthd = method(:address_method) | |
acceptable_keywords = addr_mthd.parameters.select{|p| p[0] == :key}.map(&:last) |
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/ruby | |
# | |
# Most of this taken from here: https://gist.github.com/jmazzi/436947 | |
require 'csv' | |
require 'pathname' | |
# CHANGE THIS | |
input_file = Pathname("PATH/TO/CSV").expand_path | |
output_file = Pathname("~/pwds.xml").expand_path |
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
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' |
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 Proc | |
def <<(*args) | |
args = args.flatten if args.count == 1 | |
-> (*items) { self.call(*items, *args) } | |
end | |
end | |
adder = -> (*args) { args.inject(&:+) } | |
puts [1,2,3,4,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
>> RUST_BACKTRACE=1 cargo run > log.txt | |
Compiling serde v1.0.43 | |
Compiling core-foundation-sys v0.5.1 | |
Compiling regex-syntax v0.5.5 | |
Compiling walkdir v2.1.4 | |
Compiling base64 v0.9.1 | |
Compiling proc-macro2 v0.3.8 | |
Compiling num-traits v0.1.43 | |
Compiling rand v0.4.2 | |
Compiling net2 v0.2.32 |
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
mysql> create temporary table tmp (d INT(11)); | |
Query OK, 0 rows affected (0.02 sec) | |
/* there are 2 rows being inserted with value of 1 */ | |
mysql> insert into tmp (d) values (1), (2), (1), (3); | |
Query OK, 4 rows affected (0.01 sec) | |
/* this shows that distinct works */ | |
mysql> select distinct d from tmp; | |
+------+ |
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
ag ENV.*?[A-Z_]+ -o --no-filename | ag -o [A-Z_]+$ | sort | uniq |
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 set_env | |
around do |ex| | |
@old_env = ENV.to_h | |
yield ENV | |
ex.call | |
ENV.replace(ENV) | |
end | |
end | |