RSS Feed

Cloud9


Cloud9 is a web-based IDE good for collaboration and online development. You can store your large project on the remote server, and use any computer including netbook with a web browser to develop your system.

Now, the problem I faced when using C9 on my Chromium. Firstly, the address bar, tabs, and bookmarks occupy some space in the window. This results a non-editor look and feel. This makes me feel lacking of something. Secondly, the worst part is the shortcut key like Ctrl+W. By pressing this shortcut key, it will invoke the web browser closing window instead of the C9 shortcut key. Meaning, the shortcut key of the web browser has higher precedence than C9 itself.

I looked for the C9 official Chrome extension, namely Cloud9, but it just works like a bookmark. I tried also Cloud 9 IDE Shortcut. It works better than official Cloud9 Chrome extension. Yet, I need to enter my username and password for the first time. Another drawback is the missing of the window icons like minimize, maximize/restore, and close, and title bar, which results difficulty to resize and maximize/restore.

Looks for some solutions. The easiest way is to invoke

chromium --app=https://ide.c9.io/

Yay! Now I can use the shortcut keys and it looks like native text editor!

Chromium running C9 as app

Chromium running C9 as app

If you are serious, you can write the manifest.json to create the C9 web app, then you can have a custom icon instead of Chromium icon.

Vim


Because of the new working environment, I cannot use my favourite customised Emacs to work. So, I have to adapt with the new text editor. Luckily, vim is available in the remote server. That means I can use SSH to run the vim. And, even Emacs is available, I feel difficult to customise and install the packages I need, because I don’t have experience installing Emacs’ packages using text-based UI. (But if it is available, I may make a try.)

On the other hand, vim is a little different. vim is more tend to text-based UI, though there is a GUI version called GVim. In order to familiarise with vim, I also did some customisation on it, especially the key binding (hotkey) which is, totally not user-friendly by default. So, I share my ~/.vimrc with this post.

:set tabstop=4 ai ic wrap lbr showcmd
:set shiftwidth=4
:set expandtab
:set autoread
:set list
:set listchars=eol:↵,tab:→·,space:⋅
:set whichwrap+=<,>,h,l,[,]
":set nu
:set display+=lastline
:colorscheme ron

:filetype plugin on
:syntax on

"Navigate
vmap <Down> gj
vmap <Up> gk

"This will be overridden by YouCompleteMe, so need to have alternave solution
imap <Down> <C-o>gj
imap <Up> <C-o>gk
imap <C-Down> <C-o>gj
imap <C-Up> <C-o>gk
nmap <Down> gj
nmap <Up> gk

"Select
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
nmap <S-Home> v<Home>
nmap <S-End> v<End>
imap <S-Up> <C-o>v<Up>
imap <S-Down> <C-o>v<Down>
imap <S-Left> <C-o>v<Left>
imap <S-Right> <C-o>v<Right>
imap <S-Home> <C-o>v<Home>
imap <S-End> <C-o>v<End>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
vmap <S-Home> <Home>
vmap <S-End> <End>

"Remap the delete key, so that will not override the register for pasting
vmap <Delete> "_x
vmap <Backspace> "_x

"For the characters like newline (if shown with list)
highlight NonText guifg=#333333 guibg=#000000 ctermfg=darkgrey
"For special key like whitespace and tab
highlight SpecialKey guifg=#333333 guibg=#000000 ctermfg=darkgrey

 

GVim and Emacs

Best ever text editors: (g)vim and emacs

External HDD struggling


I have an HP 1T external HDD. It is dying. Sh*t!

So, I made my final struggling onto it. Though it is not 100% work as planned, I still have around 320G usable space.

Symptoms

Firstly, I found that some files cannot be deleted, I had no choice but plug out the USB cable manually. Try to chkdsk with Windows since it is NTFS partition, but the chkdsk stopped and no response during the progress. Then I know, these were the bad signs. So, have to avoid using it and get a new HDD, and move whatever files able to be moved.

Backup like sh*t

I use Linux instead of Windows, because copying out the files with Windows is damn slow. So, I have no choice but to use Linux. During copying from this pity HDD to the new HDD, the copying process will stop without warning, and the HDD failed to work. Worst, there was no way to cancel the operation, only solution to plug it out. I repeated this procedure approximately 60-70 times (heuristic guess only).

S.M.A.R.T

There is one thing I have to mention, that is S.M.A.R.T. I had enabled it on the external HDD, but it did not show any useful feature to SAVE my date.

NTFS

After copying out primary data and giving up some secondary data, I decided to re-format it as NTFS. Though I very dislike Windows, NTFS is still the main stream. NTFS and FAT32 are widely supported by the devices, for instance, LG video player. I also considered exFAT, but it is not as good as NTFS supported by Linux.

So, booted into Windows, plugged in the USB cable, format the disk without “Quick Format”, because I intended to have a thorough “chkdsk” scanning for bad sector.

Unfortunately, it was DAMN slow. To increase from 0% to 1% requires about 30 minutes. How am I going to live my following life?

Then I cancelled the format and gave up NTFS.

ext4

Since there was no more hope on NTFS, I planned to format as ext4. I run mkfs.ext4 with “-c” to check for bad blocks (something like bad sectors). But it failed. The hard disk failed to work until I re-plugged in the USB. I tried dmesg, found that there are a lot of errors like

usb 2-2: reset SuperSpeed USB device number 2 using xhci_hcd
usb 2-2: LPM exit latency is zeroed, disabling LPM.
blk_update_request: I/O error, dev sdb, sector 721688448

I concluded that it is not just bad sectors/blocks, but just failed to read the blocks.

badblocks

So, I assumed that mkfs.ext4 with “-c” or even fsck.ext4 will not solve my problem. Those bad sectors should never be accessed. So, I decided to give up those sectors, meaning, skip those factors from the partitions. This can be done by using fdisk or cfdisk, creating the partitions based on the “sector” unit instead of size. We can create the partition to occupy the bad sectors area, then create next partition after it, and then delete the partition that has bad sectors.

Then, the next question is how to find the bad sectors. mkfs.ext4 and fsck.ext4 cannot solve, because they are checking for the bad sectors thoroughly through the partition. The solution is to use “badblocks”.

There are two things have to know, i) sector and ii) block. They are different things. badblocks command can identify the bad blocks, but not the bad sectors. However, fdisk allows us to get the total number of the sectors.

Now, we can do some maths here. Let’s say you run the “fdisk -l”, and get this,

Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors

The total number of the sectors of the hard disk is 1953525168.

Now, to get the total number of blocks, use “cat /proc/partitions”, you will get something like this,

major minor  #blocks  name

   8        0  976762584 sdb

So, that is the total number of blocks, 976762584. And you can do the calculation, 976762584*2 = 1953525168. So, 1 block = 2 sectors.

This is important information, because when we use the badblocks, the values are shown in block unit. But when we want to create partitions, we are using sector unit.

So, when we run the badblocks like

badblocks -v -s -o bad.txt /dev/sdb

It will show something like

Checking blocks 0 to 976762583

which is the first block (0) until the last block (976762584 -1).

Now, in case we stop/interrupt the badblocks, we can continue from any where we want. Or, we can just start from any block. For instance

badblocks -v -s -o bad.txt /dev/sdb 976762583 488381292

where the 976762583 is the last block we want to check, and 488381292 is the start block we want to check. (Please read the manual in detail.)

Result

So, based on these tools and information, finally I found that there is around 320G contiguous safe space. So, I create the partition for it, and finally format it at ext4. Since it is a dying hard disk, I will not use it to store primary data, but secondary data and secondary backup. (Secondary data is unimportant; secondary backup is the duplicated backup, not one and only one.)

Actual plan for the next stage

Unfortunately, because the hard disk has critical failure, I cannot implement the next stage.

In my expectation, the hard disk may have multiple large, contiguous, and safe space. For example, 0-25% from the beginning is safe, and 60-100% is safe. As a result, I can create 2 partitions for these space. This is what I actually want. If this really happen, then I can use the LVM so that I can combine both partitions as a logical volume, and finally mkfs on it.

But since it does not happen, I cannot test on the LVM.

 

Search song that plays on your computer (Linux)

Posted on

Since I am working as freelance developer, I spent most of my “otaku” time with Animenfo Radio. Now, when listening with some nice songs you like, and you would like to know what the song is, then you can use Shazam to detect it. But using Shazam requires you to turn on your volume and use your mobile phone to detect it.

What if, you are listening the songs with your ear-phone?

To make it work on your Linux computer,

  1. Listen to a music or song, make sure it is still playing
  2. Run pavucontrol (PulseAudio Volume Control), install it if you didn’t
  3. Open a music searching website such as Midomi (so far I only know this website)
  4. Click the recording button (make sure it starts recording), allow using microphone as prompted by the web browser
  5. Then you will see this in pavucontrol
  6. PulseAudio Volume Controller record audio

    PulseAudio Volume Controller record audio

  7. There are two options, one is “Built-in Audio Analog Stereo”, another is “Monitor of Built-in Audio Analog Stereo”. Choose the “Monitor” something will redirect your computer audio output to your computer recorder (input).
  8. Then, the website like Midomi will get what you are listening, and submit for a search!

Yeah! No Shazam, and you can search when you are listening with the ear-phone.

Windows – Linux Edition (opinion only)

Posted on

This is just an opinion, not the fact.

Not long ago, there is an announcement that Windows can run Bash on Ubuntu on Windows. Not only that, there is Windows subsystem for Linux.

Surely, Linux and UNIX have a lot of powerful features, especially developer oriented. That is why Windows has to adopt them. Because they really solves a lot of problems, such as bash and other commands like grep, find, and vi. Cloud computing is emerging, command-line is much more efficient than GUI. Text file for collaborative development is much more efficient (using git) than working on binary file, as you cannot diff and patch.

Since Windows now supports Linux subsystem, in my opinion, Windows may come out Windows – Linux Edition that

  • uses the UNIX filesystem hierarchy standard
  • supports commercial device drivers (like printers)
  • supports Linux container virtualisation
  • can run Windows applications natively (without WINE)
  • run X window customised with Windows theme
  • uses its own package manager with package repository
  • is cheaper price

I believe, there will be a group of users interested in it!

Multilingual programming


Recently I involve in various projects. And they are using different technologies. I am fervent in programming because it conforms to my theological and philosophical perspective.

The languages and technology I am currently using: AngularJS and NodeJS, .NET MVC with C# Mono, and Ruby on Rails. Other related technologies: Nginx, AWS, migrations, Bootstrap CSS, etc. Besides that, my background is strong fundamental C, C++, and PHP skills; have good experience on Python; some experiences on Java, Android, Perl, and VB Script.

Since the advancement of cloud computing, everything is about server and client. HTML, JavaScript, and CSS are the basic of the basics. Furthermore, I am a Linux user, working on sysadmin tasks becomes much easier.

Naming convention and syntax

Involving in various languages and different development frameworks, there is something very important, that is, naming convention. Unlike syntax, where syntax is the language level rules, naming convention is the framework level rules. That means, when using a certain framework, you should follow the naming convention, especially MVC framework. Because by following naming convention (and file structure as well), the framework will use the corresponding database, view page, and controller as well. That is why, you follow it, your development will work faster, need not to care about the internal algorithms.

And some of the naming conventions, is just the style, not really related to the framework. They are “recommended”, instead of “required”. You must know how to differentiate these two.

Let me explain why the naming convention matters. Web technology is a very interesting area. If you open an HTML file, you will see three kinds of syntaxes: HTML, JavaScript, and CSS. Yes, these kinds of syntaxes exist in one file. JavaScript usually use the camel case, so do HTML DOM methods. CSS selector has no requirement, you can use camel case as well, but it is usually hyphenated identifiers, eg foo-bar instead of fooBar. HTML has no restriction. But the attributes are usually hyphenated, yet the value can be camel case or hyphenated. If it is JavaScript related, then camelCase; if CSS, hyphenated. This is how HTML works.

The above is purely client side HTML. For the server side, we usually use a template engine or template system. MVC uses Razor: Rails uses ERB; ExpressJS uses Jade; etc. So, when using these engines, new syntax comes in. Some template engines allow logical statements written in the view, such as Razor and ERB. As a result, you will see pascal case in Razor, snake case in ERB. So, by looking at these naming conventions and syntaxes, you will know what languages being used and what you should do. On the other hand, AngularJS has a very neat template design. No logical statements allowed in the template. Consequently, the template is very neat!

Pascal case and camel case

I don’t like Microsoft, but I admit that Microsoft has its own strength in some technologies. (Else you will not see Mono in Linux.)

Microsoft uses Hungarian notations in C/C++ documentation, for instance, “szName” means identifier “Name” with zero-terminated string data type. It is less human readable. Currently there are a lot of high level languages, thus human readable is required so EVERYONE can code. That is why the methods/functions are verbs like getSomething, setSomething, countSomething, addSomething, removeSomething, clearSomething, etc.

Microsoft uses PascalCase; JavaScript uses camelCase. Because I am used to work on JavaScript and HTML DOM more, that is why I prefer camelCase. Microsoft doesn’t disallow camelCase, but the PascalCase is a suggested naming convention. The reason I prefer camelCase rather than PascalCase is because, uppercase of the first later like

MyType

means data type. And

myData

means variable.

So, using the uppercase of the first letter allows me to differentiate my source code easily. However, Microsoft .NET C# uses PascalCase.

So, the question is, should I follow PascalCase or camelCase when using C#? After working with so many projects, I decided to follow the naming convention as recommended. Just use PascalCase as it is recommended. So that, I can feel the conformity instead of alienation. So, how to differentiate the data type and the variable? That is an easy solution. Just recognise them semantically! Because the programming languages, at the end, are still human readable language.

Editor

Lastly, I have to talk about the text editor. Instead of IDE, I prefer my favourite text editor, which can split the view into multiple unlimited windows, or clone multiple unlimited windows. Not only that, the text editor has syntax highlighting in multiple languages in one file like HTML. At the same time, open different file types like Ruby, C#, JavaScript, CoffeeScript, CSS, SASS, SCSS, it can still differentiate them. None of the editor can beat it! Yah! That is Emacs. Emacs is the best programmer editor!

I like Vim too. There is always Emacs and Vim war. I like Vim, as it is a general text editor. Edit any text with keyboard only. Edit configuration files through SSH, Vim is the best. Yet, Emacs is the programmer editor. It takes care the programming language indentation smartly. This is what I need! Highlight all and TAB, everything is formatted!

Technology that you must know


Linux, git, ssh, and Docker.

Linux is the most flexible OS kernel in the world right now. It is used in supercomputer, personal computer, server, embedded system like smart vacuum cleaner, mobile phone, smart TV, etc. Firstly because it is open source, everyone can study it, modify it, and redistribute it. Secondly, thanks to GPL (license). Because of GPL, anyone who use Linux need to open source their code. Those bossy people who knows Windows only and like to earn money without paying any efforts, and never understood programming and programmers, they will never understand the power of Linux and GPL.

git, like Linux, the main author is Mr. Torvalds. It is the most popular source code and revision management tool in the world right now. Those who only know GUI will never understand the power of text files. Those who don’t know what is open source are even more out of their topics.

SSH, with the advancement of cloud computing, you need to access to remote computer or server, SSH is your need!

[B]locking an SSH port for a Linux user is like taking a mouse away from a Windows user! (Powers, 2015)

Then lastly is Docker. It is an OS level virtualisation. The development environment and production environment always has a gap. Therefore, to develop a system in an environment as similar as the production is always a need. For the software level, we can use rbenv or rvm for Ruby, virtualenv for Python. However, if the production environment uses stable version of PHP and Apache, and your working computer is using the latest version of PHP and Apache, are you going to uninstall the latest version and install the stable version? If you have multiple projects, are you going to buy many computers for each of them? One of the solution is virtualisation using virtual machine like VirtualBox. But when we are using virtual machines, we need to reserve the memory and hard disk space to the virtual machines. And some of the hardware cannot be shared, but virtualised, like the graphic card and network card. However, if using container like Docker, it can access the hardware and share the OS libraries. You can also run the GUI application as it is running on the host computer. For those Windows users they will not understand, because Docker is based on Linux technology. However, you can still using Docker on Windows and Mac OS X.

Follow

Get every new post delivered to your Inbox.

Join 175 other followers