This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jruby-1.6.7 :002 > require 'json' | |
jruby-1.6.7 :007 > str = '{"field1": "test"}' | |
=> "{"field1": "test"}" | |
jruby-1.6.7 :008 > JSON.parse(str) | |
=> {"field1"=>"test"} | |
jruby-1.6.7 :009 > _.class.name | |
=> "Hash" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'benchmark' | |
require 'active_hash' | |
def test_array(size=10000) | |
[].tap do |array| | |
(1..size).each do |i| | |
array << { :id => i, :name => "#{i}_string", :text => "text"} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctrl+c: 2.0.0p0 :001 > /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:41:in `read_nonblock': closed stream (IOError) | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:41:in `block in read_fully' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:40:in `loop' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:40:in `read_fully' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/transport.rb:199:in `read_next_frame' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:696:in `init_connection' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:214:in `start' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:485:in `recover_from_network_failure' | |
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:462:in `handle_network_failure' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def publish(routing_key, message, properties = {}) | |
ensure_connection!(routing_key, message) | |
exchange = fetch_exchange(properties.delete(:exchange)) | |
non_overridable_properties = { | |
routing_key: routing_key, | |
timestamp: Time.now.to_i, | |
content_type: 'application/json' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'optparse' | |
FILE_NAME = 'VERSION.txt' | |
options = {} | |
def red(str); "\e[31m#{str}\e[0m"; end | |
def green(str); "\e[32m#{str}\e[0m"; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule CryptoApp.AccountSync do | |
use GenServer | |
@interval 1_000 | |
def start_link do | |
GenServer.start_link(__MODULE__, :ok, name: __MODULE__) | |
end | |
def init(:ok) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PopularApp.EmailSender do | |
use GenServer | |
def start_link do | |
GenServer.start_link(__MODULE__, :ok, name: __MODULE__) | |
end | |
def init(:ok) do | |
{:ok, %{last_sent: nil, last_data: nil}} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PopularApp.Application do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec | |
children = [ | |
worker(PopularApp.EmailSender, []) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.UserService do | |
def create_user(params) do | |
%App.User{} | |
|> App.User.changeset(params) | |
|> App.Repo.insert() | |
|> case do | |
{:ok, user} -> | |
Task.start(fn -> send_email_to_user(user) end) # 🎉 | |
{:ok, user} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule YourApp.Application do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec | |
children = [ | |
{Task.Supervisor, name: YourApp.AccountSetupSupervisor} | |
] |
OlderNewer