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
@kwstannard
kwstannard / foo.md
Last active December 27, 2015 11:48

old view

<%= select_for_tag :name,
  options_for_select(complex.stuff.collect{|d| d.stuff} + ['other', 'stuff']) %>

new view

<%= select_for_tag :name,
  options_for_select(complex.stuff.collect{|d| d.stuff} + admin_selection_choices(user) + ['other', 'stuff']) %>
@kwstannard
kwstannard / blockComments.vim
Created February 26, 2013 15:44
common line block commenting
" block select commenting & uncommenting
au BufEnter *.rb map ,c :s/^/#/<CR>:nohlsearch<CR>
au BufEnter *.rb map ,u :s/^#//<CR>:nohlsearch<CR>
au BufEnter *.vim* map ,c :s/^/"/<CR>:nohlsearch<CR>
au BufEnter *.vim* map ,u :s/^"//<CR>:nohlsearch<CR>
au BufEnter *.haml* map ,c :s/^/-#/<CR>:nohlsearch<CR>
au BufEnter *.haml* map ,u :s/^-#//<CR>:nohlsearch<CR>
@kwstannard
kwstannard / IndentHighlighting.vim
Created February 25, 2013 23:13
Indent highlighting
let indent_colors = ['#645640','#564832','#484024','#646452','#565644','#484834','#565656','#484848','#404040']
let indent = 8
for icolor in indent_colors
let indent_name = 'Indent' . indent
exec 'highlight ' . indent_name . ' guibg=' . icolor
au bufwinenter * call matchadd(indent_name, '^\s\{' . (indent * 2 + 4) . '}\&^\s\{' . (indent * 2 + 1) . '}', 200-indent)
let indent -= 1
endfor
@kwstannard
kwstannard / LongLineHighlight
Created February 25, 2013 16:08
VIM long line highlighting
highlight LongLines guibg=#333300
au BufWinEnter * call matchadd('LongLines', '^.\{80,119}$', -1)
highlight VeryLongLines guibg=#330000
au BufWinEnter * call matchadd('VeryLongLines', '^.\{120,}$', -1)
@kwstannard
kwstannard / gist:5030824
Last active December 14, 2015 04:49
vimrc relative numbering. Leaves relative numbering on loss of focus and on entering insert mode. Re-enters when appropriate.
set relativenumber
au InsertEnter * :set number
au InsertLeave * :set relativenumber
function! FocusGainNumbering()
if(mode() == 'i')
:set number
else
:set relativenumber
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
arg = `echo $COUNT_CALLS_TO`
KLASS, METHOD = *arg.split('#').map(&:strip)
module MethodCounter
module ClassMethods
@@method_times_run_var = 0
def method_times_called
@@method_times_run_var
end