Regular Expression To Check For Prime Numbers

The code is in python, but the concept is the same for any language with regular expression support (perl, sed, awk, vim, etc..)

1
2
3
import re
def is_prime(n):
        return re.match(r'^1?$|^(11+?)\1+$', "1" * n) == None;

That’s it :) using a regular expression we can check if a number is prime or not.

Here is a short explanation of why it works (though it will ruin the magic part):
› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, July 24th, 2010 Regular Expressions No Comments

Firefox Extensions To Make Web Pages More Eye Friendly

To understand what I’m talking about, take a look at Dr Chip’s Vim Website which is a great resource about vim-related stuff, but is an extremely ugly website, I mean, it really hurt my eyes whenever I visit it.

If you use Firefox, then you can easily solve this problem with these two Firefox extensions. Both serve the same purpose: Making websites easier to read, by removing distractions and allowing you to focus on the content instead. Each one displays the website in a different style, and they have different options. I installed both and use them alternately (and regularly).

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , ,

Sunday, July 18th, 2010 Firefox No Comments

Colorize Make, GCC and Diff’s Output

Generally, output is more readable when it has colors to allow you distinguish between warnings, errors and progress logs.

Using colormake, colorgcc and colordiff, you can have the output of make, gcc, diff (respectively) coloured.

To install in Ubuntu:

sudo apt-get install colorgcc colormake colordiff

You might want to use aliases to override the normal make/gcc/diff commands.

Original tip from here.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags:

Saturday, July 17th, 2010 Linux No Comments

Fix Bad Indentation When Pasting Text To Vim

The problem is this:

You’re editing a buffer in vim, you copy a text (say, code snippet) from another place (say, Firefox), and you paste it inside vim (with middle mouse button / shift+insert). Most chances you won’t like what vim has just did to your text.

The problem is that vim doesn’t “know” that you’re actually pasting a text, and it thinks that you’re typing. So, if you have indentation enabled, it will re-indent your text.

The solution is simple: Whenever you want to paste text from outside vim into vim. Type this in command mode:

:set paste

So now vim knows that you’re going to paste text, and it will not touch it.

To disable the paste mode:

:set nopaste

As easy as that ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags:

Friday, July 16th, 2010 Vim No Comments

NumPad Problems When Using Vim over Tmux

I use vim as my main text editor, and I usually split the screen to edit a few buffers in parallel. To make resizing the windows faster, I mapped the numpad keys “/*-+” to resize the windows (see original vim tip here).

Recently, I started to use tmux, and opened vim, split the windows as usual, and tried to resize them. It didn’t work :)

I use Ubuntu 10.04 (Don’t remember the exotic name..), and I found that the latest tmux package in their repo is 1.1-1.

Anyway, version 1.1-1 has a bug with the NumPad. The solution is to download the source of tmux 1.2 and build it. It depends on libevent so you’ll need to get it first:

this is how to make it work:

1. sudo apt-get install libevent-dev

2. Get the source tarball of tmux from here.

3. tar xzf tmux-1.2.tar.gz

4. cd tmux-1.2

5. ./configure

6. make

7. sudo make install

Done. Now your life is better. Have fun ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , , ,

Saturday, July 3rd, 2010 Vim 2 Comments

Online JavaScript Lint

In general, a lint is a great tool which saves hours of debug. It will find the syntax errors for you, and even give you warnings to avoid potential bugs.

I happened to write JavaScript this week, and found a great Online JavaScript Lint.  Use with care ;-)

Ah, and they also have a downloadable version.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Sunday, June 27th, 2010 Web Development No Comments

Backup Your Facebook Data

This post includes “Thoughts about Facebook and You”, and a link to a great tool to backup your Facebook data.

If you use Facebook, the first thing you should know is: Never trust these bastards! They don’t give a shit on your privacy, they want (and do) own YOUR data, they can “deactivate” your account without a warning, without an explanation, and even without a good reason.

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , , , ,

Wednesday, May 19th, 2010 Social Networks No Comments

Convert O’reilly Stand-Alone iPhone Books to epub Format

O’reilly are a great publisher of books related to technology/programming. They offer their books in a few formats besides the classic print. PDF, epub, or as a standalone iPhone App.
The great thing about the standalone option, is that it much cheaper than the epub or PDF version (why?). Still, you don’t want your iPhone screen full of book icons scattered everywhere (especially if you have a large number of books).
The trick is to buy the book @ AppStore as a standalone app, unpack it, pack it again as epub, and upload to any eReader (e.g. Stanza). Now you’ll have all your books centralized in one location, and you’ll keep free space on your screen for other applications.

Here’s how to do it:
› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Thursday, April 29th, 2010 iPhone 4 Comments

Vim Tip – Convert Code To HTML

If you wrote some elegant code, and want to publish it as a HTML page, you can easily do that in vim:
In command mode, type this:

:TOhtml

A new buffer will be opened with the HTML source, just save it:

:wq

If the original file name was “mycode.c”, you’ll find a new file in the same directory named “mycode.c.html”. Open it with your favourite web browser.

Wow, not?
Have fun ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, April 24th, 2010 Vim No Comments

Bash Tip – Separate a Bash Variable From Surrounding Letters

Sometimes, you might find yourself needing to concatenate the value of a bash variable with a string.
I think it’s best demonstrated with (a somewhat artificial) example:

1
2
3
y=h
echo $yome #won't work. will print the value of the variable "yome" which is a null string (since it's not set)
echo ${y}ome #works. will print "home"

That’s it, the trick is to use the curly brackets ${var} to separate the variable from its surrounding.

Have fun ;-)

source: @bashcookbook

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, April 24th, 2010 Bash No Comments
my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
July 2010
S M T W T F S
« Jun    
 123
45678910
11121314151617
18192021222324
25262728293031
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.