class SuffixArray
attr_reader :suf, :string
def initialize(string)
@string = string
@suf = (0..string.size-1).sort_by{|i|@string[i..-1]}
end
end
This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.
Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts
Thursday, July 16, 2009
Tiny implementation of a suffix array in Ruby
Saturday, April 11, 2009
Ruby and GUIs
Is there a good ruby GUI toolkit?
I want to write a simple app, with a simple DB backend, just to keep some notes. As I want it to run on my laptop, I don't want any webserver running, so no rails app (and also because I want to do some gui programming, it's years I am only working on console or web apps).
I started earlier this morning my Google quest to answer this question, I am not so far yet. I am no expert in GUIs.
Some disorganized thoughts:
- Java of course is a good choice, isn't it? Yes I want to learn Java again (I learned it 10 years ago, and not using it a long time, so I guess my knowledge is totally out-of-date). But now I want just to write a little small app in that simple little lovely ruby language.
- I guess most Win apps are based on "native" widgets. For that maybe you need VS or the like and I am in this moment in no mood to be a MS fan. And I want something cross-platform.
- There a libraries, and like always in IT a lot of names and acronymes, just to confuse stupid newbies like me. QT is one, I think, then there are others (I think some GUI library-flame is also the reason why Gnome and KDE are 2 different desktops, isn't it?). So I guess you use one of that with some good ruby bindings and you are on it. Right?
- I read of Shoes: very simple, maybe good idea, but probably just for beginners, I don't know if I want to waste my time with it. Looks like is just something for kids learning programming?
Monday, August 18, 2008
Default values in Ruby blocks
The ruby parser does not allow default values to be set in blocks, unlike in method signatures. This is of course valid ruby:
However it is possible to simulate the behaviour, creating a de facto signature with default values. For example lets say I want a proc accepting the same parameters as a method defined as
def method(a, b=0)but this isn't:
#...
end
Proc.new {|a, b=0| } ### syntax error!See e.g. this discussion in Ruby forum.
However it is possible to simulate the behaviour, creating a de facto signature with default values. For example lets say I want a proc accepting the same parameters as a method defined as
def a(b, c=1)
:lambda do |*args| # simulated signature: |b, c=1|This has the disadvantage that is not validating the number of arguments, so let's add some validation code to the block:
b, c = args[0], args[1] || 1
end
lambda do |*args| # simulated signature: |b, c=1|Now the block behaves like if it had the signature |b, c=1|.
b, c = args[0], args[1] || 1
# validate number of arguments:
err = "wrong number of arguments"
if args.size > 2
raise ArgumentError, "#{err} (#{args.size} for 2)"
elsif args.size == 0
raise ArgumentError, "#{err} (0 for 1)"
end
end
Thursday, August 14, 2008
Execute a Rake task in another
It is easy to make one task dependent on another, for example:
executes task two, three, then one (I have to test that the order is really this). But how to execute task ":two" in the middle of the code of another task?
Here is the solution:
the ENV assignments and execute call have a similar effect to executing in your shell:
Yeah, Rake is a really easy and cool tool for every scripting need...
task :one => [:two, :three]
executes task two, three, then one (I have to test that the order is really this). But how to execute task ":two" in the middle of the code of another task?
Here is the solution:
desc "This task executes task two in its code!"
task :one do
# ... do domething
ENV['PAR1'] = 'xxx'
ENV['PAR2'] = 'yyy'
Rake::Task[ "two" ].execute
# ... do something
end
the ENV assignments and execute call have a similar effect to executing in your shell:
rake two PAR1 = xxx, PAR2 = yyy
Yeah, Rake is a really easy and cool tool for every scripting need...
Subscribe to:
Posts (Atom)
Labels
software installed on my laptop
(13)
windows software
(12)
personal settings
(10)
linux software
(8)
rails
(7)
shell rc file
(6)
linux basics
(5)
C basics
(4)
color the shell
(4)
ruby
(4)
connection to remote servers
(3)
git
(3)
mutimedia software
(3)
rake tasks
(3)
shell
(3)
active scaffold
(2)
backup
(2)
disk analysis
(2)
less
(2)
oracle
(2)
rails migrations
(2)
rails on oracle
(2)
sql
(2)
ssh
(2)
symbolic links
(2)
top open source projects
(2)
virtualbox
(2)
GUI programming
(1)
MIT
(1)
active record
(1)
algorithms
(1)
applications
(1)
apt
(1)
attr_hidden
(1)
bash
(1)
capistrano
(1)
cms tools
(1)
color picker
(1)
common errors
(1)
cooltips
(1)
data recovery
(1)
data structures
(1)
dvd43
(1)
endline chars
(1)
expression engine
(1)
ftp clients
(1)
gimp
(1)
grep
(1)
handbrake
(1)
hard disk failure
(1)
image conversion
(1)
image editing
(1)
inkscape
(1)
java software
(1)
javascript
(1)
jdiskreport
(1)
linux compact guides
(1)
ls
(1)
online lectures
(1)
oracle lob
(1)
photo manipulation
(1)
php
(1)
polymorphic associations
(1)
prototype
(1)
putty
(1)
rails plugins
(1)
rake
(1)
rsync
(1)
ruby blocks
(1)
scanf
(1)
scite
(1)
script
(1)
scripteka
(1)
sftp clients
(1)
sort_by :sql
(1)
suffix array
(1)
synctoy
(1)
tcsh
(1)
timms
(1)
unlocker
(1)
vector graphics
(1)
vi
(1)
video lectures
(1)
vlc media player
(1)
windows alpha blender
(1)
winscp
(1)
xslt xml
(1)
About Me
- Giorgio Gonnella
- Hamburg, Hamburg, Germany
- Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.