Wednesday, February 14, 2024

Thursday, May 24, 2018

vimrc - Check the file encoding before write and change it to what you want

I wanted to save almost every files into euc-kr encoding. But my system uses utf-8 as the default character set.
Therefore, I needed to check the file encoding before saving files and change it if necessary.
Here is what I added to my vimrc script to do this.

Sunday, May 13, 2018

Detect unicode encoding from BOM (Byte order mark)

To work with strings in a file, I need to know in which unicode the file is encoded. The kind of magic number which is called BOM (Byte Order Mark) let you know which unicode is used.
For more information about BOM, you can get it from wikipedia.

Here is the python code to find out which unicode is used.

Friday, January 12, 2018

Translate the number of ethernet frames into bps

How to calculate bps based on the number of ethernet frames?
To do this, I need to know the frame size of a ethernet frame.
Based on Wikipedia page explaining ethernet frame, a frame size on the layer 1 (physical layer) is 84 bytes for a 64 byte ethernet frame.

Minimum ethernet frame size is 64 bytes including 14 byte ethernet header and 4 bytes of CRC after the payload.
On layer 1, 8 bytes for the preamble and the frame delimiter and 12 bytes of inter-frame gap are also needed. Therefore, you need 84 bytes for the 64 bytes ethernet frame on layer 1.

The table below is from Wikipedia.

802.3 Ethernet packet and frame structure
LayerPreambleStart of frame delimiterMAC destinationMAC source802.1Q tag (optional)Ethertype (Ethernet II) or length (IEEE 802.3)PayloadFrame check sequence(32‑bit CRC)Interpacket gap
octets1 octet6 octets6 octets(4 octets)2 octets46‑1500 octets4 octets12 octets
Layer 2 Ethernet frame← 64–1522 octets →
Layer 1 Ethernet packet & IPG← 72–1530 octets →← 12 octets →

Let's suppose that you received 1,400,000 frames per second.
1,400,000 frames * 84 bytes * 8 = 940800000 bits
As a result, 1,400,000 FPS can be translated into 940.8 Mbps.

Thursday, January 11, 2018

The history about getting started Saleor on OS X El Capitan

I log what I do to get started a simple shopping mall with Saleor.
The whole procedure is followed on the Saleor's "Getting started" document.

Prerequisites

Install python

I use pyenv, so that I installed Python version 3.5.1 via the pyenv. I also created the virtual env and upgraded the pip. In this case, I wanted the name of the environment to be "pot".
  1. pyenv install 3.5.1
  2. pyenv virtualenv 3.5.1 pot
  3. pip install --upgrade pip

Install Node.js and webpack module bundler

I wanted to install Node.js via NVM. I followed the instruction from Junsik's Blog.
As a result, I got Node.js v9.3.0 and webpack installed.
  1. curl https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
  2. nvm install stable
  3. npm i webpack -g

Install PostgreSQL

I chose the simplest way which is installing Postgres.app. Downloaded it from Postgres.app website and installed it.

Installation

Before the installation, I cloned the source of Saleor on the directory named saleor.
When I tried to install the requirements from "requirements.txt" using pip, I got the error described by the issue of uwsgi. I solved the error with the comment by "gicornachini". After this, I could install the whole packaged from "requirements.txt".
  1. pyenv activate pot
  2. cd saleor/
  3. pip install -r requirements.txt

Prepare Database

  1. Add the path where the client programs of Postgres are located to ${PATH} (If necessary). After this, restart the terminal.
    echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
  2. Create user (role) with the name you want. -s option makes the user having superuser privilege. -W option force password prompt.
    createuser ${USERNAME} -s -W
  3. Find database setting in settings.py and modify it with the name you created.
    -- default='postgres://saleor:saleor@localhost:5432/saleor'
    ++ default='postgres://${USERNAME}:{PASSWORD}@localhost:5432/saleor'
  4. Create database named "saleor"
    createdb saleor
  5. Migrate
    python manage.py migrate


Prepare front-end

When I did "npm install", shell could not find npm. To make it work, I did "nvm use stable".

  1. npm install
  2. npm run build-assets


Run server

Now, it is ready to run server. Let's get it.
  1. python manage.py runserver
  2. Access https://localhost:8000 on your web browser


Understanding how the Toeplitz-based hash function works