Velox – Random Latin Words

16
Jun/09
0

I’ve always had a hard time naming the photographs I post on dA. Eventually, I started using a random Latin word. But going through a huge list of words looking for something that sounds cool was still tedious. So I did what anyone else in my situation would – write a web app to make my life easy. It’s called Velox (which was one of the words it came up with while testing it). As usual, it’s hosted at Heroku. Here’s a link to it- Velox – Random Latin Words.

Automatically Resize Large Images with Javascript

24
May/09
0

When you allow users to submit content, and allow that content to include images, there’s always a chance that some user will submit a really large image that will break your layout. One way to solve that is to check the content for large images and resize them using a server-side program. However, sometimes, that is simply not possible. In those cases, we use what’s left- Javascript.

Zenity.rb

12
May/09
0

Zenity is a command line based tool that helps shell scripts display GTK dialog boxes as a more interactive way to display error messages, get user input and other stuff like that.

Getting a Method to Accept an Arbitary Number of Arguments in Ruby

9
May/09
0

In LISP-like languages such as Scheme, you can do arithmetic with code like this:

(+ 5 5)           ; => 10
(- 3 2)           ; => 1

The + operator there behaves like a function. The striking thing is that it can accept any number of arguments. So you can also do stuff like this:

(+ 1 2 3 4 5)     ; => 15

You can also do that in Ruby, using the splat(*) operator. The splat operator can do a lot of fancy stuff, but I’m not going to cover all of that here.

Very Simple Metronome in Ruby

23
Apr/09
2

A metronome is basically something that beeps periodically, indicating the exact tempo of some music. I wanted one for my guitar practice, but the only one in Ubuntu’s repos (GTick) wouldn’t work, so I wrote this up.

How to Learn a New Programming Language

4
Apr/09
1

Learning a new language isn’t the easiest thing to do. It can, however, be a very rewarding experience if you are persistent enough. Luckily, if you know how to code in one language, it is much, much easier to learn another language. Here are some tips that can help you.

Implemeting HQ9+ in 10 lines of Ruby

3
Apr/09
1

HQ9+ is a excessively simple esoteric programming language. It has only four commands:
H: Print “Hello, World!”
Q: Prints the contents of the program onto the screen
9: Print the canonical lyrics of the song, “99 bottles of beer”.
+: Increment the accumulator

Here’s the entire implementation:

1
2
3
4
5
6
7
8
9
10
def hq9(src)
  src.downcase.split('').each do |i|
    case i
      when 'h'; puts "Hello, World!"
      when 'q'; puts src
      when '9'; 99.downto(0) { |b| puts "#{b==0?'No more b':"#{b} B"}ottle#{'s'if b!=1} of beer on the wall, #{b==0?'No more':b} bottle#{'s'if b!=1} of beer.#{b==0?"nGo to the store and buy some more, 99 bottles of beer on the wall.":"nTake one down and pass it around, #{b-1} bottle#{'s'if b!=2} of beer on the wall.nn"}" }
      when '+'; $i = $i ? $i + 1 : 0;
    end
  end
end

Note: I got the lyric printing code from here.

Project Euler #48 in Ruby

2
Apr/09
2

Note: Don’t look at the code if you intend to solve the problem later.

Problem 48 – Project Euler

I was surprised at how easy this turned out to be. It is really, really simple because with Ruby, the only limit on how big an integer can get is how much memory you have available. Here’s my solution:

# Project Euler, 48
start = Time.now
 
n = 1
sum = 0
 
1000.times do
  sum += n**n
  n += 1
end
 
puts sum.to_s[-10..-1]
puts "Time taken: #{Time.now-start}"

It takes a fifth of a second on my laptop running Ruby 1.9.1.

Ruby Style Blocks in Javascript

23
Feb/09
0

Javascript is a really great language when it comes to flexibility. It is possible to pass code to a function the way you can do with Ruby, albeit a bit more verbose. This is made possible by the fact that javascript allows you to pass a function as one of the parameters of a function.

Compiling Ruby 1.9.1 (stable) on Ubuntu

18
Feb/09
0

I found the default ruby install that came with Ubuntu to be a bit wonky, so I decided to reinstall it. And I like to use the newest version, always.