Skip to content

Instantly share code, notes, and snippets.

View fred's full-sized avatar

Frederico Araujo fred

  • Thailand
View GitHub Profile
@fred
fred / _search.html.haml
Created June 21, 2014 06:44
Activeadmin MongoID with Fulltext Search on Sidebar
/ file: app/views/admin/users/_search.html.haml
#panel_contents
= form_for(admin_users_path, method: :get) do |f|
.filter_form_field.filter_string
= label_tag :query, "Full Text Search"
= text_field_tag :query, params[:query], { placeholder: "Keyword to search" }
.buttons
= submit_tag "Search"
namespace :workers do
namespace :clockwork do
desc "Stop clockwork"
task :stop do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} stop"
end
end
@fred
fred / bashrc
Created March 18, 2014 05:44
show git branch in bash prompt, nicer bash prompt
# add to home .bashrc
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
safe_term=${TERM//[^[:alnum:]]/?}
match_lhs=""
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
@fred
fred / .gitconfig
Created February 28, 2014 05:08
my .gitconfig
[color]
branch = auto
diff = auto
status = auto
interactive = auto
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
/Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/rest-2.7.1/lib/rest/wrappers/base_wrapper.rb:21:in `rescue in post_file': HTTP 400 Error: In JSON, unexpected end of JSON input at position 0. (Rest::Wrappers::RestClientExceptionWrapper)
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/rest-2.7.1/lib/rest/wrappers/base_wrapper.rb:6:in `post_file'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/rest-2.7.1/lib/rest/client.rb:219:in `block in post_file'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/rest-2.7.1/lib/rest/client.rb:142:in `perform_op'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/rest-2.7.1/lib/rest/client.rb:218:in `post_file'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/iron_core-1.0.3/lib/iron_core/client.rb:258:in `post_file'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/iron_worker_ng-1.2.0/lib/iron_worker_ng/api_client.rb:43:in `codes_create'
from /Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/iron_worker_ng-1.2.0/lib/iron_worker_ng/client.rb:112:in `codes_create'
from /Users/fred/.rvm/ge
  • Zero downtime during upgrades and scaling out system (such as zero seconds downtime, while app still runs)

  • Highly Scalable with Terabytes of data with high performance and low cost with shards

  • Automatic Replica Set member take-over in case of failing primary, with automatic recovery for returning hosts.

  • Automatic promotion to primary and de promotion for any member of a replica set based on performance and latency.

  • Journaling, allows safe recovery in case of hard-disk failure.

  • Strong consistency, "Afford to loose data" in mongoDB is myth. Data is not lost, it's only not persisted due to failures on the developers code.

  • When Sharding is not feasible, different Documents (rails models) can be on different Replica sets (different database or set) altogether, since there are no joins in Mongo.

  • Background indexes.

@fred
fred / date_parse_thai.rb
Created January 28, 2014 07:53
Patching Date class to parse Thai Dates. It's very basic and raw. Date.parse_thai(string)
# Example:
# > Date.parse_thai '20 ม.ค. 2557'
# => Mon, 20 Jan 2014
# > Date.parse_thai '20 ม.ค. 2554'
# => Thu, 20 Jan 2011
# > Date.parse_thai "26 ก.พ. 2556"
# => Tue, 26 Feb 2013
# > Date.parse_thai "26 กรกฎาคม 2556"
# => Fri, 26 Jul 2013
# > Date.parse_thai "กรกฎาคม 14, 2556"
@fred
fred / gist:6433475
Created September 4, 2013 06:47
publishing keen.io with celluloid
# lib/models/keen_publisher.rb
require 'celluloid'
class KeenPublisher
include Celluloid
def initialize(name, status)
@name = name
@status = status
end
def publish
Keen.publish(@name, @status)
@fred
fred / gist:6248817
Created August 16, 2013 10:28
ruby script to clone/copy Iron IO cache (using celluloid pool)
require 'celluloid'
class IronQueueWorker
include Celluloid
def initialize
@token = "your-token"
@old_project_id = "source-project-id"
@new_project_id = "source-project-id"
@old_iron_cache = IronCache::Client.new(token: @token, project_id: @old_project_id)
@new_iron_cache = IronCache::Client.new(token: @token, project_id: @new_project_id)
@fred
fred / .gitconfig
Created August 11, 2013 15:19
my nice .gitconfig, to put on your home directory
[color]
branch = auto
diff = auto
status = auto
interactive = auto
ui = auto
[color "branch"]
current = yellow reverse
local = yellow