The Full Snack Developer

by Huy Tran

A quick learner and a geek that have passion with technologies

Read this first

Multiple binaries in a Rust project

If you have a project that needs to compile into multiple binaries or libraries, you can config it in Cargo.toml like this:


name = "<your-lib-name>"
src = "<path-to-source>"

name = "<your-binary-name>"
src = "<path-to-source>"


For example, I am working on a 6502 emulator, and I need to build some tool along with my emulator, so this is my Cargo.toml:


name = "romgen"
src = "src/"

name = "emulator"
src = "src/"

Please note that after config the Cargo.toml to build multiple binaries, you need to specify the binary name everytime you run the project with cargo run:

cargo run --bin <binary-name>

But it’s annoying, it would be great if we could have a default binary that will execute every time we use cargo run. There is also an issue created for this.

Continue reading →

Writing 6502 Disassembler in Rust

In this post, I am talking about writing a disassembler for MOS 6502 microprocessor. It is a very first step to building a sophisticated emulator such as NES or even Apple II.

It is recommended to read about implementing CHIP-8 interpreter first. If you are not familiar with it, so I can wait, just go and read, then come back.

 Little-endian memory layout

One of the most important things you need to know before building anything with MOS 6502 is: It is a little-endian 8-bit microprocessor. So what do it mean?

The NES Hacker has an excellent explanation about how 6502 stores memory.

The table below tells us the difference between Little-Endian and Big-Endian:

Hex Value Byte Value
Little-Endian $1000 00 10
Big-Endian $1000 10 00

It is the assembler’s job to take care of the order of memory addresses and values to make sure they are in Little-Endian. However, you are

Continue reading →

Recursive type problem in Rust

After spending much time reading about Rust, I decided to give it a

It was a very simple implementation of Binary Tree Traversal algorithm.
Surprisingly, by doing it, I learned a lot of Rust’s basic concepts!

 Rust tell us what’s wrong in our code

One of the first things that the smartass Rust compiler threw to my face was the lovely error message:

$ rustc -o binary_tree
error[E0072]: recursive type `Node` has infinite size
  = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Node` representable
error: aborting due to previous error

So yes, this is the code:

struct Node {
    value: i32,
    left: Option<Node>,
    right: Option<Node>

This code is a very obvious way to implement a binary tree node in other
programming languages like C/C++ or Java. However, Rust compiler just doesn’t agree with

Continue reading →

Creating virtual dev environment with xhyve

xhyve is the awesome lightweight virtual machine for Mac OS X.

In this post, I will show you how to have the same target as Vagrant with
xhyve. At the end of this post, we will have the virtual environment which
synced with the host OS’s folder to work on our project.

Our virtual environment will run Ubuntu Server
14.04, which has built-in Python

 Install Ubuntu on xhyve

 Prepare the kernel and initrd

Because xhyve does not support BIOS or EFI booter. We need to pass the
kernel and ramdisk file to xhyve manually.

Since OS X does not recognize the file system of Ubuntu ISO. We need a little
hack to mount it.

Create a cloned ISO file named /tmp/tmp.iso of Ubuntu ISO disk.

$ dd if=/dev/zero bs=2k count=1 of=/tmp/tmp.iso
$ dd if=ubuntu.iso bs=2k skip=1 >> /tmp/tmp.iso

Now we can mount the ISO file to copy the necessary files:

$ hdiutil attach /tmp/tmp.iso

The ISO file now

Continue reading →

Print console.log with custom style

This happen when you tried to open Console panel in Facebook, you will see:

To print a message in Console panel with style like this, you can use the

console.log("%c<Your message>", "<css properties>");

For example:

console.log("%cWhy can't fish live out of water", "color: #F00; font-size: 50px;");

Another example, create a Stop message like Facebook:

console.log("%cStop!", "font-size: 50px; color: #F00; text-shadow: 1px 1px #000, -1px -1px #000, -1px 1px #000, 1px -1px #000")

Continue reading →

Setup free SSL with Let’s Encrypt and Nginx

If you search Google for “free SSL”, there are many companies provide you a free trial SSL for only 90 days or less. After that, you will have to pay.

Now, thanks to Let’s Encrypt. It’s no longer needed.
You can claim your own SSL certificate for free!

In this post, I will show you how to create your own free SSL certificate with
Let’s Encrypt and setup it with nginx.

 1. Install Let’s Encrypt

It’s recommended to run Let’s Encrypt on Linux.

The setup process is very simple, just clone it from Github:

git clone 

Then, navigate to letsencrypt folder and start the program to automatically setup everything.

cd letsencrypt ./letsencrypt-auto

Run this command to create your SSL certificate:

./letsencrypt-auto certonly --standalone --email -d -d 

Don’t forget to replace as your own domain address.

Your certificate now available

Continue reading →

Behind the scene: Syntax Highlighted Editor

Syntax highlighted editors is not a new concept in the world wide web.

Few years ago, there are some famous names that dominating the world:
FCKeditor in the early age, TinyEditor, nedit and ton of other WYSIWYG
(What you see is what you get) editors during the jQuery age,…

Nowaday, syntax highlighted editor can be found anywhere, in Wordpress, in blog engines, online code editors like C9 or Koding,… and the numbers are countless.

Most of them are very easy to integrate with your website / web app. Some just has one CSS and one JS file, all you have to do is to include them to your web page and, voilà!!!

But have you ever asked: How does it work? How it’s made?

Well… the answer is much easier than you think. You can find out yourself by
using Chrome Dev Tool or Firebug.

If you’re a lazy man, then read on, I will do it and tell you how :)

OK, no more talking, this is the basic

Continue reading →

“Branch early, branch often”

There is a tip for all Git users: “Branch early, branch often”

It means you should create yourself a habit of using branch when doing anything on a Git repository (doing the new task, fixing the new bug,…)

 But why?

So, why create a new branch? I want to work on my master branch, what’s wrong with it?

Okay, you can work on master, directly. However, this will lead to some hidden trouble, especially when you work in a team.

Let’s say: when you are working on a cool feature for the website, a customer suddenly called to ask you to fix an urgency bug. What will you do? Use git stash to backup your changes then revert the code to the original version and fix the bug? Of course, this will solve the problem, but it is not the proper solution at all. It might make some conflict when you revert your code from stash after fixed that bug. Or something weird will happen during the code

Continue reading →

Subscribe to The Full Snack Developer

Don’t worry; we hate spam with a passion.
You can unsubscribe with one click.