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 |
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
#!/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 |
⊙﹏⊙ |
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 | |
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 |
# 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 |
class Invitation < RedisDataMapper | |
key_property :mail | |
key_property :type | |
key_format -> { |attrs| "invitation:#{attrs[:type]}#{attrs[:mail]}" } | |
property :token | |
property :mail_sent | |
property :accepted |
class Article | |
include Neo4j::ActiveNode | |
include IdPropertyWithRetry | |
id_property :uuid, on: :id_builder, retry: 3 | |
def id_builder | |
SecureRandom.urlsafe_base64(8) | |
end | |
end |
// Add this to favourites, prefixing this with "javascript:"" | |
window.open(encodeURI("https://github.com/:NAME/:REPO/issues/new?body=\n\n----\nRefers to " + window.location.href)) |