Skip to content

Instantly share code, notes, and snippets.

View kwstannard's full-sized avatar

Wolf kwstannard

  • Andros
  • New York City
View GitHub Profile
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
# boring var technique
x = nil
[1,2,3,4].each do |y|
if x
puts x + y
end
x = y
end
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)
@kwstannard
kwstannard / gist:6135f77608690c51d0c3
Created January 29, 2016 18:29
Dashlane csv to KeePass1 xml compatible format
#!/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
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'
@kwstannard
kwstannard / insert_args.rb
Last active October 21, 2016 19:06
equivalent to elixer pipe in ruby
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]
>> 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
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;
+------+
ag ENV.*?[A-Z_]+ -o --no-filename | ag -o [A-Z_]+$ | sort | uniq
def set_env
around do |ex|
@old_env = ENV.to_h
yield ENV
ex.call
ENV.replace(ENV)
end
end