2015年4月24日 星期五

繩子長度與重量單位換算表

繩子長度單位:
1 台丈 = 10台尺 ≒ 3.\overline{03}公尺
1 台尺(日尺)[4] = (10/33) 公尺[5]0.\overline{30}公尺
1 台寸 = 0.1台尺 ≒ 0.\overline{03}公尺

繩徑單位(英吋、分):1英吋 = 8分,一分≒ 3.175mm


B級特多龍繩長度重量換算表
繩子粗細//mm
每公斤長度/m
每捆重量/kg
備註
1.2/4mm
40
15

1.5/5mm
35
15

1.8/5.5mm
21
16

2/6mm
16
22

3/9mm
11
23

3.5/10mm
9.5
25

4/12mm
8
37

4.5/14mm
6
50

5/15mm
4.5
50

6/18mm
3.5
64

     通常到了零售商繩子會再整理裁切,所以每捆重量不一,此表僅供參考。


Reference:

2015年4月23日 星期四

Ubuntu: Install FirefoxNewVersion/MozillaBuilds

Ubuntuzilla repository

An easy way of installing a Mozilla build is to use the Ubuntuzilla project repository. Ubuntuzilla is for ordinary users that want to use the latest Mozilla build as their default browser.
The Ubuntuzilla project's repository contains .deb repacks of the unmodified official Mozilla builds of Firefox, Thunderbird, and SeaMonkey. Just add the repository to your sources, and you'll be kept up to date on the latest Mozilla releases through the package manager. 
See the Ubuntuzilla website for details and usage instructions.

Installation

Old ubuntuzilla installer script users note: before installing these packages, run "ubuntuzilla.py -a remove -p packagename". Otherwise installation may fail due to the existence of a local diversion of /usr/bin/ links, placed there by the old ubuntuzilla script.
  • It is strongly recommended to make a backup of your Firefox/Thunderbird/Seamonkey user profile, just in case. This is stored in your home directory. Firefox and Seamonkey profiles are stored in the .mozilla directory, Thunderbird profile is stored in .thunderbird or.mozilla-thunderbird directory.
  • Add the ubuntuzilla repository to your /etc/apt/sources.list, either using your favorite editor, or by running the provided one-line command (copy and paste the entire line into a terminal, then press enter).
The repository to add, if you're adding it manually to your sources.list, is
deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main
If you wish, verify that the repository has been added, by looking at /etc/apt/sources.list in your favorite text editor, or running "tail /etc/apt/sources.list" in the terminal.
  • Then add the package signing key to your keyring, by running the following command:
    sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C1289A29
  • Update your package database:
    sudo apt-get update
  • Install your desired package, with one of the following commands:
    sudo apt-get install firefox-mozilla-build
    sudo apt-get install thunderbird-mozilla-build
    sudo apt-get install seamonkey-mozilla-build
All of this can also be done through the GUI with the Synaptic Package Manager, if you so desire. See this step-by-step visual tutorialif you would like to try the GUI approach.
From here on, any updates will be offered to you through the usual channels in the Update Manager.

Localizations

The packages in the repos are 'en-US' (US English) versions. To install any other translations:
  • Download the appropriate language pack add-on .xpi file,
  • Install it from within Firefox/Thunderbird/Seamonkey (as you would with any other add-on).
  • Enable it by setting the config general.useragent.locale to the name of the locale that you want to use. The name of the locale is the same as the name of the language pack that you installed.
    • To edit the config, go to Edit -> Preferences -> Advanced -> General -> Config Editor.
  • Restart the application for the setting to take effect.
Firefox language packs are at
http://releases.mozilla.org/pub/mozilla.org/firefox/releases/<version>/linux-i686/xpi/
Thunderbird language packs are at
http://releases.mozilla.org/pub/mozilla.org/thunderbird/releases/<version>/linux-i686/xpi/
Seamonkey language packs are at
http://releases.mozilla.org/pub/mozilla.org/seamonkey/releases/<version>/langpack/
For more info about installing language packs, see this Mozilla knowledgebase article.

Removal

To uninstall the packages, uninstall the *-mozilla-build packages, using your favorite package manager. E.g., using apt-get:
sudo apt-get remove firefox-mozilla-build
sudo apt-get remove thunderbird-mozilla-build
sudo apt-get remove seamonkey-mozilla-build
If you no longer wish to have the Ubuntuzilla repository in your sources, you can edit it out of your /etc/apt/sources.list.

Reference:

Ubuntu: Modify the Dependency of a package (*CAUTION* THIS MAY BREAK THE SYSTEM UNINTENTIONALLY)

*CAUTION* THIS MAY BREAK THE SYSTEM UNINTENTIONALLY


Search packages on:
http://packages.ubuntu.com/
http://www.ubuntuupdates.org/
http://www.debian.org/distrib/packages

1. Extracts the filesystem tree:
  $ dpkg -x original.deb data
2. Extracts the control information (default to DEBIAN/):
  $ dpkg -e original.deb
3. Edit the dependency of the packages:
  $ vi DEBIAN/control
  $ mv DEBIAN data/
4. Create a new debian archive:
  $ dpkg -b data new.deb
5. Install the new package:
  $ sudo dpkg -i new.deb


If some dependency issues still occurred, dpkg may suggest you to use "--auto-deconfigure" to solve those issue. *CAUTION* THIS MAY ALSO BREAK THE DEPENDENCY OF OTHER INSTALLED PACKAGES.
If the dependency is broken after using the "--auto-deconfigure" option, try the following commands to fix it:
Reinstall the original version of some packages which break the dependency:
  $ sudo apt-get install package=x.y.z-m.n
Use "-f / --fix-broken" option in apt-get:
  $ sudo apt-get -f install package
    OR (if still unable to correct the problem, but may be a LOT of works to do.)
  $ sudo apt-get -f install

2015年4月22日 星期三

C++: vector v.s. deque

std::vector

template < class T, class Alloc = allocator<T> > class vector; // generic template
Vector


Vectors are sequence containers representing arrays that can change in size.

Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.

Internally, vectors use a dynamically allocated array to store their elements. This array may need to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new array and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, vectors do not reallocate each time an element is added to the container.

Instead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the storage strictly needed to contain its elements (i.e., its size). Libraries can implement different strategies for growth to balance between memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity (see push_back).

Therefore, compared to arrays, vectors consume more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.

Compared to the other dynamic sequence containers (deques, lists and forward_lists), vectors are very efficient accessing its elements (just like arrays) and relatively efficient adding or removing elements from its end. For operations that involve inserting or removing elements at positions other than the end, they perform worse than the others, and have less consistent iterators and references than lists and forward_lists.

std::deque

template < class T, class Alloc = allocator<T> > class deque;
Double ended queue
deque (usually pronounced like "deck") is an irregular acronym of double-ended queue. Double-ended queues are sequence containers with dynamic sizes that can be expanded or contracted on both ends (either its front or its back).

Specific libraries may implement deques in different ways, generally as some form of dynamic array. But in any case, they allow for the individual elements to be accessed directly through random access iterators, with storage handled automatically by expanding and contracting the container as needed.

Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of elements also at the beginning of the sequence, and not only at its end. But, unlike vectors, deques are not guaranteed to store all its elements in contiguous storage locations: accessing elements in a deque by offsetting a pointer to another element causes undefined behavior.

Both vectors and deques provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors use a single array that needs to be occasionally reallocated for growth, the elements of a deque can be scattered in different chunks of storage, with the container keeping the necessary information internally to provide direct access to any of its elements in constant time and with a uniform sequential interface (through iterators). Therefore, deques are a little more complex internally than vectors, but this allows them to grow more efficiently under certain circumstances, especially with very long sequences, where reallocations become more expensive.

For operations that involve frequent insertion or removals of elements at positions other than the beginning or the end, deques perform worse and have less consistent iterators and references than lists and forward lists.
 
Reference:
http://www.cplusplus.com/reference/vector/vector/?kw=vector
http://www.cplusplus.com/reference/deque/deque/?kw=deque
GotW #54: Using Vector and Deque

2015年4月21日 星期二

Git Usage

Git Basics

Git Commands
git clone
git pull
  --rebase: Instead of a merge, perform a rebase after fetching.
git push
git remote
  -v, --verbose
  set-url <name> <url>

git log
git diff
git tag
  -a <tagname> <commit>
git describe
git status
git-rev-parse

git add
git rm
git mv
git reset
git revert
git commit
  --ammend*
  Git 版本控制系統(3) 還沒 push 前可以做的事

git branch
  branch: create a new branch.
  -d branch: Delete a branch. The branch must be fully merged in HEAD.
  -D branch: Delete a branch irrespective of its merged status.
git checkout
  branch: switch to branch
  path: discard changes on working copy
git merge
git rebase
  branch: Forward-port local commits base on the branch.
  Git 分支 - 分支的新建與合併
  Git Branch 的操作與基本工作流程
  使用 git rebase 避免無謂的 merge
  Pull with rebase

2015年4月17日 星期五

ANSI escape code

Colors

Text colors (and SGR parameters in general) are manipulated using CSI n1 [;n2 [; ...]] m sequences, where each n1, n2, ... is an SGR parameter as shown above. Thus, for instance, you use codes 30+i to specify foreground color, 40+i to specify background color, where i is the number in the desired color's column header in the table below. The following examples can be used with the printf utility, where \x1b[ implements the CSI: To switch the foreground color to black, use \x1b[30m; to switch to red, use \x1b[31m; utilizing the "bold" parameter, gray would be \x1b[30;1m; to get bold red, use \x1b[31;1m. To reset colors to their defaults, use \x1b[39;49m (or reset all attributes with \x1b[0m).
Color table[11]
Intensity 0 1 2 3 4 5 6 7
Normal Black Red Green Yellow[12] Blue Magenta Cyan White
Bright Black Red Green Yellow Blue Magenta Cyan White
There are two other color standards CSS/HTML standard colors and X Window colors which standardize both the color names and associated RGB color values, but the escape sequence standard only specifies the color names, not RGB values. The chart below shows default RGB assignments for some common terminal programs, together with the CSS and the X Window System colors for these color names.[citation needed]

Color name Standard VGA colors Windows XP CMD Terminal.app PuTTY mIRC xterm CSS/HTML X
Normal Black 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0 0, 0, 0
Red 170, 0, 0 128, 0, 0 194, 54, 33 187, 0, 0 127, 0, 0 205, 0, 0 255, 0, 0 255, 0, 0
Green 0, 170, 0 0, 128, 0 37, 188, 36 0, 187, 0 0, 147, 0 0, 205, 0 0, 255, 0 0, 128, 0
Brown/yellow 170, 85, 0 128, 128, 0 173, 173, 39 187, 187, 0 252, 127, 0 205, 205, 0 255, 255, 0 255, 255, 0
Blue 0, 0, 170 0, 0, 128 73, 46, 225 0, 0, 187 0, 0, 127 0, 0, 238 0, 0, 255 0, 0, 255
Magenta 170, 0, 170 128, 0, 128 211, 56, 211 187, 0, 187 156, 0, 156 205, 0, 205 255, 0, 255 255, 0, 255
Cyan 0, 170, 170 0, 128, 128 51, 187, 200 0, 187, 187 0, 147, 147 0, 205, 205 0, 255, 255 0, 255, 255
Gray 170, 170, 170 192, 192, 192 203, 204, 205 187, 187, 187 210, 210, 210 229, 229, 229 255, 255, 255 255, 255, 255
Bright/light Darkgray 85, 85, 85 128, 128, 128 129, 131, 131 85, 85, 85 127, 127, 127 127, 127, 127

Red 255, 85, 85 255, 0, 0 252,57,31 255, 85, 85 255, 0, 0 255, 0, 0

Green 85, 255, 85 0, 255, 0 49, 231, 34 85, 255, 85 0, 252, 0 0, 255, 0 144, 238, 144 144, 238, 144
Yellow 255, 255, 85 255, 255, 0 234, 236, 35 255, 255, 85 255, 255, 0 255, 255, 0 255, 255, 224 225, 255, 224
Blue 85, 85, 255 0, 0, 255 88, 51, 255 85, 85, 255 0, 0, 252 92, 92, 255 173, 216, 230 173, 216, 230
Magenta 255, 85, 255 255, 0, 255 249, 53, 248 255, 85, 255 255, 0, 255 255, 0, 255

Cyan 85, 255, 255 0, 255, 255 20, 240, 240 85, 255, 255 0, 255, 255 0, 255, 255 224, 255, 255 224, 255, 255
White 255, 255, 255 255, 255, 255 233, 235, 235 255, 255, 255 255, 255, 255 255, 255, 255



Reference:
http://en.wikipedia.org/wiki/ANSI_escape_code

2015年4月14日 星期二

Github Usage

Change the repository URL of local working copy:
View the current origin URL:
$ git remote -v
$ git remote set-url origin https://github.com/<user>/<repo>.git

If you try to access the repository (clone, push, ...etc) via HTTP/HTTPS, the following error occurred:
error: The requested URL returned error: 403 while accessing https://github.com/user/repo.git/info/refs
fatal: HTTP request failed
Use SSH (get the URL from the repository):
$ git remote set-url origin git@github.com:<user>/<repo>.git



Connecting over SSH
If you clone with SSH, you must generate SSH keys on each computer you use to push or pull from GitHub.

Note: you can use the ~/.ssh/config to setup the SSH authentication instead of ssh-agent


Template of .gitignore
https://github.com/github/gitignore


Reference:
https://help.github.com/set-up-git-redirect
https://help.github.com/create-a-repo
https://help.github.com/articles/fork-a-repo/
https://help.github.com/articles/https-cloning-errors/

https://help.ubuntu.com/lts/serverguide/git.html

Subversion Command

Checkout:
svn co URL[@REV]... [PATH]

Commit:
svn ci [PATH]
  --depth ARG : limit operation by depth ARG ('empty', 'files',
                        'immediates', or 'infinity')

Log:
svn log [PATH][@REV]
            URL[@REV] [PATH...]
  -r ARG1[:ARG2] :
    NUMBER: revision number
    {DATE}: revision at start of the date, ex: {2015-01-01}
    HEAD: latest in repository
    BASE: base rev of item's working copy
    COMMITTED: last commit at or before BASE
    PREV: revision just before COMMITTED

Difference:
svn diff [-r ARG1[:ARG2]]

Merge:
Roll back to the old version:
$ svn up
$ svn merge -rHEAD:{NUMBER} [PATH]
$ svn ci

Edit Property:
svn pe svn:externals .

Note: svn recognizes the following special versioned properties
  svn:ignore - A newline separated list of file glob patterns to ignore.
  svn:keywords - Keywords to be expanded.
  svn:executable - If present, make the file executable.
  svn:eol-style - One of 'native', 'LF', 'CR', 'CRLF'.
  svn:mime-type - The mimetype of the file.
  svn:externals - A newline separated list of module specifiers, each of which consists of a URL and a relative directory path.
  svn:needs-lock - If present, indicates that the file should be locked before it is modified.

2015年4月10日 星期五

cURL: VERSIONS -- the version numbering scheme in curl

Version Numbers and Releases
Curl is not only curl. Curl is also libcurl. They're actually individually versioned, but they mostly follow each other rather closely.
The version numbering is always built up using the same system:
X.Y[.Z]
Where
X is main version number
Y is release number
Z is patch number
One of these numbers will get bumped in each new release. The numbers to the right of a bumped number will be reset to zero. If Z is zero, it may not be included in the version number.
The main version number will get bumped when *really* big, world colliding changes are made. The release number is bumped when changes are performed or things/features are added. The patch number is bumped when the changes are mere bugfixes.
It means that after release 1.2.3, we can release 2.0 if something really big has been made, 1.3 if not that big changes were made or 1.2.4 if mostly bugs were fixed.
Bumping, as in increasing the number with 1, is unconditionally only affecting one of the numbers (except the ones to the right of it, that may be set to zero). 1 becomes 2, 3 becomes 4, 9 becomes 10, 88 becomes 89 and 99 becomes 100. So, after 1.2.9 comes 1.2.10. After 3.99.3, 3.100 might come.
All original curl source release archives are named according to the libcurl version (not according to the curl client version that, as said before, might differ).
As a service to any application that might want to support new libcurl features while still being able to build with older versions, all releases have the libcurl version stored in the curl/curlver.h file using a static numbering scheme that can be used for comparison. The version number is defined as:
Where XX, YY and ZZ are the main version, release and patch numbers in hexadecimal. All three number fields are always represented using two digits (eight bits each). 1.2 would appear as "0x010200" while version 9.11.7 appears as "0x090b07".
This 6-digit hexadecimal number is always a greater number in a more recent release. It makes comparisons with greater than and less than work.
This number is also available as three separate defines: LIBCURL_VERSION_MAJOR, LIBCURL_VERSION_MINOR and LIBCURL_VERSION_PATCH.

The library name may always be "libcurl.so.4.1.1". So check the actually version number in "curl/curlver.h" or use the curl-config tool:
$ sh curl-config --version

Reference:
http://curl.haxx.se/docs/versions.html
http://curl.haxx.se/libcurl/using/

2015年4月9日 星期四

Linux: Split A File Into Several Smaller Pieces

Split the "BIGFILE" into PREFIX001, PREFIX002, ..., PREFIXNNN files, and each file size is 1MB:
$ split -a 3 -b 1M -d BIGFILE PREFIX
  -a: use suffixes of length N (default 2)
  -b: put SIZE bytes per output file
       SIZE may have a multiplier suffix: b 512, kB 1000, K 1024,
       MB 1000*1000, M 1024*1024, GB 1000*1000*1000,
       G 1024*1024*1024, and so on for T, P, E, Z, Y.
  -d: use numeric suffixes instead of alphabetic

Split a text (log) file into several smaller files, and each one has 1000 lines:
$ split -a 3 -l 1000 -d LOGFILE PREFIX
  -l: put NUMBER lines per output file

Split a text (log) file into several smaller files, and each file size is at most 1MB:
$ split -a 3 -C 1M -d LOGFILE PREFIX
  -C: put at most SIZE bytes of lines per output file

Merge all split files into one:
$ cat PREFIX* > BIGFILE

Linux: Change The System/Hardware Date & Time Zone

# Search the "Area/City" in /user/share/zoneinfo
Ubuntu:
  $ sudo echo "Asia/Taipei" > /etc/timezone

CentOS:
  $ sudo echo "ZONE=\"Asia/Taipei\"" > /etc/sysconfig/clock

$ sudo cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime


# Set Date
$ sudo date 040911112015.00

# Set Hardware Clock
$ sudo hwclock -w

2015年4月2日 星期四

Windows PowerShell "Pause"

Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")


In this line we’re using PowerShell’s automatic variable $host (which is actually an instance of the .NET Framework class System.Management.Automation.Host) and the ReadKey method. (Which is actually a method of the RawUI property, which is a property of the UI property, which is a property of $host. And the leg bone’s connected to the knee bone, the knee bone’s connected to the ankle bone, the ….) The ReadKey method enables us to get information about the key that has just been pressed. Of course, in this case the only information we care about is the fact that a key has been pressed. Therefore, we pass ReadKey two parameters:

NoEcho. This prevents any information from appearing on screen when the user presses a key. If you leave out this parameter the pressed key will be echoed back to the screen.

IncludeKeyDown. This tells the script to continue as soon as a key has been pressed; that means the script will continue even if the user presses and holds a key down. If you’d prefer to wait until the user has released the key, then use this parameter instead: IncludeKeyUp.

There’s one more parameter that we can add to the ReadKey method: AllowCtrlC. In Windows PowerShell, pressing Ctrl+C typically causes the script to terminate. If you add the AllowCtrlC parameter to the ReadKey method, however, the user can choose to press Ctrl+C instead of pressing any other key. If they do that, the script will not terminate, but instead continue on as if the user had pressed any other key on the keyboard. (But only in conjunction with the ReadKey method. If the user presses Ctrl+C somewhere else the script will terminate.)

Reference:
Pausing a Script Until the User Presses a Key
How do you do a ‘Pause’ with PowerShell 2.0?
How to Properly Pause a PowerShell Script