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 / fisherYates.coffee
Created January 31, 2012 02:09
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
# Refactored from git://gist.github.com/859699.git by ddgromit for swapping
fisherYates = (arr) ->
i = arr.length
if i is 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
[arr[i], arr[j]] = [arr[j], arr[i]] # use pattern matching to swap
@sntran
sntran / echo_client_example.py
Created April 10, 2012 04:18
Sample XMPP client on Sublime Text
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2010 Nathanael C. Fritz
This file is part of SleekXMPP.
See the file LICENSE for copying permission.
"""
@sntran
sntran / 2d_component.erl
Created June 25, 2012 05:30
Entity System Prototype in Erlang
-module ('2d_component').
-behaviour(gen_event).
-export([init/1, handle_event/2, terminate/2]).
init({X, Y, Width, Height, Rotation}) ->
{ok, {X, Y, Width, Height, Rotation}}.
handle_event({change, {x, NewX}}, {OldX, OldY, W, H, Rotation}) ->
io:format("Entity moved from (~p, ~p) to (~p, ~p).~n", [OldX, OldY, NewX, OldY]),
@sntran
sntran / Makefile
Last active December 12, 2015 09:38
Makefile for Erlang projects based on Rebar
REBAR=$(shell which rebar || echo ./rebar)
REBAR_URL=https://github.com/rebar/rebar/wiki/rebar
.PHONY: all test deps clean
all: $(REBAR) deps compile start
start:
./start.sh
app: $(REBAR)
/* Transparent Tabs */
.tabs {
list-style: none;
padding: 0;
overflow: hidden;
}
.tab {
display: block;
float: left;
@sntran
sntran / Conway's Game of Life in Erlang.md
Last active December 15, 2015 01:29 — forked from jszmajda/Readme.md
Conway's Game of Life in Erlang Conway's Game of Life in Erlang, in 2 hours, with 0 Erlang experience, in 22 lines of code.

sadsadasd

sadasd

<%= files["Flick.png"] %>

  • @sntran
  • @sdfippinger
// Ported from Stefan Gustavson's java implementation
// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
// Read Stefan's excellent paper for details on how this code works.
//
// Sean McCullough banksean@gmail.com
/**
* You can pass in a random number generator object if you like.
* It is assumed to have a random() method.
*/
@sntran
sntran / arrows.css
Last active December 17, 2015 19:48 — forked from danott/entities.css
Separated to reusable CSS classes, with support for IE.
/* Daniel Ott
* entities.css
* 31 January 2011
*
* Updated: 28 May 2013
* Son Tran
*
* Adding arrows to thinks makes them more clickable. Right?
* Use CSS's :after pseudo-selector to insert hexadecimal values
* of html entities into the document. Less markup. More awesome.
@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(),