Skip to content

Instantly share code, notes, and snippets.

View edouard's full-sized avatar

Edouard Brière edouard

View GitHub Profile
@edouard
edouard / script.rb
Created October 30, 2012 09:52
Create a Gettext .po file containing all untranslated strings in a WebTranslateIt project
# before using: gem install web_translate_it
require 'web_translate_it'
file = File.new("pt.po", "w")
api_key = 'your_api_key'
WebTranslateIt::Connection.new(api_key) do
puts "Fetching all untranslated PT strings in project..."
WebTranslateIt::String.find_all({ :status => 'to_translate', :locale => 'pt' }).each do |string|
file.puts "msgid \"#{string.key}\"\n"
@edouard
edouard / yml.rb
Created August 8, 2012 07:17
Output a WebTranslateIt project’s translations to a .yml file
# before using: gem install web_translate_it
require 'web_translate_it'
file = File.new("fr.yml", "w")
file.puts "fr:\n"
WebTranslateIt::Connection.new('api_key') do
puts "Fetching all strings in project..."
WebTranslateIt::String.find_all.each do |string|
@edouard
edouard / csv.rb
Created July 27, 2012 07:51
Output a WebTranslateIt project’s translations to a .csv file
# before using: gem install web_translate_it
require 'web_translate_it'
file = File.new("my_file.csv", "w")
locales = %w{en fr de it ru sv}
file.puts "key," + locales.join(",")
WebTranslateIt::Connection.new('api_key') do
@edouard
edouard / strings.rb
Created June 6, 2012 09:55
This ruby script will pull all your strings from WebTranslateIt.com and format them under the Apple .strings format
# This ruby script will pull all your strings from WebTranslateIt.com
# and format them under the Apple .strings format
# beforehand: `gem install web_translate_it`
# make sure you’re using the version 2.0.2 which implements pagination on `String.find_all`
require 'web_translate_it'
api_key = 'sekret'
WebTranslateIt::Connection.new(api_key) do
@edouard
edouard / example.rb
Created April 12, 2012 13:31
Example code to create and get strings on WebTranslateIt to translate a Product database
require 'web_translate_it'
# create a KeepAlive HTTPS connection to WebTranslateIt.com
WebTranslateIt::Connection.new('secret_api_key') do
# create translations
translation_en = WebTranslateIt::Translation.new({ :locale => "en", :text => "Hello" })
translation_fr = WebTranslateIt::Translation.new({ :locale => "fr", :text => "Bonjour" })
# create a new segment
string = WebTranslateIt::String.new({ :key => "Greetings", :translations => [translation_en, translation_fr]})
# and save
@edouard
edouard / dominant_colors.rb
Created February 10, 2012 08:53
A ruby script to get the most dominant colours in an image (uses ImageMagick)
require 'RMagick'
TOP_N = 10 # Number of swatches
# Create a 1-row image that has a column for every color in the quantized
# image. The columns are sorted decreasing frequency of appearance in the
# quantized image.
def sort_by_decreasing_frequency(img)
hist = img.color_histogram
# sort by decreasing frequency
# change postgresql template1 db encoding to utf8 (unicode) by dropping it and recreating from template0
UPDATE pg_database SET datistemplate=false WHERE datname='template1';
drop database template1;
create database template1 with template = template0 encoding = 'UTF8';
UPDATE pg_database SET datistemplate=true WHERE datname='template1';
# this is the sphinx.yml file I use for webtranslateit.com
# It has been tested with latin languages, Chinese, Japanese, Korean and Russian
development:
enable_star: true
min_prefix_len: 1
min_word_len: 1
ngram_len: 1
ngram_chars: "U+00C6->U+00E6, U+01E2->U+00E6, U+01E3->U+00E6, U+01FC->U+00E6, \\\n \
U+01FD->U+00E6, U+1D01->U+00E6, U+1D02->U+00E6, U+1D2D->U+00E6, U+1D46->U+00E6, U+00E6, U+0622->U+0627, U+0623->U+0627, U+0624->U+0648, U+0625->U+0627, U+0626->U+064A, U+06C0->U+06D5, U+06C2->U+06C1, U+06D3->U+06D2, U+FB50->U+0671, U+FB51->U+0671, U+FB52->U+067B, \\\n \
# in /etc/munin/munin.conf
contacts campfire
contact.campfire.command | /web/scripts/alerts /web/scripts/alerts
contact.campfire.always_send warning critical
@edouard
edouard / god.rb
Created September 22, 2009 23:49 — forked from defunkt/god.rb
rails_root = "/data/github/current"
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{rails_root}/Rakefile production jobs:work"
w.uid = 'git'