Other articles


  1. Why Unsafe State != Deadlock

    You have a list of processes and a list of resources, and for each process you have:

    • The number of each resource they will ever need at once.
    • The number of each resource they are currently allocated.

    When a process makes a request for a resource, you only allocate the ...

    read more
  2. x86 Stack Diagrams

    All of the x86 stack diagrams I could find are either cluttered with too much information, can't be read from a distance, or put the high address on top (I'm sure there are people who prefer that but... I'm not one of them). So I made my ...

    read more
  3. Visual Basic's "With" in Ruby

    def with( obj )
      yield obj
    end
    
    with Math do |m|
      puts m.exp( 1 )
      puts m.exp( 2 )
      puts m.exp( 3 )
    end
    
    # Deeply nested modules
    module Foo
      module Bar
    
        module Baz
          A_CONSTANT = 3
          def self.aMethod( x )
            x * A_CONSTANT + A_CONSTANT
          end
        end
    
        module Biz
          def self.anotherMethod( x )
            "hello ...
    read more
  4. Ruby Obfuscation

    Just having fun...

    Obfuscated #1

    This evaluates to the string "?".

    ??????????????:????????:??:??:??:??:?????:?? # => "?"
    

    Obfuscated #2

    $i=0;[$c="[$s=['p '],[$s<<[*1?3??'+?<+?3:?y:?]],$s+=[?b],$s|=[*?y+?'],$s[2,0]=5??r+?u:?$],($i+=1)<30?eval($s.join<<?;<<$c):nil]",eval($c)]
    

    Output

    "<3ruby"
    "<3ruby"
    "<3ruby"
    "<3ruby"
    "<3ruby"
    "<3ruby"
    "<3ruby ...
    read more
  5. Ruby Maze Solver

    Here's a recursive-backtracking ASCII maze solver I wrote to practice ruby. The o's are the solution.

    Output

    $ ruby maze.rb maze.txt
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ++++oooooooo  ++++++++++++++++++++++ ++++++++++++++++++++++++        ++++ ++++++
    +oooo++ +++o++++++++++++++++++++++++ ++++ +++++++++++++++++++ +++ +++++++ ++++++
    ++++ ++   oo+++++++++++++++++++ ++++ ++++                 +++ +++ +++++++ ++++++
    ++++ ++ ++o++++++++ooooooo+++++ ++++ ++++ +++++++++++++++++++ +++         ++++++
    ++   +++++o++++++++o+++++o+++++           ++++ ++++++++++++++ ++++++++ +++++++++
    ++++++++++o++++++++o+++++o+++++ +++++ ++++++++ +++oooooooooooooo++++++ +++++++++
    ++++++++++o+oooooooo+++++ooooooo+++++ ++++++++ +++o++++++++ +++o++++++ +++++++++
    ++++++++++ooo++++++++++++ +++++o+++++ +++++++++   o++++++++++++o++++++ +++++++++
    +++++++++++++++++++++++++      o++++++++++++++++++o      ++++++o       +++++++++
    +++++++ +++++++++++++++++++++++o ...
    read more
  6. My Favorite 'Rubyisms'

    I've been using Ruby at work to write watir tests, and I am constantly amazed at how elegant it is. Here are some of my favorite techniques:

    Pass a default value block to Hash.new to implement a memoized recursive function:

    fibonacci = Hash.new do |h,k|
        h[k ...
    read more
  7. Random .vimrc Tips

    Here are some of my favorite .vimrc lines.

    Save quickly from any mode by pressing CTRL+:

    imap <C-\> <Esc>:w<Cr>
    map <C-\> <Esc>:w<Cr>
    

    Make indenting and de-indenting in visual mode preserve the selection:

    vnoremap > ><CR>gv
    vnoremap < <<CR>gv
    

    Quick case insensitive search with double slash or ...

    read more

social