Skip to content

Instantly share code, notes, and snippets.

View sntran's full-sized avatar

Sơn Trần-Nguyễn sntran

View GitHub Profile
@sntran
sntran / elixir
Last active December 17, 2015 23:09
Dockerfile for Erlang container for Docker.IORename each of these to `Dockerfile` to build the imagedocker build -t="{imagename}" .docker run -i -t {imagename} /bin/bash
# Elixir on Erlang
#
# VERSION 0.13.2
FROM sntran/kerl
MAINTAINER Son Tran-Nguyen "me@sntran.com"
RUN apt-get install -y unzip
RUN mkdir -p /opt/erlang/elixir
RUN cd /opt/erlang/elixir && curl -L -O https://github.com/elixir-lang/elixir/releases/download/v0.13.2/Precompiled.zip && unzip Precompiled.zip
-module(helpers).
is_pid_alive(Pid) when node(Pid) =:= node() ->
is_process_alive(Pid);
is_pid_alive(Pid) ->
lists:member(node(Pid), nodes()) andalso
(rpc:call(node(Pid), erlang, is_process_alive, [Pid]) =:= true).
get_current_time() ->
Now = calendar:local_time(),
@sntran
sntran / index.html
Created September 20, 2013 13:32 — forked from roman01la/index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="viewport"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r58/three.min.js"></script>
<script src="//threejs.org/examples/js/controls/OrbitControls.js"></script>
@sntran
sntran / Gists.IO - Just Write It.md
Last active December 24, 2015 20:29
Gists.IO - Just Write It A simple Gist\-based blogging platform for those of us hacker to jolt down our thoughts without concerning about server setup.

As developer/hacker, we are all caught up in our projects, but some times we want to write. Write about our thought process, our ideas, our instructions to do certain thing, etc...

But we don't have time to set up a blog server. Other services are there but not many of them target us, the hackers. We want something simple, with ability to embed code, and not other fancy stuffs.

So we made this. What you can do are:

  • Author (create/edit/delete) an entry using Markdown
  • Attach code files and embed them inline
  • Revert back to previous version of the entry.
  • Use Emoji 👍
@sntran
sntran / Caching and Pagination.md
Last active December 25, 2015 03:49
Caching and Pagination When implementing the cache system for [Gists.IO](http://github.com/sntran/gists.io), we hit a wall with pagination. Mostly due to our lack of knowledge on caching, and the difference between our definition and GitHub's one on pagination. So let this entry be the rubber duck.

Lets talk about cache

Initially, we cache only individual gist using the key {:gist, gist_id, username} in which the first element of the tuple is the atom :gist to act as the tag, then the gist_id and the username of the owner of that gist.

When fetching for gists of a particular user, we perform a match on keys with pattern {:gist, :'$1', username} to retrieve all the cached gists by that username. All went well, or so we thought.

Lets talk about pagination

GitHub's API for fetching Gists will return a Link header when there are more results than the default per_page query, which is 30. The header has the following format when fetching gists for myself:

@sntran
sntran / New Entry.md
Last active December 27, 2015 06:49
New Entry

Ec ido metr decilitro, iz celo semajntago via. Jh volu punktokomo ies, nk plus stil neni hop, igi in tempo renkonten komplemento. Nura nenia centimetro vir co, tc pri loka stop konsonanto, go okej' predikato por. Plena daralbajdo fi veo, povi panjo tet ok, is pli vatto komparado komplemento. Ut alial altmontaro tri, nul uj falsa nekutima.

Gv ing falsa siatempe interogativo. Mili grado monatonomo ek san, jes liternomo difiniteco substantiva as, oni pere poezio frazparto en. Tio kelke samtempe ne, nf tet vira kaŭzo, an eks liva rilativo. Ehe disde aliom gentonomo at, meze alternativa hej in, hoj ng tiuj tempopunkto memkompreneble. Pra nu hago nette, unu titolo tagnokto prepozicio ba. Ador hebrea duobla anc ha, dev bo foren grupa ometr, al ore olog geto. Ali il alio miriametro suplemento.

Hot kontraŭa malebligi ul. Dura getto infra sep ki, cent lingvonomo tutampleksa avo ve, oz plej afro ont. Hura ometr mf fin. Geedzo ipsilono bo ien. Oni krome estiel subtraho tc. Tio ne apuda subjunkcio, en multe kr

@sntran
sntran / poker.erl
Created November 26, 2013 23:25
Peter Norvig's 5-card Poker hand evaluator, ported to Erlang.
%%%
%%% Peter Norvig's 5-card Poker hand evaluator, ported to Erlang.
%%%
-module(poker).
-export([hand_rank/1, sort_hands/1, winners/1]).
%% Return a list of the ranks, sorted with higher first.
%% Hand is a list of 2-char strings, i.e. ["6H","3D","AS","TH","JC"].
card_ranks(Hand) ->
#!/usr/local/bin/python2.7
#!/usr/local/bin/python2.7
# (Minimal) Perfect Hash Functions Generator (key, value) value in this code is the key counter during reading but can be any number
# implementing the MOS Algorithm II CACM92 , and Amjad M Daoud Thesis 1993 at VT;
# based on Steve Hanof implementation http://stevehanov.ca/blog/index.php?id=119.
# Download as http://iswsa.acm.org/mphf/mphf.py
@sntran
sntran / Interesting Erlang Repos.md
Created December 29, 2013 22:45
Interesting Erlang Repos From time to time, I came across some interesting repos when researching on Erlang. They are interesting in many ways, i.e., their purpose, their choice of libraries, and their way of handling the task.

Keybase proof

I hereby claim:

  • I am sntran on github.
  • I am sntran (https://keybase.io/sntran) on keybase.
  • I have a public key ASBcUAzxTk-x6WlcKCjLyc8hYXHZpLpInPoBAEJ20Z9M-wo

To claim this, I am signing this object: