tips

Duck Duck Go – My new search engine

Posted in duckduckgo, find, tips on May 22nd, 2010 by fseek – 13 Comments

I was lately looking for a better search engine to use (can’t stand Google anymore) and I recently found one that I really liked: http://duckduckgo.com. Yes, funny name, but they have the features that I was looking for:

  • Privacy -Your searches are private! I don’t need to say more
  • It looks at Sourceforge and other software repositories and show its results first (perfect for FOSS users).
  • Good categorization
  • Awesome for searching C functions! (details later)

Awesome, no? And no, I am not making any money from them, I just loved the product. Now, to the searches. Let’s compare a few of them with Google.

Let’s search first for “tux+racer” on Duck Duck go (I was looking for it this morning):duck duck go

Very good description from Wikipedia at the top, describes what Tux is and categorizes it properly under the open source video game. In the “feeling ducky”, it sends to the download page. Perfect! Now search for it on Google… It shows the right results, but without any good description and too much cluttered.

Now, that’s what I loved. Search for “fseek” (or any C function). DDG beats Google easily…It shows that “fseek is a C function belonging to the ANSI C standard library, and included in the file stdio.h”, links to the C++ library reference, and if you go to their categorization, you will see everything about related C functions. Awesome! On Google, they just point a bunch of man pages…
Duck Duck and Go
That’s what sold me. If you like it too, they even have a spread page if you want to help them out: http://duckduckgo.com/spread.html

Finding lasted modifies files on Linux

Posted in find, linux, tips on May 13th, 2010 by fseek – Be the first to comment

Looking for a file that you just modified or downloaded? That’s the easy way:

1- Files modified in the last 5 minutes:

$ find ./ -type f -mmin -5

 
2- Files modified in the last hour:

$ find ./ -type f -mmin -60

 
3- Files modified in the last day:

$ find ./ -type f -mtime -1

 
If you want to process them and they have spaces in the name, use:

$ find ./ -type f -name “*.txt” -mtime -1 -print0 | xargs -0 cat

 
This one will cat all text files modified on the last day (with spaces or not in the name).

Removing empty lines from the top of a file

Posted in linux, tips on May 4th, 2010 by fseek – Be the first to comment

Nice one liner:

find ./ -type f | sed -i ‘/./,$!d’

Recovering deleted files on Linux

Posted in linux, tips on April 28th, 2010 by fseek – 5 Comments

Did you just rm’ed -rf a file by mistake? Well, that just happened to me as well.

I spent the whole day working on a PDF document and decided to forward it to a co-worker for review. Since the PDF was quite big, I gunzipped it:

$ gzip work-temp.pdf

Then I realized that my co-worker uses Windows, so I had to zip instead of the gzip. That’s what I did:

$ rm work-temp.pdf.gz
$ zip work-temp.pdf
zip warning: name not matched: work-temp.pdf

Uh-oh. I forgot that gzip deletes the original file. Crap!

To recover my file, I used my big friend “foremost”, a file recoverer for Linux. To install on my Ubuntu box, I did:

# apt-get install foremost

To recover my files, I ran foremost, specifying my partition (/dev/sdb2) and the file type (PDF):

# foremost -s 100 -t pdf -i /dev/sdb2
Processing: /dev/sdb2
|**********************************|

Once it was done, we had all the PDF files it could recover at /root/output/pdf. Easy and simple!

Note, that it will not recover the original file names. So all the PDF files (or whatever file type you were looking for) will be stored as /root/output/pdf/12345.pdf, /root/output/pdf/123456.pdf, etc). You will have to check each one to find the one you wanted.

Mail function missing – Wordpress error

Posted in tips, wordpress on April 27th, 2010 by fseek – 1 Comment

Are you getting this error when trying to reset a password (or send an email) on Wordpress?

The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function…

If you are on a VPS/Private server, it probably means that you don’t have mail/sendmail installed. To fix it, run as root:

# yum install mailx
# yum install sendmail

If you are not on a VPS, call your hosting company or check your php.ini to see if the mail function is disabled:

disable_functions = mail

If it is, disable the “mail” from there…

backtweets is awesome!

Posted in tips, twitter on March 24th, 2010 by fseek – Be the first to comment

I don’t know how I missed it for so long, but http://backtweets.com is really awesome.

backtweet

Why is it awesome? One of the biggest drawbacks of having short urls on twitter is that you can’t search for tweets referencing your domain. And just this week I was trying to see who mentioned this site on twitter, when I found their service. Very simple concept and very well done (note that this is not a paid post, I just really liked it).

This is the output when I searched for fseek.me:
backtweet

One problem that I noticed is that some links were missing, but very few of them. I guess they monitor the twitter stream (for everyone), so missing a few tweets is expected.

Search and replace inside a MySQL database

Posted in mysql, tips on March 13th, 2010 by fseek – 3 Comments

Have you ever wanted to modify multiple rows and tables inside your MySQL database? We have a simple way to do it.

Well, yesterday I had to modify in one of our databases (a big one), every occurrence of an email address (contact@company.com) to another one (sales@company.com). Doing that via our web interface would take a long time, so I did the simple way:

1- Backup your MySQL database using Mysqldump

$ mysqldump -u dbuser -pdbpass dbname > dump.sql

Now we have our database backed up at dump.sql

2- Search and replace inside your MySQL dump

We did this very easily with sed to replace “contact” for “sales”. Just change for whatever values you want to replace.

$ cat dump.sql | sed ’s/contact@company/sales@company/gi’ > dump-fixed.sql

Note that we did a case insensitve search for contact@company.com and replace that with the sales address. Also, we used the “g” modifier to apply to all cases (not the first one in the line).

3- Restore your database using the modified dump

$ mysql -u dbuser -pdbpass dbname < dump-fixed.sql

Yes, it was that simple. No more running a bunch of INSERTS, DELETES, ALTER tables, etc…

Tunnel HTTP traffic through SSH

Posted in desktop, tips on March 6th, 2010 by fseek – Be the first to comment

This is more a note to self, since every time I have to google for it.

If you want to tunnel some HTTP traffic (SOCKS) through SSH, on the client box, run:

$ ssh -D 8881 user@server

This will dynamic forward everything from the local port 8881 to the SSH server. Now go to firefox (inside edit->preferences->Advanced->Network->Settings ) and configure the SOCKS proxy to use 127.0.0.1 and port 8881. That’s all!

Generating a photo gallery on Linux

Posted in desktop, linux, tips on March 5th, 2010 by fseek – Be the first to comment

Looking for a quick way to create a HTML photo gallery on Linux? That’s how I did it.

I have a small child and my wife asked (err tasked me) to create a web site with his pictures. I didn’t want to host his pictures on picasa or flickr, so I used a simple Unix tool to create an HTML gallery and posted it on my on site.

The tool? jigl. Perl-based, command-line and very easy to use. To install on Ubuntu, I just did:

# apt-get install jigl

To create the gallery, you just need to run the command and specify a directory. For example:

$ jigl /home/me/pics/1yo

And it will create the gallery inside /home/me/pics/1yo/web/ . Note that the default theme and options are a bit ugly, so I decided to download the white theme (much better) and ran it with some extra options to reduce the noise from the final HTML:

$ cd /home/me/.jigl/themes/
$ wget http://xome.net/projects/jigl/themes/white-theme.tar.gz
$ tar -zxvf white-theme.tar.gz
$ cd /home/me/pics
$ jigl –theme white -it “My babys pics” -noskb -nosxy -nogi 1yo

There is an example of the white theme here: http://xome.net/projects/jigl/themes/white/

Hope you like!

Mass search and replace with sed and grep

Posted in programming, sed, tips on March 4th, 2010 by fseek – 2 Comments

Ever had to search and replace a string in multiple files? That’s how to do it with grep and sed

Today at work I was tasked to upgrade the copyright statement on all our PHP, HTML and C files from 2009 to 2010. Plus, it had to be done only on the files that we owned the copyright. That’s how I did:

1- Search for all the files that we own the copyright

$ cd /source
$ grep -r “Copyright OurComapany Inc” *

It will print all files that match our copyright, so we know at least what files we are changing.

2- Search and replace all these files

$ grep -r “Copyright OurComapany Inc” * | cut -d “:” -f 1 | sort | uniq | xargs sed -i ’s/Copyright 2009/Copyright 2010/’

With this command, we will run “sed” to replace the string 2009 to 2010 on all the files that matched our copyright stement. If you wanted to replace all the files, just the following would work:

$ find ./ | xargs sed -i ’s/Copyright 2009/Copyright 2010/’