Skip to main content

Posts

God is bigger than the Boogie Man - Guitar Chords

This song is called "God is Bigger than the Boogie Man" which came from Veggietales and is quite the hit for the preschoolers at church. There are some more words that are said when played in the movie however for the kids at church this chorus works wonders. G God is bigger than D the boogie man A He is bigger than Godzilla D Or the monsters on TV G Oh God is bigger than D the boogie man A He is watching out for G you and D me.

Robot moving across a NxM matrix.

Lets say I have a matrix that is a 2 dimensional array of NxM elements and the Robot needs to find all the ways from the top left corner all the way to the bottom right corner. Now the Robot it self has some rules to follow on the way. The Robot can move up, down, left, right in order to get there. However the Robot may not move over the same square more than once. def robot (matrix,n ,m) return 0 if n <0 || m <0 || n > matrix . length -1 || m > matrix . length -1 return 0 if matrix [ n ][ m ] == 1 return 1 if n == m && n ==0 count =0 tmp = matrix tmp [ n ][ m ]=1 count += robot(tmp, n +1 , m) #right count += robot(tmp, n -1 , m) #left count += robot(tmp, n, m +1 ) #up count += robot(tmp, n, m -1 ) #down tmp [ n ][ m ]=0 return count end Now lets say that you have the same size matrix but the Robot can only move down and left. def robot (matrix,n ,m) return 0 if n <0 || m <0 || n > matri...

JRuby Image Comparison - Part 2

In continuation to find ways of comparing if images are equal I decided to try comparing them as byte arrays. First we need to declare some library's. We will be using JRuby for these examples. If you want to use Java this will look simular. require 'java' java_import 'java.awt.image.BufferedImage' java_import 'javax.imageio.ImageIO' java_import 'java.io.ByteArrayOutputStream' Now we need to make a function that will allow us to open an image as a bufferedImage, and a function to convert image to a byte array. def get_image (filename) file = java : :io :: File . new(filename) return ImageIO : :read (file) end def byte_array (image) os = ByteArrayOutputStream . new ImageIO : :write (image, "png" , os) return os . toByteArray() end Lastly we need a way to compare the 2 arrays to see if they are equal def compare (img1, img2) java : :util :: Arrays . equals(b1, b2) end Want to download the whole scri...

JRuby Image Comparison

Working on a project to validate some images and I thought this would be a good opportunity to show a simple way to compare 2 images to see if they are equal. First we need to declare some library's. We will be using JRuby for these examples. If you want to use Java this will look simular. require 'java' java_import 'java.awt.event.InputEvent' java_import 'java.awt.image.BufferedImage' java_import 'javax.imageio.ImageIO' Now we need to make a function that will allow us to open an image as a bufferedImage def get_image (filename) file = java : :io :: File . new(filename) return ImageIO : :read (file) end Lets start figuring out if the images are the same. A good place to start is to define a function that with tell us whether the width and height are the same. If they are equal then the images could be the same. def compare_size (img1, img2) if (img1 . getWidth == img2 . getWidth && img1 . getHeight == img2 ....

Setup Sinatra Application on Hostmonster.

Step 1 - Environment Setup Make sure that you have ruby installed on environment, and have SSH access. To your account. Step 2 - Create Ruby on Rails Environment Login to your Hostmonster C-Panel. Click Ruby on Rails icon. Fill out form with your information Step 3 - Setup Directory Link SSH into your account and goto where you would like the base of your app to be in. For example if you have website www.example.com and you want it hosted at www.example.com/myApp ln -s ~/rails_apps/myApp ~/public_html/myApp Step 4 - Clean up automatic Rails files. rm -Rf ~/rails_apps/myApp/* Once you have cleaned up the directory copy your sinatra files to ~/rails_apps/myApp If you have a Gemfile this would also be a good time to run a "bundle install" while you are in the directory. If you don't get your gems loaded you will experience problems. Step 5 - Setup your .htaccess file Open up your .htaccess file for the myApp directory and make it look like...

Set Git to stop tracking file

I have found the need to ignore a file with out using the .gitignore. In my case its because of a chrome driver that we using for Cucumber and Watir. The office has a standard setup with a certain repository, however on my Mac chrome likes to update. This causes an issue with versioning of the driver. So I wanted to put a new chromedriver in my repository folder but not ignore it from the repository. To do this little trick I can update the index and tell it to assume the file is unchanged. git update-index --assume-unchanged <file> If you have the need to reverse the tracking of the file. git update-index --no-assume-unchanged <file>