Jul
3
VI Basic Movement
July 3, 2008 | Leave a Comment
I like vi. Yes I do. Not Emacs. But VI. Here is a list of some basic commands to move around in VI!
| h l k j | character left, right, line up, down |
| b w | word/token left, right |
| ge e | end of word/token left, right |
| { } | beginning of previous, next paragraph |
| ( ) | beginning of previous, next sentence |
| 0 gm | beginning, middle of line |
| ^ $ | first, last character of line |
| nG ngg | line n, default the last, first |
| n% | percentage n of the file (n must be provided) |
| n | column n of current line |
| % | match of next brace, bracket, comment, #define |
| nH nL | line n from start, bottom of window |
| M | middle line of window |
Apr
17
Fun With Rsync - Part I
April 17, 2008 | 2 Comments
If you’ve used rsync in the past, you know that it makes quite a few things much easier to manage. For example, you can use rsync to backup files from one server to another, you can use it to automate patch deployments, you can mirror entire websites and also have it function like a semi-NFS client/server which can synchronize data between several servers by running it like a watchdog so that as soon as a file gets updated on primary server, it instantly syncs up all other servers.
What is Rsync?
rsync is a file transfer program for Unix systems. rsync uses the “rsync algorithm” which provides a very fast method for bringing remote files into sync. It does this by sending just the differences in the files across the link, without requiring that both sets of files are present at one of the ends of the link beforehand. Some features of rsync include
- Can update whole directory trees and filesystems
- Optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
- Requires no special privileges to install
- Internal pipelining reduces latency for multiple files
- Can use rsh, ssh or direct sockets as the transport
- Supports anonymous rsync which is ideal for mirroring
The Basics
If you don’t already have it installed, get it done this way on Debian systems:
apt-get install rsync
On other Linux distributions you would use yum(Fedora/CentOS) or yast (SuSE) to install rsync.
The base requirement of the rsync system is that you install the rsync program on the source and destination hosts. The easiest way to transfer files is to use a remote shell account. To copy a group of files to your home directory on host, you can run this command:
rsync file1 file2 … host:
Rsync defaults to rsh as the remote shell and that is not secure. Instead you can have rsync use ssh by using the option –rsh or -e ssh option:
rsync -e ssh file1 file2 … host:destination_dir
Copying one folder to another:
rsync -r /home/lxpages/junk /home/backups/junk/
That will copy the folder with simple application, without that much are to preservation of permissions/owners/etc. To make exact
duplicates, we can add the -a switch.
rsync -av /home/lxpages/junk /home/backups/junk
The above retains ALL ownership/permission and rsync in verbose mode.
rsync -av --delete /var/www/junk /home/lxpages/junk
The –delete keeps destination folder identical to source by removing any files that don’t match src dir.
rsync -av --delete -e sshlxpages@remotehost.com:/home/lxpages/junk /home/lxpages/junk
Rsync everything from remote server and folder /home/lxpages/junk to local server and folder /home/lxpages/junk.
There are many more examples which I will include later parts. For now just remember that man page is your friend. Simply type ‘man rsync’ and read/view all the available options you can play around with.
References: http://samba.anu.edu.au/rsync/
Mar
25
How to Remove Linux and Install Windows XP
March 25, 2008 | 2 Comments
Earlier I stumbled on a Microsoft support page titled How to Remove Linux and Install Windows XP. I’m sure there are a small number of people who come back to Windows after finding Linux a bit hard but I don’t think there was ever a need for an article on how to remove Linux. You can simply pop in the XP CD and reboot and follow the instructions to install it!
I wonder how many people this article helped.
Mar
14
Calculate big using bc
March 14, 2008 | Leave a Comment
If you’re a command line freak, you’ve probably use expr for common math calculations but did you know that the bc command allows you to do similar math calculations and is more powerful when it comes to bigger calculations?
bc is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language. A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.)
If the above man page description don’t make any sense yet, then just remember that bc is a command line calculator. The nice thing about bc is that it accepts inputs from files, from standard output and this allows the command line user to pipe data out for quick calculations. The syntax for basic calculation is very similar to Google’s calculator.
Here are some basic examples:
$ cat file.txt
5+5
$ bc < file.txt
10
$ echo 2+2 | bc
4
It’s possible to use basic math with variables:
$ A=9
$ B=6
$ C=$ ((A+B))
$ echo $C
15
Some more basic examples of addition, subtraction, multiplication and division:
$ echo ‘50+20′ | bc
70
$ echo ‘50-20′ | bc
30
$ echo ‘50*20′ | bc
1000
$ echo ‘50/20′ | bc
2
There is a variable called scale and using it adds number of digits which follow the decimal point. By default scale is 0. So the above example shows 2 but if scale variable was used, the result could be displayed in x # of digits.
$ echo ’scale=1;50/20′ | bc
2.5
How about square root, and power:
$ echo ’scale=15;sqrt(8)’ | bc
2.828427124746190
$ echo ‘4^4′ | bc
256
Convert from decimal to hexadecimal, from decimal to binary and from binary back to decimal:
$ echo ‘obase=16;255′ | bc
FF
$ echo ‘obase=2;22′ | bc
10110
$ echo ‘ibase=2;obase=A;10110′ | bc
22
bc in interactive mode:
$ bc
4*4
16
13*13
169
scale=10
199/3
66.3333333333
2^32
4294967296
As you can see, it’s not shy about displaying the big value results. Here are some more resources to help you explore bc further:
- command-line calculations using bc
- Hexadecimal or Binary Conversion
- bc Command
- bc - The shell maestro’s calculator
- bc — The Linux Command-line Calculator
- man bc
Mar
11
What’s wrong with NSOL?
March 11, 2008 | 2 Comments
I wanted to transfer out this decade old domain I had originally registered with NSOL but the shameless business practice of NSOL didn’t allow it to happen. The domain is expiring in the next 2 weeks so I finally made some time (yes I couldn’t make time in 10 years) to actually transfer it over to a more reasonable registrar that is obviously much cheaper, $6.95 compared to $35 for one year renewal! Why in the world does NSOL still charge so much money? Don’t they realize this business is no longer a monopoly?
So back to my domain transfer issue… I clicked on all the necessary buttons to initiate the transfer to my new registrar and in the process I may have updated domain contact info because it was outdated. I didn’t realize doing something so stupid like updating my contact info would trap me with NSOL for yet another year!
Here is the email I receive from NSOL on the last step of domain transfer:
Dear Network Solutions® Customer,
We were unable to process the request to transfer YABADABADOOOOOOOO.COM to another domain name service provider.
Specifically, the domain name registration was not eligible for transfer because:
The domain cannot be transferred to another registrar for a period of 60 days following a change in Primary Contact or WHOIS Admin Contact.If you have any questions, please contact Customer Service at registrar@networksolutions.com.
Network Solutions is committed to delivering high quality services to meet your online needs. We hope to continue to serve you in the future.
Sincerely,
Network Solutions® Customer Support
I know that if it’s a new domain registration, there is a rule that disallows you to transfer until 60 days has passed but I’ve never heard of something like updating contact info screwing things up too.
Feb
21
to HUP or nohup?
February 21, 2008 | 6 Comments
Any user or admin more than likely faced or will face a situation where their command will take a long time to complete and at the same time you’d want to logout and go home. If user’s shell exits, it sends a SIGHUP signal to it’s children killing them all. However, if the job is preceded by the nohup command, then the program ignores SIGHUP and will continue to run on the system until completion. Processes run by nohup are immnue to SIGHUP and SIGQUIT signals.
Now you can use screen to do the same thing by detaching your terminal before logging out but that still ties your command to your shell. By using nohup, it releases the command to the system level and it becomes independent of your shell and functions as a system daemon. You can also run your command and redirect output to a log to scan through later.
Here are some examples of using nohup.
$ nohup myprogram &
$ exit
- The above command starts myprogram in the background in such a way that the subsequent logout does not stop it. By default, nohup.out is created and captures all the output.
$ nohup myprogram > output.log &
- The above redirect output to a file other than the nohup.out.
If you already have something running in bg without using the nohup command, you can easily bring nohup to the picture:
$ myprogram &
$ nohup -p `pgrep myprogram`
- myprogram is now preceded by nohup.
$ nohup find / -name ‘*’ -size +1000k > log.txt &
- The above example runs the find command, detaches itself in bg as a daemon and continues to run until completion.
So if you’re not using nohup. Use it often, it’s a great helper.
Feb
20
Getting started with Ruby
February 20, 2008 | 7 Comments
Language (latest release by time of writing: 1.8.6)
- All: Source release for any platform
- Windows: Ruby Installer for Windows
- OS X: Pre-compiled disk image for OS X
Reference documentation
- Ruby Core Library: Complete methods listing and explanation for all the built-in Ruby classes, such as strings, hashes, and IO. Only covers 1.6.8 — supplement with What’s New in Ruby 1.8.
- Ruby Standard Library: Ruby ships with about a hundred standard libraries. They’re all documented in varying degree and collected in one easy bundle with this site.
Guides and books for programmers
- Ruby in Highlights: An introduction to Ruby by its creator Matz. Excellent for a quick overview and feel of the language.
- Programming Ruby: A thorough introduction and guide to Ruby for programmers written by the Pragmatic Programmers duo. Available in full-length form for free!
- The Ruby Way: Includes more advanced Ruby topics including an especially excellent chapter on OOP and Dynamicity in Ruby. Requires a Safari membership, though.
- Ruby Garden Wiki: Tons of great information about Ruby, such as OS X gotchas and Ruby usage in real life (convince your boss by name-dropping NASA, Lucent, and HP)
Guides for non-programmers
- Why’s (Poignant) Guide to Ruby: Hilarious and very aparte introduction to programming with Ruby — complete with cartoon series.
- Learn to Program: A thorough introduction to programming in general using Ruby as the learning language.
Ruby bloggers
- Chad Fowler (RubyGems), Rich Kilmer (RubyGems, Jabber4r), Dave Thomas (Pragmatic Programmers), Jim Weirich (Rake), Why (Poignant guide, YAML, RedCloth)
- Artima’s Ruby Buzz Forum: Aggregated feed for a lot of Ruby bloggers.
Library & Applications Repositories
- Ruby Application Archive: More than a thousand projects across 200 categories. Nothing like learning about Ruby than reading lots of Ruby code.
- RubyForge: Hosts close to two hundred Ruby projects with CVS repositories and project management features. The place to publish your projects.
My favorite packages outside of the standard library
- Rake: Ant/make replacement for building and packaging projects. (See also the usage presentation)
- Log4r: Comprehensive logging package for needs that go beyond the simple Logger class in the standard library.
- DBI: Database abstraction layer. Run the same code on everything from MySQL and PostgreSQL to Oracle and DB2.
- MySQL: Native library for accessing MySQL through Ruby.
- FlexMock: Simple mock object for unit testing.
- RMagick: Wrapper for ImageMagick that makes image composition and altering a walk in the park.
- Madeleine: Object prevaylence port.
Jan
31
Long live FreeBSD
January 31, 2008 | 7 Comments
While Linux gets all the glory and commercial support, BSD derived operating systems such as FreeBSD chug away in the backrooms and datacenters of the world quietly processing HTTP and SMTP transactions. While it lacks funding and recognition, the FreeBSD community regularly updates and improves their OS, with a version 7 already in pre-release.
FreeBSD traces its roots to the Computer Systems Research Group at the University of California, Berkeley. Ten years of work have been put into enhancing BSD that includes adding SMP and multithreading support.
The new version 7 release due out in the summer of 2008 will distinguish itself with it’s performance abilities. It will support up to 8 CPU cores, the ZFS filesystem and 10 Gbs network support.
Staying true to it’s back office roots, these features will inevitably keep it out of the spotlight and a fringe community at best.
Dec
20
What happened to LXPages?
December 20, 2007 | 1 Comment
As you may or may not know. We’ve been building a Local Search service called LXPages.com. Don’t ask why it’s called LXPages, it just sounded right when we registered it. This was approximately 1 - 2 years ago, and it was live and kicking up until 2 days ago when we brought it down temporarily. We decided against renewing our data license with Acxiom and found a new data provider with better terms. As soon as we figure out how to re-import this new data into our old structure we’ll re-launch LXPages as well as InYellow.com. So stay tuned.
Dec
6
Gmail is ridiculous!
December 6, 2007 | 9 Comments
Don’t judge the article by it’s title… I meant ridiculous in a good way!. Gmail is the best webmail system on the Interne and nothing comes close to it. Yahoo and MSN has tried it all and every time they launch a new interface, it looks worse than the previous.
To top it all off, neither one got the “blogs” to give as much space as Google is giving. At the time of this writing the size of my Gmail space is 5526.745202 and it’s still incrementing!
This is ridiculous amount of disk space. I don’t even have that much space on my work PC!!






