2016/10/28

Createa a bootable USB stick for ubuntu on ubuntu

Things below are just an alternative. There is an official way to do this.

Get a USB stick

Make sure you have an usb stick with enough storage. Mine is 8 GB.

Format the USB Stick

There are plenty options to do this. My solution is using the built in one disks
  • Click the USB device
  • Click the square button
  • Select EXT4 as the type of parition
  • Done

Download Ubuntu ISO

Bootable USB

  • Install and Use UnetBootin
sudo apt-get install unetbootin
  • Launch UnetBootin
  • Select the Ubuntu ISO
  • Select your USB drive
  • OK
  • Done
Now, you have a Bootable USB for ubuntu :D

2016/02/26

Lua string.match vs string.gmatch

Overview

Just now, I spent a while on coding with string.gmatch and string.match. In my opinion, they are not quite intuitive for their usage. So, I tried to placed my example here for future references.

Code example

  • gmatch aims for global search while match ends at 1st match.
> line = "Jan  1 08:17:02 ABC hotplug: [OK] ifup: 'lan' => 'br-lan'"
> pat = '([^ ]+)'

# End at Jan
> return line:match('([^ ]+)')
Jan

# Equivalent to split by ' '
> for w in line:gmatch(pat) do print(w) end
Jan
1
08:17:02
ABC
hotplug:
[OK]
ifup:
'lan'
=>
'br-lan'
  • gmatch does not good at dealing with ^
> line = "Jan  1 08:17:02 ABC hotplug: [OK] ifup: 'lan' => 'br-lan'"
> pat = '^([A-Z][a-z][a-z])'
# Able to get Jan
> =line:match(pat)
Jan
# Unable to get anything
> for w in line:gmatch(pat) do print(w) end
>

Reference

  1. http://stackoverflow.com/questions/28593385/lua-string-match-vs-string-gmatch
  2. http://lua-users.org/wiki/StringLibraryTutorial

2016/02/09

Notes on studying LTN12

Background
Suppose you don’t know what LTN is, LTN stands for Lua technical note.
Below are notes dropped from LTN12 which is the 12th documents talking about filters, sink , source, chain and pump.
Source codes from the author is available here
Interpretations
XXX: My interpretations may or not may correct. Let me know if there are any misunderstands.
Functions accept successive chunks of input, and produce successive chunks of output.

Mathematically speaking,

Suppose f1, f2, ..., fn are filters s.t. F = f1 + f2 + ... + fn
Suppose x1, x2, ... xn are input s.t. X = x1 + x2 + ... + xn

F(x) == f1(x1) + f2(x2) + ... + fn(xn)
  • What is a chain?
A function combines two *similar* functions. By *similar*, I mean same function signatures and return data type.

Mathematically speaking,

Suppose f1, f2, ..., fn are functions s.t. C = f1 + f2 + ... + fn
Suppose x1, x2, ... xn are input s.t. X = x1 + x2 + ... + xn

C(x) == f1(x1) + f2(x2) + ... + fn(xn)
  • What are sources and sinks?
Filters form internal nodes inside an arbitrary *data flow*. *Data* in *data flow* means things shared between producer and consumer while *flow* means the direction of that things which is from *Producer* to *Consumer*

Given picture above, we can interpret *Sources* and *Sinks* as initial and final nodes of the *data flow*.
  • What is pump?
The driving force between internal nodes (filters)
  • Example application?
-- Goal: convert any input text ends with \r\n

-- source.file() returns a kind of filter
-- normalize() returns a kind of filter
-- source.chain() shows how to combine *similar* filters
-- input is a kind of *source*
input = source.chain(source.file(io.stdin), normalize("\r\n"))

-- sink.file() returns a kind of filter
-- output is a kind of *sink*
output = sink.file(io.stdout)

-- Driving force between input and output
-- Or, start the jobs
pump(input, output)

2016/01/15

Rescue vim process from other dead terminal session

Due to the fact that my office’s PC always down with no reason and leaving bunch of vim zombie sessions in my remote machine, I am tired for rescuing them times by times.
Finally, I found a way to resolve this issue.

Setup

  • OS: Ubuntu 14.04
  • Command required: reptyr and ps

Find PIDs of those zombie vim session

$> ps aux | grep vi

Rescue them

$> reptyr PID

Permission Problem

In case you got error like below
$ reptyr 1851
Unable to attach to pid 1851: Operation not permitted
The kernel denied permission while attaching. If your uid matches
the target's, check the value of /proc/sys/kernel/yama/ptrace_scope.
For more information, see /etc/sysctl.d/10-ptrace.conf
Fix this by editing configuration from 1 to 0
$vi /etc/sysctl.d/10-ptrace.conf

 kernel.yama.ptrace_scope = 0
Reload rule
$ sudo sysctl -p /etc/sysctl.d/10-ptrace.conf
Done.

References