Skip to content

Instantly share code, notes, and snippets.

View wang-zhijun's full-sized avatar

WANG ZHIJUN wang-zhijun

  • Tokyo
View GitHub Profile
@archaelus
archaelus / interfaces.erl
Created September 28, 2011 06:53
Snippet to route addresses based on directly attached networks.
%% @copyright Geoff Cant
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version {@vsn}, {@date} {@time}
%% @doc Snippet to route addresses based on directly attached networks.
%% @end
-module(interfaces).
-export([route/1
,route/2
,routes/0
@cooldaemon
cooldaemon / sticky_write_vs_write.erl
Created April 6, 2012 16:46
Sticky Write Lock vs Write Lock.
-module(sticky_write_vs_write).
-author('cooldaemon@gmail.com').
-export([init_primary/0, init_secondary/0, run/3]).
-record(store, {key, value}).
init_primary() ->
{ok, _} = net_kernel:start(['primary@localhost', shortnames]),
true = erlang:set_cookie(node(), 'secret_cookie'),
@smpallen99
smpallen99 / constants.ex
Created April 5, 2014 18:22
Approach for constants shared between modules in Elixir
defmodule Constants do
@moduledoc """
An alternative to use @constant_name value approach to defined reusable
constants in elixir.
This module offers an approach to define these in a
module that can be shared with other modules. They are implemented with
macros so they can be used in guards and matches
## Examples:
@rushilgupta
rushilgupta / GoConcurrency.md
Last active July 11, 2024 12:52
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines