Programming

Building an application to track expenses in one hour using GeoChat

Whenever one of our team member travels to another country we tell her to track expenses like food, transportation and accomodation so that later that money can be refunded. Each of us does it in a different way: we write it in a notes application in a cellphone, or in a text file in our [...]

Quick way to test many values in ruby

Many times we end up having similar tests: same logic but different inputs and expected outputs. For example, suppose we need to test our brand new sqrt function:

test "sqrt 1" do
assert_equals 1, sqrt(1)
end

test "sqrt 4" do
assert_equals 2, sqrt(4)
end

test "sqrt 9" do
assert_equals 3, sqrt(9)
end

Here we are dupplicating code, since “assert_equals [...]

String concatenation in ruby

I just found out the difference between += and << when used for a string.
irb(main):001:0> str = 'chan'
=> "chan"
irb(main):002:0> str.object_id
=> 69952758899780
irb(main):003:0> str += 'ged'
=> "changed"
irb(main):004:0> str.object_id
=> 69952758848800
irb(main):005:0> str << ', now not'
=> "changed, now not"
irb(main):006:0> str.object_id
=> 69952758848800
So I think that basically you should never use += for strings, unless you really want to hurt the [...]

Ruby-Jump plugin for gedit

I searched the internet for a gedit plugin that would allow me to press a key and jump (navigate) to the file where a ruby class is defined. I couldn’t find one so I wrote one (I know about Geany but I couldn’t find that functionality there either).
Usage
You need to have the FileBrowser plugin installed [...]

Indentation also means something else…

Some days ago I read this in the Digital Mars D programming language newsgroup.
bearophile says:
From:
http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7...
Automated Resource Blocks, to be able to say things like:

try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}

instead of:

BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}

and Andrei [...]

Constant Silverlight CPU usage? Double check your animations.

I had to fix a problem in a Silverlight application we are building. The problem was that it’s CPU usage was constant, between %20 and %40, and never stopped. I won’t go into the details of how I discovered the problem, but I’ll tell you what the problem was, and how we solved it.
The application
In [...]

Embedding YouTube videos in Silverlight

There’s no straight way of embedding YouTube videos in Silverlight. What you can do, however, is to create a floating div over the Silverlight plugin, whose content will be the YouTube video control. For this purpose, I’ve wrote a simple class to make it easier to do this.
The usage is simple:

// ZCcedd9EfHI is the id [...]

Adding double click support in Silverlight

code {
font-size: 12px;
}
pre {
background-color:#F4F4F4;
border: 1px solid #B2B2B2;
padding:4px;
font-size: 12px;
}

Silverlight Beta 2 doesn’t support double click, but since I needed it, I implemented it. I’ve created a class named Mouse. You create a Mouse instance that wraps an UIElement. The instance attaches itself to the [...]

Syndicate content