CARVIEW |
Archive: Linux
September 10, 2008
HOWTO - make a serial port IR receiver
Alessio Sangalli has been maintaining a guide for a few years that shows you how to create a serial port IR receiver from scratch and use it in both Windows and Linux. Her design is pretty slick since, as you can see from her photo above, the whole package fits neatly inside a standard 9 pin serial connector. There are still plenty of machines that don't have built-in IR support, so this could be handy if you're thinking of turning an old box into a media player or DVR.
How To Build A Simple But Cool IR (Infra Red) Receiver
Posted by Jason Striegel |
Sep 10, 2008 09:58 PM
Electronics, Home Theater, Linux, Windows |
Permalink
| Comments (1)
| TrackBack
| Digg It
| Tag w/del.icio.us
September 8, 2008
Run Google Chrome in Linux with Wine
If you're waiting impatiently for the native Linux release of Chrome, check out the instructions by Romeo Adrian Cioaba, who was able to get Chrome running on his Ubuntu box using Wine. The latest Wine release (1.1.4) contains a fix that corrects some rendering problems with the application, so make sure to upgrade first.
Most of the application is functional, except for HTTPS support. Unfortunately, according to the Wine wiki, this is because SSL support has only been stubbed in at this point. I can't say for sure if it'd work, but you could try copying the native Windows secur32.dll and crypt32.dll files into your Wine installation (assuming you can get your hands on them). There's a chance that there might be a few other incomplete libraries that you'll run into along this path, but if you get it to work, let us know.
Install Google Chrome on Linux using wine [via Lifehacker]
Posted by Jason Striegel |
Sep 8, 2008 08:43 PM
Google, Linux, Linux Desktop, Ubuntu |
Permalink
| Comments (1)
| TrackBack
| Digg It
| Tag w/del.icio.us
September 3, 2008
HOWTO - reset a lost Ubuntu password
I loaded one of my test Ubuntu virtual machines today (one that I hadn't used for a month) and, surprise, I had forgotten the password. This sort of thing happens from time to time, and if you're new to Linux, it can be a little disconcerting.
Losing your root password isn't the end of the world, though. You'll just need to reboot into single user mode to reset it. Here's how to do it on a typical Ubuntu machine with the GRUB bootloader:
Boot Linux into single-user mode
- Reboot the machine.
- Press the ESC key while GRUB is loading to enter the menu.
- If there is a 'recovery mode' option, select it and press 'b' to boot into single user mode.
- Otherwise, the default boot configuration should be selected. Press 'e' to edit it.
- Highlight the line that begins with 'kernel'. Press 'e' again to edit this line.
- At the end of the line, add an additional parameter: 'single'. Hit return to make the change and press 'b' to boot.
Change the admin password
The system should load into single user mode and you'll be left at the command line automatically logged in as root. Type 'passwd' to change the root password or 'passwd someuser' to change the password for your "someuser" admin account.
Reboot
Once your done, give the three finger salute, or enter 'reboot' to restart into your machine's normal configuration.
That's all there is to it. Now just make sure to write your password down on a post-it and shove it somewhere safe like under your keyboard. :)
Posted by Jason Striegel |
Sep 3, 2008 10:37 PM
Linux, Ubuntu |
Permalink
| Comments (14)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 27, 2008
Multitouch touch-pad support for Linux laptops
The Synaptics TouchPad device is a common input device for many laptop brands, including models made by Acer, Toshiba, and IBM. Normally, the touchpad is used for single-finger mouse input, but the Synaptics device has rudimentary support for tracking multiple fingers at the same time. Nathan Harrington wrote an article for IBM that shows you how to make use of this to add instant multitouch gesture support to your X applications.
A small perl script uses the synclient
command to listen to the touchpad and then send a message to the active window.
Using syclient output for monitoring the TouchPad state is a simple and effective way for adding further interface options to Linux applications. The gestureListener.pl program introduced below opens a pipe to read from the synclient program and processes the TouchPad events to detect gestures. These gestures are linked with keyboard commands sent to the current in-focus application in X Window System.
It's tricky, because you don't get a discrete x and y location for each finger. Instead, synclient gives you an average of the inputs, and a count of the number of inputs. It makes detecting a pinch gesture difficult, but Nathan noticed that two fingers at the corners of the pad average to a stable location, while the average location of two fingers near each other tends to wiggle. Using this, he was able to hack together semi-reliable pinch and open-pinch gestures.
With the script installed, you can open any X application and swipe three fingers to the left or right to trigger a left or right keypress. The pinch and open-pinch gestures will trigger a + or - to be sent to the application.
Add multitouch gesture support to a TouchPad-equipped laptop
Posted by Jason Striegel |
Aug 27, 2008 06:51 PM
Linux, Linux Desktop |
Permalink
| Comments (0)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 26, 2008
Dealing with large numbers of files in Unix
Most of the time, you can move a bunch of files from one folder to another by running a simple mv command like "mv sourcedir/* destdir/
". The problem is that when that asterisk gets expanded, each file in the directory is added as a command line parameter to the mv command. If sourcedir contains a lot of files, this can overflow the command line buffer, resulting in a mysterious "Too many arguments" error.
I ran into this problem recently while trying to manage a directory that had over a million files in it. It's not every day you run across a directory that contains a metric crap-ton of files, but when the problem arises, there's an easy way to deal with it. The trick is to use the handy xargs program, which is designed to take a big list as stdin and separate it as arguments to another command:
find sourcedir -type f -print | xargs -l1 -i mv {} destdir/
The -l1 tells xargs to only use one argument at a time to pass to mv. The -i parameter tells xargs to replace the {} with the argument. This command will execute mv for each file in the directory. Ideally, you would optimize this and specify something like -l50, sending mv 50 files at a time to move. This is how I remember xargs working on other Unix systems, but the GNU xargs that I have on my Linux box forces the number of arguments to 1 any time the -i is invoked. Either way, it gets the job done.
Without the -i, the -l parameter will work in Linux, but you can no longer use the {} substitution and all parameters are placed as the final arguments in the command. This is useless for when you want to add a final parameter such as the destination directory for the mv command. On the other hand, it's helpful for commands that will end with your file parameters, such as when you are batch removing files with rm.
Oddly enough, in OS X the parameters for xargs are a bit wonky and capitalized. The good news is that you can invoke the parameter substitution with multiple arguments at a time. To move a bunch of files in OS X, 50 files at a time, try the following:
find sourcedir -type f -print | xargs -L50 -I{} mv {} destdir/
That's about all there is to it. This is just a basic example, but once you get used to using xargs and find together, it's pretty easy to tweak the find parameters and move files around based on their date, permissions or file extension.
Posted by Jason Striegel |
Aug 26, 2008 07:22 PM
Linux, Linux Server, Mac |
Permalink
| Comments (5)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 22, 2008
The smallest program ever
Brian Raiter wrote an article many years ago in which he documented his quest to make the smallest possible Linux ELF executable, a stripped-down program that returns the answer to life, the universe, and everything.
While the standard gcc-compiled version of the application nets out at 3998 bytes, Brian discovered that the smallest possible size for an ELF executable that will still run correctly is 45 bytes:
This forty-five-byte file is less than one-eighth the size of the smallest ELF executable we could create using the standard tools, and is less than one-fiftieth the size of the smallest file we could create using pure C code. We have stripped everything out of the file that we could, and put to dual purpose most of what we couldn't.Of course, half of the values in this file violate some part of the ELF standard, and it's a wonder than Linux will even consent to sneeze on it, much less give it a process ID. This is not the sort of program to which one would normally be willing to confess authorship.
It's not an easy process creating the smallest possible program. To get there, you need to dissect the inner workings of the operating system and the ELF file format, which is really what the article is about. If you've ever wondered about the mysterious events that happen before main() and after return(), here's your chance to take the red pill.
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
Posted by Jason Striegel |
Aug 22, 2008 05:55 PM
Linux, Software Engineering |
Permalink
| Comments (2)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 20, 2008
Text-to-speech in PHP
It's been a while since I've played with the open source Festival TTS software, and I'm pretty impressed with the quality of the speech output. Some of the voices that are available sound so much better than the old diphone-based voices that evoke WOPR from War Games.
This got me thinking it'd be fun to integrate some of this functionality into a web application. A quick search and I discovered Tony Bhimani's Linux Text-To-Speech Tutorial which has a sample PHP application that uses the Festival text2wave utility and the lame mp3 encoder to produce mp3 files from user submitted text.
I mentioned that some of the voices are pretty outstanding. In particular, the "unit selection" voices, demonstrated on the Festival demo page, are able to synthesize a lot of sentences with few noticeable glitches. These voices sound so nice because they contain a much larger database of common sound units, only falling back on heavy processed output on less common utterances. There's a howto and discussion over on Ubuntu Forums that'll guide you through installing and using the more enhanced voices with Festival. With a decent voice file, Festival, and an adaptation of Tony's PHP text-to-speech demonstration, it wouldn't be too hard to add audio output to your blog or create a script that turns your RSS feeds into a podcast for the daily commute.
Have any of your own text-to-speech ideas or demos? Please share them in the comments!
Tony Bhimani - PHP Text-To-Speech Example
The Festival Speech Synthesis System
HOWTO: Make Festival TTS Use Better Voices
Posted by Jason Striegel |
Aug 20, 2008 09:57 PM
Linux, Linux Multimedia, Podcasting, Web |
Permalink
| Comments (1)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 18, 2008
Beagle Board - ultra tiny, 2-Watt Linux system
Hackszine pal Patti Schiendelman tipped me off to the Beagle Board, a spartan little embedded platform, perfect for all things hackable. It's based on the TI OMAP3 processor, which is packaged with 128MB of DDR RAM and 256MB of NAND Flash all on the single chip in the center of the board.
Instead of including things like ethernet and 802.11 on-board, they opted to keep the footprint small and only include the bare essentials: DVI for monitor output, SD/MMC for storage, audio in/out, and USB for device expansion. If you need any other hardware, just get a USB device that has a Linux driver.
Did I mention it's $150 and draws less that 2 Watts? This is definitely what you need for your next autonomous spy weather blimp.
BeagleBoard.org
BeagleBoard Embedded Linux Wiki
Linux Journal - The BeagleBoard: $149 Linux System
Posted by Jason Striegel |
Aug 18, 2008 09:06 PM
Electronics, Hardware, Linux, Ubuntu |
Permalink
| Comments (1)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 9, 2008
Edit binary files in Vi
If you've ever wanted to examine or edit a binary file in your favorite text editor, there's an easy way to simulate a vi hex mode. To do this, you just filter the file's contents through the xxd
hex dump utility, a trick that can be accomplished right within the vi/vim interface.
To convert a file to hex dump representation, just load your file in vi and type the following:
:%!xxd
This sends the entire contents of the opened document to xxd and loads in the result. At this point, you can view or edit any of the hex data. The ASCII representation is listed to the right, though editing this region will not affect the hex portion of the file.
When you are done, you'll want to convert things back into their binary format before saving. To do this, you run things through xxd again, but this time with the -r option:
:%!xxd -r
Your file should be returned to illegible gibberish, which you can save back out with :wq
.
A funny thing I just noticed: OS X binaries all start with the same 4 bytes which, in hex, spell out the phrase "cafe babe". This is just a magic number used to identify the file as an OS X binary, but it's hard not to ascribe some deeper meaning. ;)
Posted by Jason Striegel |
Aug 9, 2008 10:00 PM
Linux, Mac |
Permalink
| Comments (5)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 6, 2008
Memcached and high performance MySQL
Memcached is a distributed object caching system that was originally developed to improve the performance of LiveJournal and has subsequently been used as a scaling strategy for a number of high-load sites. It serves as a large, extremely fast hash table that can be spread across many servers and accessed simultaneously from multiple processes. It's designed to be used for almost any back-end caching need, and for high performance web applications, it's a great complement to a database like MySQL.
In a typical environment, a web developer might employ a combination of process level caching and the built-in MySQL query caching to eke out that extra bit of performance from an application. The problem is that in-process caching is limited to the web process running on a single server. In a load-balanced configuration, each server is maintaining its own cache, limiting the efficiency and available size of the cache. Similarly, MySQL's query cache is limited to the server that the MySQL process is running on. The query cache is also limited in that it can only cache row results. With memcached you can set up a number cache servers which can store any type of serialized object and this data can be shared by all of the loadbalanced web servers. Cool, no?
To set up a memcached server, you simple download the daemon and run it with a few parameters. From the memcached web site:
First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you'll likely use:
# ./memcached -d -m 2048 -l 10.0.0.40 -p 11211
This starts memcached up as a daemon, using 2GB of memory, and listening on IP 10.0.0.40, port 11211. Because a 32-bit process can only address 4GB of virtual memory (usually significantly less, depending on your operating system), if you have a 32-bit server with 4-64GB of memory using PAE you can just run multiple processes on the machine, each using 2 or 3GB of memory.
It's about as simple as it gets. There's no real configuration. No authentication. It's just a gigantor hash table. Obviously, you'd set this up on a private, non-addressable network. From there, the work of querying and updating the cache is completely up to the application designer. You are afforded the basic functions of set, get, and delete. Here's a simple example in PHP:
$memcache = new Memcache; $memcache->addServer('10.0.0.40', 11211); $memcache->addServer('10.0.0.41', 11211);$value= "Data to cache";
$memcache->set('thekey', $value, 60);
echo "Caching for 60 seconds: $value <br>\n";$retrieved = $memcache->get('thekey');
echo "Retrieved: $retrieved <br>\n";
The PHP library takes care of the dirty work of serializing any value you pass to the cache, so you can send and retrieve arrays or even complete data objects.
In your application's data layer, instead of immediately hitting the database, you can now query memcached first. If the item is found, there's no need to hit the database and assemble the data object. If the key is not found, you select the relevant data from the database and store the derived object in the cache. Similarly, you update the cache whenever your data object is altered and updated in the database. Assuming your API is structured well, only a few edits need to be made to dramatically alter the scalability and performance of your application.
I've linked to a few resources below where you can find more information on using memcached in your application. In addition to the documentation on the memcached web site, Todd Hoff has compiled a list of articles on memcached and summarized several memcached performance techniques. It's a pretty versatile tool. For those of you who've used memcached, give us a holler in the comments and share your tips and tricks.
Memcached
Strategies for Using Memcached and MySQL Better Together
Memcached and MySQL tutorial (PDF)
Posted by Jason Striegel |
Aug 6, 2008 10:37 PM
Data, Linux, Linux Server, MySQL, Software Engineering |
Permalink
| Comments (1)
| TrackBack
| Digg It
| Tag w/del.icio.us
August 4, 2008
Shield your files with Reed-Solomon codes
Thanassis Tsiodras wrote in about a utility for adding additional error correction redundancy to your backup data:
The way storage quality has been nose-diving in the last years, you'll inevitably end up losing data because of bad sectors. Backing up, using RAID and version control repositories are some of the methods used to cope ; here's another that can help prevent data loss from bad sectors. It is a software-only method, and it has saved me from a lot of grief.
The technique uses Reed-Solomon coding to add additional parity bytes to your data. If you suffer partial damage to the storage media, these files can still be recoverable.
Storage media are of course block devices, that work or fail on 512-byte sector boundaries (for hard disks and floppies, at least - in CDs and DVDs the sector size is 2048 bytes). This is why the shielded stream must be interleaved every N bytes (that is, the encoded bytes must be placed in the shielded file at offsets 1,N,2N,...,2,2+N,etc): In this way, 512 shielded blocks pass through each sector (for 512 byte sectors), and if a sector becomes defective, only one byte is lost in each of the shielded 255-byte blocks that pass through this sector. The algorithm can handle 16 of those errors, so data will only be lost if sector i, sector i+N, sector i+2N, ... up to sector i+15N are lost! Taking into account the fact that sector errors are local events (in terms of storage space), chances are quite high that the file will be completely recovered, even if a large number of sectors (in this implementation: up to 127 consecutive ones) are lost.
The application works similar to any other command line archiving utility, so you can tar your files as normal and then send them to the freeze.sh script. Running melt.sh on the archive will return your original data, even if there was a reasonable amount of corruption to the file. Thanks, Thanassis!
Hardening your files with Reed-Solomon codes
Posted by Jason Striegel |
Aug 4, 2008 10:04 PM
Data, Linux |
Permalink
| Comments (0)
| TrackBack
| Digg It
| Tag w/del.icio.us
July 16, 2008
Improve Linux laptop performance with Ramlog
One of the most power-hungry components in a traditional laptop is its hard disk, and time between charges can be greatly improved by keeping the disk in sleep mode. On machines like the OLPC that have solid-state disks, keeping disk writes to a minimum improves the life of the drive, minimizing unwritable sectors. Depending on how your machine is configured, log activity from kernel events and running daemons like sshd, a dns cache, or a local copy of apache can force your disk to make tiny writes every few minutes, impacting flash drive lifetime and ensuring that a mechanical drive never sleeps.
One solution to the problem is to disable syslogd entirely. An alternative is Ramlog, which offers a bit of a compromise. With Ramlog installed, log data is stored in RAM until shutdown, when it's copied back to disk in one big write. You will loose your logs if you have a system crash, but in a more usual scenario where you're trying to track down a wireless problem or an apache error on your development laptop, the logs are there for you to examine.
Installing Ramlog [linux.com]
Ramlog downloads
Posted by Jason Striegel |
Jul 16, 2008 09:11 PM
Linux, Ubuntu, olpc |
Permalink
| Comments (0)
| TrackBack
| Digg It
| Tag w/del.icio.us
July 13, 2008
Find and Grep 101
Find and Grep are perhaps the most used command line tools for the Linux user or administrator. Terse but powerful, these two commands will allow you to search through files and their contents by almost any imaginable attribute or filter criteria: file name, date modified, occurrence of the some specific word in a file, etc. Combined with a couple of other standard unix utilities, you can automate and process modifications over a number of files that match your search.
Here are two blog posts by Eric Wendelin which nicely illustrate the basics of these two commands:
Find is a Beautiful Tool
Grep is a Beautiful Tool
There are a number of other great unix utilities for file search, but knowing how to use find and grep is fundamental, as these two utilities can be found on the most basic build of every unix-like machine you come across.
Got a favorite command line hack that uses find or grep? Drop it on us in the comments.
Posted by Jason Striegel |
Jul 13, 2008 09:19 PM
Linux, Linux Server, Ubuntu |
Permalink
| Comments (3)
| TrackBack
| Digg It
| Tag w/del.icio.us
June 15, 2008
Home security with Twitter and a webcam
Shantanu Goel created a cool home security tool using Twitter and a linux application called Motion, a program that will monitor a webcam looking for differences between frames.
When Motion detects movement, it archives a photo of the event and has the option of triggering an external script. Shantanu combined this with a simple curl command that will ping your Twitter account when a motion event occurs. The end result is a tweet that tells you that motion was detected and checking Motion's integrated mini-http server will allow you to see if it's a false alarm or view the intrusion in real time.
I'm going to set this up at work so I can track down who keeps running off with my red stapler.
Keep Tab On Home Security With A Webcam And Twitter
Motion
Posted by Jason Striegel |
Jun 15, 2008 09:04 PM
Home, Linux |
Permalink
| Comments (2)
| TrackBack
| Digg It
| Tag w/del.icio.us
June 4, 2008
Use video RAM as swap in Linux
If you are into the headless or console experience, there are a couple of ways to put your machine's graphics card to good use. Most new boxes come with a GPU that has a substantial amount of RAM that is normally used for direct rendering. Using the Memory Technology Device (MTD) support in the Linux kernel, you can actually map the video card RAM to a block device and format it for swap use or as a ramdisk.
The Gentoo wiki has detailed instructions for doing this. The only tricky part is determining the video memory address, but after that it's a simple modprobe to load the MTD driver and you can run mkswap/swapon on the device just as if you were creating a normal swap disk. Considering many machines have 512MB of video RAM and it's waaaaay faster than disk, this could give you a pretty huge performance boost.
You can still use your graphics card in X, but you'll need to reserve a small chunk of that RAM for normal graphics use, use the VESA driver, and add inform the driver that it should only use that teensy portion of memory. "VideoRam 4096" in the XF86Config, for instance, will let you use your card in X and only eat the first 4MB of RAM. Everything after that 4MB is fair game for swap. Michal Schulz wrote a bit about calculating the memory address offsets to make this all work. It's the second link below, for those of you who aren't hardcore enough to deal with only the command line.
Use Memory On Video Card As Swap
Configuring X11 With A VRAM Storage Device
Posted by Jason Striegel |
Jun 4, 2008 09:10 PM
Linux, Linux Server |
Permalink
| Comments (0)
| TrackBack
| Digg It
| Tag w/del.icio.us
Bloggers
Welcome to the Hacks Blog!
Categories
- Ajax
- Amazon
- AppleTV
- Astronomy
- Baseball
- BlackBerry
- Blogging
- Body
- Cars
- Cryptography
- Data
- Design
- Education
- Electronics
- Energy
- Events
- Excel
- Excerpts
- Firefox
- Flash
- Flickr
- Flying Things
- Food
- Gaming
- Gmail
- Google Earth
- Google Maps
- Government
- Greasemonkey
- Hacks Series
- Hackszine Podcast
- Halo
- Hardware
- Home
- Home Theater
- iPhone
- iPod
- IRC
- iTunes
- Java
- Kindle
- Knoppix
- Language
- LEGO
- Life
- Lifehacker
- Linux
- Linux Desktop
- Linux Multimedia
- Linux Server
- Mac
- Mapping
- Math
- Microsoft Office
- Mind
- Mind Performance
- Mobile Phones
- Music
- MySpace
- MySQL
- NetFlix
- Network Security
- olpc
- OpenOffice
- Outdoor
- Parenting
- PCs
- PDAs
- Perl
- Philosophy
- Photography
- PHP
- Pleo
- Podcast
- Podcasting
- Productivity
- PSP
- Retro Computing
- Retro Gaming
- Science
- Screencasts
- Security
- Shopping
- Skype
- Smart Home
- Software Engineering
- Sports
- SQL
- Statistics
- Survival
- TiVo
- Transportation
- Travel
- Ubuntu
- Video
- Virtualization
- Visual Studio
- VoIP
- Web
- Web Site Measurement
- Windows
- Windows Server
- Wireless
- Word
- World
- Xbox
- Yahoo!
- YouTube
Archives
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
Recent Posts
- Super GreaseMonkey - your favorite Firefox plugin meets jQuery
- HOWTO - create a see-through information graphic
- HOWTO - make a serial port IR receiver
- All AJAX image editor
- Run Google Chrome in Linux with Wine
- DIY photography speed strap
- Write a Hadoop MapReduce job in any programming language
- Read Excel files in Perl and PHP
- Objective-J and Cappuccino released
- HOWTO - reset a lost Ubuntu password
www.flickr.com
|
Most read entries (last 30 days)
- HOWTO - reset a lost Ubuntu password
- LED security camera disruptor
- Change the message on HP printers
- HOWTO: Reset a lost OS X password
- Using an optical mouse for robotic position sensing
- HOWTO - Read/Write to NTFS drives in OS X
- Unbrick or downgrade any PSP
- HOWTO - Install Ubuntu on the Asus Eee PC
- Make a cheap Xbox 360 Wireless Adapter with DD-WRT
- Free airport WiFi
- Using Google as a Proxy (or HOW TO: View MySpace at School)
- T-Zones and iPhone: the $5.99 data plan
- Star Wars music played by a floppy drive
- Play MS-DOS Games on Vista
- Pocket PC iPhone conversion
© 2008 O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on makezine.com are the property of their respective owners.
Recent comments