Ole Bakstad

Where god does not play dice.

Google Tech Talk: Java Puzzlers

Tobias found this cool Google Tech Talk about Advanced Topics in Programming Languages: Java Puzzlers.

The puzzles are sometimes very non-intuitive, and is mostly results of bad API's or other strange features. Some of the puzzles aren't very useful, but it's always nice to have a deep understanding of a programming language.

Watch the talk a YouTube:

Posted in Java, Programming, Tips & Hints | No comments
Tags: , , , , , ,

Learn Python in 10 minutes

My friend He Yu provided me with a link where you can learn Python in 10 minutes. A nice introduction to Python assuming that you know general programming.

I'm looking into Python for two reasons. One; I want to expand my knowledge of programming languages. Two; Next term I'm taking the course Introduction to Algorithms where Python is the language we will be using. It's always nice to have a head start.

Update:

It turns out that the professor teaching the course has written books about Python and also written a short tutorial. Click here for tutorial.

Posted in Programming, Python, Tips & Hints | No comments
Tags: , , ,

How to use and write snippets

In TextMate and in gedit (probably more editors too) you have the option to use snippets. I love snippets, and they make my day much easier.

To make a snippet you have to define a tab-trigger which is a word or a random sequence of characters that you will remember. Then you have to write the snippet body.

Easy example: If and else statements. When you write "ife" and press tab you want an if-else statement to pop up. We write the snippet:

if($1)
{
    $2
}
else
{
    $0
}

$0, $1 and $2 are where the cursor will be placed. When you first type "ife" and press the tab button the cursor will be where the $1 is. If you hit tab again the cursor moves to $2 and so on, but you always ends up at $0. Now you can use this snippet whenever you need it. Just write "ife" press tab and fill inn the code you need.

More advanced example: Lets say you are getting tired of writing all the code for a for loop every time you need one. Make a snippet!. We set the tab-trigger to be the string "for" and write the snippet:

for (\$${1:i}=${2:0}; \$${1:i} < $3; \$${1:i}++)
{
    $0
}

What the ${1:i} does is that it sets the 1st cursor position and sets a default value ("i" in this case). The default value is marked, so when you tab to the position you can immediately overwrite the default text. And an other thing in this example worth mentioning is that we use ${1:i} more than once. This enables you to change the default at more than one place at once. Let's say you don't want your variable called "i", but "index". You still just write "for", press tab, and "i" is marked. You now write "index", and the "i" in all 3 places where it's used will change to "index". Then tab again to set the start value of the for loop, and yet again to set the max value for the loop. After choosing variable name, start value and max value you just have one tab left. The last tab brings to you $0 and you're ready to write some code inside the for loop. If you tab one more time while the cursor is at $0 the tab sequence will start over.

Posted in Programming, Tips & Hints | One comment
Tags: , , , ,

gedit + plugins = \o/

I've been looking for good editor for Ubuntu for a while, and I think I found it.  After reading Micah Carrick's post on Customizing gedit as a Web Developer’s IDE I was amazed how much gedit with plug-ins could do. It almost have anything I want in an editor. I don't know if I would call it an IDE though. Missing debugging and CVS/SVN is kinda important in an IDE. There are debugging plug-ins for Perl and Python, but not for PHP, Java and JS (which is the languages I mostly use).

Personally I like the same preferences that Micah uses. I enable indent with 4 spaces, turn of line wrapping and enable line numbering. Read a more detailed description in Micah's post.

Plug-ins I use:

- Gemini
A plug-in which auto-completes parenthesis, brackets and so on (the characters: < { [ ' " " ' ] } >) and nicely indents and places the cursor where you (me) want it. This plug-in is an absolute life saver!

Before return is pressed (notice that there is no "}"):

{//Cursor here

After return is pressed:

{
    // Cursor here
}

- Symbol Browser
Shows a list of classes, functions, enums and class fields.

- Snippets
This plug-in allows you to define snippets of codes which appear when you use a tab-trigger. This one saves you a lot of time. Make a for-loop with a few keystrokes. See my post on how to use snippets.

Screenshot of my gedit (oblivion theme):

If you use an awesome plug-in or something for gedit please leave comment!

Posted in Programming, Tips & Hints | No comments
Tags: , , , ,

Amazing twelve year old talks about jQuery

I just found this amazing clip with the wonder child Dmitri Gaskin. He's twelve years old, contributes to dupral, involved in the google summer of code and attending 6th grade classes! This is something you don't see everyday. He talks a bit fast, but that's just because he's nervous. Anyways, a twelve year old kid on Google Tech Talks is damn impressive!

I just realized how powerful jQuery library is, and I will definitely start using it.

See the clip on YouTube:

Wish I was that smart when I were twelve years old :-|.

Posted in Internet, Programming | 2 comments
Tags: , , , , , ,

LaTeX in WP

I finally got LaTeX in WP! Now I can write [ tex ] [ / tex ] and voilá! I'm now using a external site for rendering my equations, but as soon as I get the code running on my own server I will of course use my own.

To get this working I had to write a little plugin for WP, which was easier than I thought. Here is the code I'm using:

/*
Plugin Name: LaTeX
Version: 0.1
Author: Ole
*/


function addLatex($text)
{
    $text = preg_replace("/\[tex\](.+)\[\/tex\]/",'<img src="http://www.codecogs.com/eq.latex?\\1" alt="" />',$text);
    return $text;
}

add_filter('the_content','addLatex');

WP need the comment to get data about the plugin and you simply use the add_filter() to apply your own function on given data. Here I'm using addLatex() on the content.

Here is how it works:

[ tex ] V_{ind} = -\frac{d}{dt}{\int_A{\vec B d\vec A } = -\frac{d\Phi_B}{dt} = -\frac{d}{dt}\left( \int_{a+vt}^{a+b+vt}{ \frac{\mu_oI}{2\pi x} cdx \right) = ... = -\frac{\mu_0 Ic}{2\pi}\left( \frac{v}{a+b+vt} - \frac{v}{a+vt} \right) [ / tex ]

Gives:

You gotta love LaTeX, and you gotta love physics. This equation is actually the solution to a problem on an old exam.

Posted in PHP, Programming | One comment
Tags: , , ,
This site is powered by WordPress.