Friday, October 21, 2016

Elixer style pipes in ruby.

Pipes that are like mappings can already be reproduced in Ruby using the map method. Elixer allows you to treat the item as the first argument of a function call. This is an experiment with inserting arguments into procs.
 
class Proc
  def <<(*args)
    -> (*items) { self.call(*items, *args) }
  end
end

adder = -> (*args) { args.inject(&:+) }

puts [1,2,3,4,5]
  .map(&adder << 1)
  .map(&adder.<<(10, 100)).inspect 
 
A more Elixer style chain with class methods by monkey patching the Method class.
 
class Method
  def <<(*args)
    -> (*items) { self.call(*items, *args) }
  end
end

class Mathx
  def self.product(*args)
    args.inject(&:*)
  end

  def self.division(*args)
    args.inject(&:/)
  end
end

puts [1,2,3,4,5]
  .map(&Mathx.method(:product) << 4)
  .map(&Mathx.method(:division) << 2).inspect

Friday, January 29, 2016

Dashlane to KeePassX on OSX

KeePassX-2.0 is missing a lot of nice features on OSX, such as importing xml or csv files. Here is how to get around this ommission.

Open Dashlane and click File -> Export -> Unsecured CSV

Save the CSV

Run this ruby script to generate a KeePass0.4 compatible xml file.
https://gist.github.com/kwstannard/6135f77608690c51d0c3

Download KeePassX-0.4.3.dmg from here:
https://www.keepassx.org/releases/

Open KeePassX-0.4.3 and click File -> Import -> From XML

Select ~/pwds.xml to import

Enter a password for this imported DB. You should see your passwords in KeePassX-0.4.3

Save the imported database and close KeePassX-0.4.3. Remember where you saved it.

Open KeePassX-2.0 and click Database -> Import KeePass 1 database

Select the database that you just saved.

Use the same password as above to open the DB. You should now have your passwords in KeePassX-2.0

*** Delete the CSV, XML, and kdb files! ***