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

Finding The Median Of Two Sorted Arrays

This is one of the beautiful cases where solving the general case first, and then applying it to a particular case is simpler and smoother than solving the particular case at once.

The problem:

Given two sorted arrays, “a” and “b”, with sizes “sa” and “sb” respectively, find the median of the union of these arrays.

Complexity requirements: O(log(sa + sb)) in the worst case, both time and space.

There are a few solutions for this problem, but non of them is as intuitive as the solution of a more general problem: The Select Problem:

Given two sorted arrays, “a” and “b”, with sizes “sa” and “sb” respectively, find the k-th smallest element of the union of these arrays. Under the same complexity requirements as above.

› Continue reading

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

Tags: , ,

Saturday, March 6th, 2010 Algorithms 1 Comment

Array Indexing in C

I found this interesting thing about array indexing in C somewhere in the web:
Suppose that “a” is an array. Then, a[5] and 5[a] are quivallent. Both are interpreted as *(5 + a) or *(a + 5) which is the same :)
Also: “Hello World”[3] and 3["Hello World"] are the same. Try and C ;)

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

Tags: ,

Wednesday, January 6th, 2010 Programming No Comments

Infinite zip File

A nice idea: How to build an infinitely recursive zip file. Details and resulting file here:
http://www.steike.com/code/useless/zip-file-quine/

Have fun ;-)

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

Tags: , , , ,

Saturday, December 12th, 2009 Cool Tricks No Comments

Blogging From BlackBerry

Posting from BlackBerry using WordPress app for BlackBerry.
You can install the application to your BalckBerry from here: http://blackberry.wordpress.org/install

Have fun ;)

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

Tags: , ,

Thursday, December 3rd, 2009 BlackBerry No Comments

Wisdom by Python (Easter Egg)

An easter egg by python displays a list of quotations, useful in programming and in many cases in life as well.

In your shell, type this:

1
python -c 'import this'

You’ll get this:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!

via commandlinefu

Have fun ;)

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

Tags: , ,

Monday, September 28th, 2009 Easter Eggs 1 Comment

Fix Facebook Chat in Firefox 3.5 (Shiretoko) in Ubuntu

Since I upgraded Firefox to 3.5 (Codename : Shiretoko), I noticed that Facebook chat does not work anymore, moreover, in order to get notifications for new events, I had to refresh the page manually.

After a search at Google, I found the problem, and the way to fix it: Looks like Ubuntu had decided to rename the user-agent into “Shiretoko” which is the codename of firefox 3.5, instead of “firefox”.

Because of the new user-agent name, Facebook does not recognize the browser as firefox, and thus disables some features that are browser dependent.

In order to fix the problem:

1. In the URI bar (that’s the place where you type the URLs of websites you want to visit), type “about:config” (without the double quotes).

2. Click the funny button “I’ll be carefull, I promise”.

3. Now look for “general.useragent.extra.firefox”, right click it, and choose “Modify”.

4. Instead of “Shiretoko”, type “Firefox”. (e.g. if you had “Shiretoko/3.5.4pre” it should become “Firefox/3.5.4pre”.

That’s it, now the world should be a better place ;)

via vimtips.

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

Tags: , ,

Sunday, September 27th, 2009 Firefox 5 Comments

Embed A Document Using Google Docs

You can embed a document viewer for any PDF or PPT using Google Docs.

You will get something similar to this:

The code I used for the above is:

1
<iframe src="http://docs.google.com/gview?url=https://agora.cs.illinois.edu/download/attachments/10456143/vim.pdf?version=1&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Or in general:

1
<iframe src="http://docs.google.com/gview?url=DOCUMENT_URL_HERE&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Where DOCUMENT_URL_HERE should be replaced by the document’s URL ;)

via Google Operating System.
Smile ;)

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

Tags: ,

Sunday, September 27th, 2009 Google No Comments

Re-Use A Bash Command With Different Parameters

Suppose you have typed and executed this command in your Linux shell:

1
./script_a.sh 1.23 && ./script_b.sh 1.23 && ./script_c.sh 1.23.45

Now you want to run the same command, but with 2.34 instead of 1.23
A nice way to do it is this:

1
!!:gs/1.23/2.34

Meaning, run the last command (!! is also called ‘bang bang’, and it’s substituted by the last command you executed), and replace every instance of 1.23 by 2.34

via Unix Bash Scripting.
Have fun ;)

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

Tags: ,

Sunday, September 27th, 2009 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.
September 2010
S M T W T F S
« Aug    
 1234
567891011
12131415161718
19202122232425
2627282930  
SEO Powered by Platinum SEO from Techblissonline

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