Convert a ruby hash to dotted path
def hash_to_dotted_path(hash, path = "")
hash.each_with_object({}) do |(k, v), ret|
key = path + k.to_s
if v.is_a? Hash
ret.merge! hash_to_dotted_path(v, key.to_s + ".")
else| class Invitation < RedisDataMapper | |
| key_property :mail | |
| key_property :type | |
| key_format -> { |attrs| "invitation:#{attrs[:type]}#{attrs[:mail]}" } | |
| property :token | |
| property :mail_sent | |
| property :accepted |
| # Rename games.filters.* to games_sections.* | |
| i18n-tasks data -f yaml | i18n-tasks tree-filter games.filters.* | i18n-tasks tree-rename-key *.games games_sections | i18n-tasks data-merge | |
| # Remove games.filters.* | |
| i18n-tasks data -f yaml | i18n-tasks tree-filter games.filters.* | i18n-tasks data-remove | |
| # Adds a new tree | |
| echo 'en.my.new.tree' | i18n-tasks tree-convert -f keys -t yaml | i18n-tasks tree-set-value Hello | i18n-tasks data-merge |
| #!/usr/bin/env bash | |
| if [[ $1 == 'words' ]]; then | |
| git diff --color-words="[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+" | |
| elif [[ $1 == 'nospace' ]]; then | |
| git diff --color-words=. | |
| else | |
| git diff --color-words | |
| fi |
| class Object | |
| def dig(*methods) | |
| output = self | |
| methods.each { |method| output = output&.public_send(method) } | |
| output | |
| end | |
| end | |
| class MyClass | |
| attr_accessor :some_attribute |
| ⊙﹏⊙ |
| #!/usr/bin/env bash | |
| # | |
| # Usage: | |
| # $ video2gif.sh in.avi out.gif [width] | |
| # | |
| # Based on http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html | |
| size=$3 | |
| if [ -z $size ]; then | |
| size=320 |
Convert a ruby hash to dotted path
def hash_to_dotted_path(hash, path = "")
hash.each_with_object({}) do |(k, v), ret|
key = path + k.to_s
if v.is_a? Hash
ret.merge! hash_to_dotted_path(v, key.to_s + ".")
else| class HashToDottedPath | |
| def initialize(hash) | |
| @hash = hash | |
| end | |
| def to_dotted_path | |
| result = [] | |
| @hash.each do |k, v| | |
| explore_keys(v, [k], result) | |
| end |
| class Tree | |
| attr_reader :data | |
| def initialize(data) | |
| @data = data | |
| end | |
| def +(other) | |
| Tree.new(deep_merge(@data, other.is_a?(Tree) ? other.data : other)) | |
| end |
| #!/usr/bin/env bash | |
| origin_raw_folder="raw_images" | |
| rm -rf images | |
| mkdir -p images/iphone | |
| mkdir -p images/android/res-hdpi | |
| mkdir -p images/android/res-hdpi | |
| mkdir -p images/android/res-xhdpi | |
| mkdir -p images/android/res-xxhdpi |