Skip to content

Instantly share code, notes, and snippets.

@ProGM
ProGM / invitation.rb
Last active March 29, 2016 10:02
An example "orm" for redis.
class Invitation < RedisDataMapper
key_property :mail
key_property :type
key_format -> { |attrs| "invitation:#{attrs[:type]}#{attrs[:mail]}" }
property :token
property :mail_sent
property :accepted
@ProGM
ProGM / i18n-tasks-snippets.sh
Last active April 12, 2016 20:16
A set of i18n-tasks snippets.
# 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
@ProGM
ProGM / diff-words.sh
Created March 29, 2016 10:01
A script to run git-diff per character/words.
#!/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
@ProGM
ProGM / dig_for_objects.rb
Created April 14, 2016 11:41
An implementation for `dig` method for generic objects.
class Object
def dig(*methods)
output = self
methods.each { |method| output = output&.public_send(method) }
output
end
end
class MyClass
attr_accessor :some_attribute
@ProGM
ProGM / video2gif.sh
Last active June 7, 2016 08:41
A script to create a gif from a video!
#!/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
@ProGM
ProGM / hash_to_dotted_path.rb
Created July 1, 2016 15:38
Hash to Dotted Path
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
@ProGM
ProGM / prepare_images_for_appcelerator.sh
Created August 25, 2016 13:49
Prepare and resize images for Appcelerator using imagemagick
#!/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