Linux

Re-mapping Keyboard Keys

Posted by admin on February 18, 2012  /   Posted in Linux

In Linux, it’s easy to remap one or more keys on the keyboard, in this article we’ll see how.

For remapping certain keys you need two tools: xev and xmodmap.

Start terminal window and run xev. Now it’s active and what’s for you pressing a key. Then press a key, it’s behavior you want to change. i.e. PgUp.

Notice the output of the terminal where you start xev from. You should see the following:

state 0x10, keycode 110 (keysym 0xff55, Prior), same_screen YES,

In this example Prior is the name of the action that the key is currently assigned to, remember the number after “keycode”, that’s the internal number for the key.

Now press another key i.e. PgDown, which should output:

state 0x10, keycode 115 (keysym 0xff56, Next), same_screen YES,

Remember the keycode number and the action name (Next in this case). Now let’s say you want to swap this both keys. Here we use the second program: xmodmap.

xmodmap -e "keycode 110 = Next"

This changes the action for the key with keycode 110 to “Next”. Do this for every keycode that you have remembered and apply any actions you wish.

NOTE: These change are for the current X session only and won’t survive a reboot. To do that, record all of the key mappings into a file called .Xmodmap using this command:

xmodmap -pke > .Xmodmap

Then enable this mapping from your .xinitrc (create one inside your home directory if you don’t have one already. Put this command in it:

xmodmap .Xmodmap

You’re done, now the new key mapping will be reactivated every time an X session is initialized for this user.

Android hacking the Linux-style

Posted by admin on April 19, 2011  /   Posted in Linux

Download adb by googling: “adb linux download”
It’s a tar file, untar it somewhere and make it an executable file.

If you’re like me, running 64-bit Linux, you have to install the missing 32-bit library required by adb manually:
For example:

apt-get install libc6-i386
apt-get install lib32stdc++6
apt-get install lib32ncurses5

TIP: use ldd /path/to/adb to see the list of the actual libraries required. Try to do this in Windows :)

Enabling the phone as a USB device.
Become UNIX root:

$vi /etc/udev/rules.d/50-android.rules

SUBSYSTEM==”usb|usb_device”, SYSFS{idVendor}==”0bb4″, MODE=”0660″, GROUP=”plugdev”
SUBSYSTEM==”usb|usb_device”, ATTR{idVendor}==”0bb4″, ATTR{idProduct}==”0c02″, SYMLINK+=”android_adb”
SUBSYSTEM==”usb|usb_device”, ATTR{idVendor}==”0bb4″, ATTR{idProduct}==”0c01″, SYMLINK+=”android_fastboot”


NOTE: The hexadecimal numbers above (0bb4:0c02) are the two-part ID of the phone when you use the lsusb command to list attached usb devices. It’s easy to recognize because the manufacturer and/or phone model should be listed along with the output.


$chmod a+r /etc/udev/rules.d/50-android.rules
$/path/to/adb devices  <-- this should tell you that the phone as been found
$/path/to/adb shell    <-- this will give you an actual UNIX shell

Now you can use adb to interact with your phone at system level, for example:

Backing up your sdcard is as simple as this:

./adb pull /sdcard/ /tmp/sdcard

If your phone has been rooted, you can do the following:

Always start by getting a root shell on the phone:

user@pc$ adb shell
$ su -
#

To remount /system read-write (adb remount):

# mount -o remount,rw /dev/block/mtdblock3 /system

To uninstall an application (adb uninstall):

# rm /system/app/PackageYouNoLongerWant.apk
# pm uninstall package.you.no.longer.want

To put a file somewhere other than the SD-card (adb push):
Put the file on the SD-card as usual.

# mv /sdcard/file /where/you/want/to/put/the/file

How can I download these gazillion links?

Posted by admin on October 06, 2010  /   Posted in Data Best Practices, Linux

Don’t you hate it when you find yourself needing to download hundreds of files, by clicking on each HTML link, one-at-a-time?

For example, some publishers decided that it is cute to chop their big document/manual/manuscript/research paper/etc. per chapter into their own PDF files.  Not too cute for us who wants to save them all, is it?

Or your ace graphic artist in the Philippines refused to learn Zip and has instead given you access to the directory containing hundreds of images that you need for tomorrow’s demo to the client.

I bet one of your first thought is to view the source of the web page and copy out all of the links, right? That would work, but it still involves a hunt-and-peck method fishing out all the links amidst the hairy HTML/CSS/JS code in the page.

Sure it’s easy if you are a UNIX command line hacker who can spit out the exact grep/awk/perl script to automate this in a heartbeat.  But in this journal we want an easier approach that most of us sophisticated (read: lazy) geeks would want to use.

Well, here is *one* easy way to solve this problem:

Use Firefox (version 3.6 at the time of this writing) and install a nifty add-on called Link Gopher.  After installation and a restart, down at the bottom right corner of the browser there will appear a small word called Links (next to the window resizer).

Go to the web page that listed all the links.

Right-click that Link word, and select Extract All Links. Voila! all of the links are now appear in a neat, clean web page.  Simply copy and paste all the links that you want to download into a text file, and run this command on a terminal:

cat links_list.txt | xargs -P 4 wget

This command will pipe the content of links_list.txt (that is the name of the file you saved the links into, by the way) into xargs, which in turn will fire off 4 parallel processes of ‘wget’ command, each being handed one of the links (NOTE: That -P parameter is pretty slick).

That’s it! now all you need to do is wait.  The output of wget processes downloading each link is also fun to watch.

When all the processes finished, you’d be left with all the files you need, and a text file containing the list of the file in URL format.  Now that’s pretty easy, wouldn’t you say?

Accessing Intranet Sites Remotely

Posted by admin on June 21, 2010  /   Posted in Data Best Practices, Linux

If you are like me, maintaining a server at home is like a hobby.  There is a certain satisfaction to be able to install whatever we like without having to ask for anybody’s permission.

And sometimes thanks to our tinkering, we discover good solutions that are applicable to the task given to us at work.  Think about it as giving our employers a bonus.

One of the most important rules in running a server is to never expose unnecessary information publicly.  Want an example? how about an obvious one, your router’s administration application.  This should never be accessible from outside of your home network for an obvious reason, obviously.

But the benefit of this approach is also its own downside.  Consider the following (highly likely) case:

You need to urgently change a setting on your router, while you are not at home.

Yep, you can’t.  Not without doing something extra anyways.

And that something extra is SSH tunneling.  Now, there are at least two ways that I know of on how to accomplish this.  For simplicity’s sake, let’s talk about one now:

If you are on a Windows machine, get yourself Putty and follow the steps on this website while replacing the forwarded port numbers with the one that you are trying to use.

http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html

Basically, you are telling Putty to tunnel port number x from a machine within your home network to port number y on the machine where you are working on.

So in the above example, to access your router’s admin application, you can setup the tunnel from port 80 on your router’s ip-address, to let’s say port 8080 on the local machine (where you are working from).

In the UNIX world, that translates into the following:

ssh -L 8080:your_router_ip:80 your_username@your_home_server.net

After successfully loggin into your home serve remotely, you can start a browser (on the machine where you’re working on currently), then go to localhost:8080 and voila! you’ll see your router’s administration application as though you are at home.

Pretty handy, eh?

Running GUI Linux programs in Windows

Posted by admin on June 03, 2010  /   Posted in Data Best Practices, Linux, Microsoft Windows

Now why on earth would you want to run GUI Linux programs on Windows?

If you were to ask me that a week ago, I would not be able to come up with a good business scenario.  Other than the fact that I did it at home, because my main computer is a Windows box and my development stuff is on my Linux server.

But at the moment I am stuck with an old laptop at work — which, being a good corporate laptop, of course is running Windows XP — because the giant four-letter computer company has messed up the shipment for my new computer.

So to make lemonade out of a lemon, I have enlisted two powerful free software that can get me out of this jam: PuTTY and Xming.

The idea is to use a powerful Linux machine to host and run the GUI programs that I need to work with from my very resource-limited old laptop (Pentium 4 Mobile with 512 MB, anyone?).

What applications? you say…

Let’s pick a big one, how about the Eclipse IDE.

Step one:

You install Xming and fire up XLaunch.  Out of the three modes that Xming offered: 1) multiple apps in one window, 2) each app running in a separate window, 3) fullscreen mode, mode 2 is one that works the best in this scenario.

So I went ahead and created an .xlaunch file that basically fired up Xming in the background, ready to accept X-window connections on the old laptop. NOTE: Don’t forget to check a box that says “No Access Control” otherwise your Linux application will be rejected when it tried to connect to Xming.

NOTE: Xming has a file called X0.hosts (that’s X and zero, not the letter ‘o’) which is usually located in the Xming install directory.  This file may need to be modified to include the IP address of the linux box.  But only if it connects to Xming via another network domain (other than the primary one).

For example, I setup a virtual linux guest on my windows 7 machine, the local network subdomain looks like 192.168.56.x unlike the default network domain which is 192.168.1.x.  The latter is where Xming waits for connections from.  Therefore I need to add 192.168.1.101 (the IP address of the linux machine) to the end of X0.hosts file (a line by itself), then Xming will work as expected.

A subnote, on my machine, windows 7 forces me to become administrator user to edit this file.  Although not as elegant as UNIX’s sudo command, the Switch User facility in windows makes this not as painful as it could have been.

Next, I fired up PuTTy.  I followed the steps to configure a PuTTy session that will allow X-forwarding and all that good stuff on this website.

Once you are connected to the Linux server, in which I already have downloaded the appropriate Eclipse distribution, ready to go.

All I need to do once I connected via PuTTy is:

  1. Set the DISPLAY environment variable to point to the laptop’s Xming instance: export DISPLAY=192.168.x.x:10.0 (the 192.168.x.x being the laptop’s internal IP address, of course).
  2. Run Eclipse IDE: ./eclipse &

And voila! Eclipse is running on the Linux server with every bit of its UI tunneled via X onto the old laptop.  Of course the performance depends on the network connection, but it is surprisingly snappy on a typical 100Mbps Gigabit Ethernet.  And I am talking about Eclipse loaded with a large project.

Now if this article does not make you run to the storerooms in the back and pull out those old laptops and give those out to your developers, I don’t know what else will :)

A Good IDE

Posted by admin on May 10, 2010  /   Posted in Data Best Practices, Linux

An IDE is a good idea.  If you as much as having the need to organize a couple of text files that you often write and change, you need one.

An Integrated Development Environment (IDE) is basically a multi-document text editor that assist you in managing a project.

Assist me how? you might ask.

Beyond reliably allowing you to edit your text files — be it your collection of barbecue recipes, love-letters, or your latest Cake PHP project — a good IDE should have the following features:

  • File-type recognition.  The IDE should be somewhat aware of what type of file you are editing.  The most popular file formats are a must, in my book, such as .html, .php, .java, .c, .py, .xml, .css, et cetera.
  • Syntax highlighting.  As part of the above feature, an IDE should highlight the common components of the said file type.   This is helpful especially when you are dealing with more than one type of files (typical if you are a software developer/web designer).
  • Auto-completion.  Another form of file-type recognition is to provide suggestions when we write a couple of letters.  For example, if I type “clearT”, the IDE should do a lookup for functions visible from the current code context and present it to me.  In this case, “clearThroat()” and “clearTupperware()” should be selectable.
  • Pair matching.  Pairs of what? Well, brackets, braces, HTML tags, multi-line comments, you name it.  Along with folding, this feature really makes figuring out your colleague’s code much easier.  Or your own code written six-months ago, for that matter.  Some IDEs out there go as far as auto-completing your brackets.  I find this annoying fifty-percent of the time, though.
  • Refined indentation control.  Try highlighting a few lines of code in a basic text editor like Gedit or Notepad and then hit the ‘Tab’ key.  If you are a developer, unconsciously you’d expect the highlighted lines to be indented.  Instead, you are rewarded with a blank space.  A good IDE also allows you to select between tabs and spaces.  I like spaces, four of them per indentation level.  No, not Fortran, Python.
  • Multiple-file Text Search. For you UNIX users, think of a built-in ‘grep’ command within the IDE.
  • Terminal/Console facility.  At the very least, a good IDE should have a way to execute compilers or other command-line tools that you may need to run your text file through.  At the most, an IDE can act as a GUI for your favorite application/web server.
  • Shortcut-keystrokes.  Preferably intuitive ones. As far as developer goes, I am an old-school, hands on keyboard, only reach for the mouse when needed -kinda guy.  I love shortcuts using key combinations.  They make tedious coding sessions a breeze.
  • Scriptable Macro Engine.  If you know even what this means, you have been coding long enough.  One of the “badges” of an veteran programmer is to be able to brag about how they wire their text editors to jump through hoops and play dead at their whim.  Yeah, nerdy; but in a good way.

Also, some features that are “nice-to-haves” like built-in graphical debugger, version control integration, or library-dependency manager.

In short, if an IDE does not do enough to relieve you from the most mundane editing tasks, then it’s useless.  On the other hand, if the IDE is so complicated to use that you’re losing hair trying to figure it out, it’s worse than useless.

A good IDE should be intuitive.  If I issued an Open file command from an active document, then I should be presented with the contents of that same directory.  Some editors I use always show me what’s on my home directory.

A Few Good IDEs

Now let’s take a look at some good IDEs out there.

  • Geany

This lightweight IDE runs on Linux and Windows. OS X and BSD users should be able to compile and run, in fact, I’d be surprised if there are not port install for it.

The lightweight-ness of this particular IDE cannot be stressed enough.  I am running it remotely inside Xming (an X-windows server for Windows) and I never noticed any performance hit at all.

Two things impressed me right of the bat:

1) it recognizes any file types I’ve thrown at it so far, and when I need to map a new file extension to an existing file format, I went to Tools > Configurations > filetype_extensions.conf.

It opened up the configuration file (formatted intuitively), add the new file extension, save and close, then Tools > Reload Configuration.  Done!

2) configurable shortcut-keystroke system, with defaults that make sense.  For instance, I can use Ctrl-PgDn to go to the next document on the right, Ctrl-PgUp to the left.  Just like how I navigate the tabs on Firefox. Very intuitive.

Most of the information that separates an IDE from an ordinary text editor is displayed on the lower panels.  Geany does not skimp on the  features.  As you can see below, the lower part of the IDE sports application status messages, compiler outputs, search outputs, a scribbling space, and a full blown terminal (or ‘console’ for you modern UNIX users):

A few features that I am missing: 1) a file browser/manager, 2) integration with souce-code version control systems such as SVN, 3) a scriptable macro engine.

Which, brings me to the last feature that I want to highlight.  Although billing itself as a lightweight IDE, the Geany developers are forward-thinking enough to embed a plugin infrastructure.  Perfect for implementing the ‘missing’ features I mentioned above.

It is my hope that as this IDE gets more popular, people would start writing plugins for it to make it even more powerful.  For now, I’m going to enjoy using it.

Lightweight GUI on Linux servers

Posted by admin on April 27, 2010  /   Posted in Linux

Background

By definition, a Linux server is designed to host long-running processes unattended.  It is the opposite of a Linux-based desktop environment.

Yet a lot of time you do need or miss the convenience of GUI tools when working on your Linux servers.  Or sometimes you use your Linux server as your development platform; and development tools, unless you’re a masochist, are typically GUI-based.

A relevant example would be in a setting where you and your co-workers need to connect to a cloud-computing instance.  Obviously you want the minimal GUI without having to clog the network with unnecessary eye-candy and “smooth-rounded edges” of the mainstream GUI, or maybe you just prefer minimalistic and quick-response over polish.   Either way, you can use this article as a stepping stone to join the fun.

NOTE: You can apply this to any modern UNIX system as long as you can get to the programs that we are discussing below.

As the world’s most flexible and (arguably) powerful OS, UNIX and its derivatives do not disappoint in this regard.  Discovering the right combination of so many good programs out there is a big part of the thrill of putting together an environment.

In this article, I’m using Ubuntu 9.10 (Karmic).  You can substitute almost 90% of apt-get command with yum if you’re using Fedora, or emerge for those of you Gentoo wizards.

First Part: Server-side setup

The reason I came across this exercise is a few months ago, I was upgrading my server to the latest Ubuntu release.  A power outage shutdown the server when it’s in limbo-mode, rather than trying to recover from the unknown state, I decided to went ahead and re-install Ubuntu from scratch and rebuild the server.

TIP: I was able to “wing-it” because I have done the due diligence of backing up my data, otherwise, I’d have way less hair to worry about when combing.

Anyways, on to the history lesson (a practice of using UNIX history command to learn a great deal about how to setup a server):
3  apt-get update
4  apt-get upgrade
5  apt-get install apache2
10  apt-get install mysql-server-5.0
11  apt-get install libapache2-mod-auth-mysql phpmyadmin
19  apt-get install lamp-server^
20  apt-get update
21  apt-get install openbox
22  apt-get install obconf
23  obconf
30  vi /etc/xdg/openbox/menu.xml

Here we start by a pristine Ubuntu server install, nothing on it, and we add to it the LAMP stack, which gives us Apache 2.x, MySQL, and PHP.

Next here’s the lightweight window manager: Openbox. It’s not only a window manager that can run on top of Gnome or KDE, it’s can also run as a stand alone session. And this is the path we’re going in this article, since our goal is to go lean.

Two words: 1) ~/.xinitrc and 2) openbox-session. Put the second one inside the first one; and the next time you start Xwindows you’ll be running Openbox. Like this:

Follow this thread for much more details and interesting aspects of Openbox.

Next, what file manager?…


We serve businesses of any type and size
Contact Us Today
500 Internal Server Error

500 Internal Server Error


nginx