Skip to content

Instantly share code, notes, and snippets.

View kwstannard's full-sized avatar

Wolf kwstannard

  • Andros
  • New York City
View GitHub Profile
@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
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)
# boring var technique
x = nil
[1,2,3,4].each do |y|
if x
puts x + y
end
x = y
end
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
# app/models/user.rb
Dryer.def_class(__FILE__) do
def hi
"hello world"
end
end
User.new.hi
=> "hello world"
=begin
This class allows you to condsolidate the declaration of class names into
the file name. It also handles namespacing based on the file path if you are
using Rails autoloading.
This works with the single exception of constant lookup via nesting, so you
will need to replace constants with variables and methods.
Examples:
### In file version
klass = Class.new do
def hi
puts 'hello'
end
end
name = __FILE__.slice(/\w*.rb$/).slice(/\w*/).camelcase
Object.const_set(name, klass)
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config modalEscapeKey esc
alias modal esc,ctrl
alias mt ${modal}:toggle
>> be vim
Your Ruby version is 2.2.3, but your Gemfile specified 2.1.7
Vim: Caught deadly signal SEGV
Vim: Finished.
Segmentation fault: 11
@kwstannard
kwstannard / infinite.rb
Created September 14, 2015 19:35
infinite enumerator
irb(main):008:0> x = Enumerator.new(Float::INFINITY) { yield 1 }
=> #<Enumerator: #<Enumerator::Generator:0x007f85531b6360>:each>
irb(main):009:0> x.size
=> Infinity