Skip to content

Instantly share code, notes, and snippets.

View benjamintanweihao's full-sized avatar

Benjamin Tan Wei Hao benjamintanweihao

View GitHub Profile
@benjamintanweihao
benjamintanweihao / fib.exs
Created June 20, 2013 16:25
Fibonacci Server in Elixir
import Enum
defmodule FibSolver do
def fib(scheduler) do
# This will send to the scheduler a ready message
# once its done calculating. Notice the call to
# fib(scheduler) which will invoke this line of
# code again.
scheduler <- { :ready, self }
require 'bundler/capistrano'
require 'capistrano-unicorn'
require 'sidekiq/capistrano'
require 'whenever/capistrano'
load 'config/recipes/base'
load 'config/recipes/cache'
load 'config/recipes/postgresql'
load 'config/recipes/redis'
load 'config/recipes/rails'
load 'config/recipes/seed'
require "redis"
root = "/home/deployer/apps/qs/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.qs.sock"
worker_processes 7
command finished in 60385ms
* executing "ls -1 /home/deployer/apps/qs/shared/assets/manifest* | wc -l"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 941ms
* executing "ls /home/deployer/apps/qs/shared/assets/manifest*"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 1413ms
* executing "ls -x /home/deployer/apps/qs/releases"

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh root@123.123.123.123

Add ssh fingerprint and enter password provided in email

defmodule Chat.Client do
# In all of the following functions 'server' stands for the server's pid
def join(server) do
send server, :join
end
def say(server, message) do
send server, { :say, message }
end
@benjamintanweihao
benjamintanweihao / crawler.erl
Created September 13, 2013 02:10
Some crawler stolen from some place.
-module(download).
-compile(export_all).
%%
%% Include files
%%
%%
%% Exported Functions
%%
#!/bin/bash
set -ex
BUILD_ENV=$1
rm -Rf public
mkdir -p public/styles
function bower_components() {
init([]) ->
Element = {sc_element, {sc_element, start_link, []},
temporary, brutal_kill, worker, [sc_element]},
Children = [Element],
RestartStrategy = {simple_one_for_one, 0, 1},
{ok, {RestartStrategy, Children}}.
defmodule Ring do
def run(member_count, loop_count, message) do
log(:ringleader, "building ring with #{ member_count - 1 } more nodes...")
next_pid = spawn_link(__MODULE__, :build_ring, [member_count - 2, self])
log(:ringleader, "sending initial message to #{ inspect(next_pid) }...")
next_pid <- {:message, message, loop_count}
message_loop(next_pid)
end