Recap from Ruby Coding Group: 8-11-07
- Make sure Ruby, Rails, MySql & Subversion are installed and working properly on your machine.
- Create 2 databases: atlrug01_development & atlrug01_test
- Login to Assembla where the atlrug coding project 1 is being hosted. You need to be invited to the atlrug project in order to checkout the project with subversion.
- Checkout the atlrug project: svn co http://tools.assembla.com/svn/atlrug. You will have to enter your assembla password and username in order to check the project out.
Here are two options for syncing the data between development databases in rails:
1. export and import sql—using a command like this one…
mysql -u root -p atlrug01_development < /path/to/your/project/.../atlrug/atlrug01/trunk/atlrug01/db/development_data.sql
2. fixtures + yaml
I placed a rake task in lib/tasks that will take whatever is in the db and dump that into a yaml fixture located in test/fixtures.
After checking out the latest version of the project, you run rake db:migrate & rake db:fixtures:load to import the yaml to your db.
Full instructions here: http://snippets.dzone.com/posts/show/3393
Digg is my guilty pleasure...
Dear Digg,
I just don’t know how to quit you. Your front page with its ultimate tutorial lists, DIY hacks, news of new software releases, links to photos of scantily-clad women & oh God, don’t get me started on diggnation. Digg, you make me feel… inadequate. There’s always something new to tweak, new software to try, links to bookmark, news stories to, err…’research’. I can’t keep up.
And who’s fault is it that I feel inadequate? Well, I certainly can’t be the one to blame; you are everywhere! Even after removing all digg artifacts from my browser, I cannot escape the ‘digg this’ buttons & the ‘top-on-digg’ widgets slopped on various blogs (I think there was one on this blog at one time). You are in my internetz, destroying my blankspaces & thus, my self-esteem (not that that is terribly hard).
I want my simple, pre-digg life back; a life where I did important things, like save kittens & write “bad” poetry.
Fortunately, my interest in mouseHole has given me reason to spend less time at digg and more time at code.whytheluckystiff.net/mouseHole/ (Google says I’ve made 6 visits since the middle of this month! & that excludes all of the internet stalking I’ve been doing at the library). Now, I know what your’e thinking… “Just write a nice little mouseHole script to removes all of the digg paraphernalia from around the web.” And writing such a script would be a smart thing for me to do; my time away from digg would result in more time away from digg. But alas, I can’t seem to quit you. In fact, the mouseHole script that I ended up writing [1] uses your new API to display the number of diggs for the page I am currently viewing, along with (what else) a link to that page on digg.

And you know, the thing is that I suck at writing Ruby. Hell, I don’t even know if I’m a programmer yet. I have lots to learn and do with Ruby; I don’t have time for you & your front page and especially not for your comments or video podcasts. Maybe you could meet me half way and make yourself a paid-members only site? No? Then, I am hopelessly yours. Just promise me that you won’t take all of my time and that if you ever leave me for good, that you will return that little piece of my heart that I have given to you.
Lovingly, but irritatedly,
JessiRae
[1] Using this Ruby Digg Wrapper, I added to the browserbar.rb mouseHole script that I created earlier. The browserbar script places a list of links at the top of every page; the list forms a bar, similar to the plugins and quick links firefox makes available. Yeah, sure you are making all of your web surfing known to digg, but that just makes the guilt stronger. To use the digg “plugin”, place the digg.rb wrapper in your {mouseHole_root}/lib/mouseHole directory.
Browser Bar for mouseHole
.mouseHole folder to add a browser bar at the top of every page your view with mouseHole; like this…
def rewrite(page)
document.search('//a[@href]') do |link|
href = URI(link.attributes['href']) rescue nil
next unless href && href.host && href.host != page.location.host
link.after '<span style="font-size:8px">[' + href.host + ']</span>'
end
#add the following line
document.search("body").prepend("<a href=\"http://del.icio.us/jowensbysandifer\">"
+"<img src=\"http://127.0.0.1:3704/doorway/static/images/delicious.gif\" />"
+"</a>")
#just include your links to your favorite sites and you can check them...
# no matter where you are
end
Oh and don’t forget to place any icons in the static/images folder in your mouseHole application.
-Teehe! And if I knew how to get the url to the script, I could submit sites to del.icio.us (or whatever site I wanted) via javascript… but that might be dangerous!-
UPDATE:
Here’s how to submit a site to del.icio.us via the browser bar by getting the page url.
Step 1: save the request in proxyhandler.rb as $request. A global… bad I know :-(
I’m still figuring out how mouseHole works. Maybe the best thing to do would be to write the value out to the database?
Step 2: add submit html to a user script or create a new one (I call mine browserbar.rb), like this…
document.search("body").prepend("<a href=\"http://del.icio.us/jowensbysandifer?url="
+ $request.to_s + "&submit=save&jump=no\">"
+" <img src=\"http://127.0.0.1:3704/doorway/static/images/delicious.gif\" /></a>")
Step 3: Restart mouseHole.
Installing Openssl on Ubuntu
LoadError: no such file to load—openssl
despite the fact that you have installed openssl with “gem install libopenssl-ruby”.
Thanks to this thread, I found out that in order to install openssl, you have to tell ruby how to compile the openssl extension, like this…
cd /ruby-1.8.4/ext/openssl
ruby extconf.rb
make
make install
Grab all of the href links from a Page
Use Rubyful Soup to get all of the hyperlinks on a page…
soup = BeautifulSoup.new(page_content)
result = soup.find_all('a')
result.each { |tag|
urls[i] = tag['href']
if urls[i].to_s.slice(0,1) != 'h' then
#add first part of url to href link if link is internal
urls[i] = home + urls[i]
end
i = i + 1
}
Multiline Comments with Ruby
I didn’t know that ruby
has multiline comments.
- =begin
Name:
Last Updated:
Location:
...
=endWell, at least I wasn’t the only one.
Sitemap with Rails
I finally got around to generating a sitemap for this site. I used these instructions for creating sitemaps in rails. Very simple and straight forward instructions.
Unfortunately, the sitemap created isn’t valid according to google. The xml document created has <link> tags instead of <loc> tags which google webmaster requires.

I am guessing that these errors mean that my sitemap is useless to Google. Still looking for a solution and will post an update as soon as I find one.
Install mouseHole on Ubuntu 1
rewrite the web as you view it, altering content and behavior as you browse. Basically, it’s an alternative to Greasemonkey, which does similar things from inside the Firefox web browser.

To get mouseHole up and running, first install the required gems (json and sqlite3) if you don’t already have them installed. I encountered the following issues while installing those gems…
- Installing json
lib/json/editor.rb:977:50: ’:’ not followed by identified or operator
The solution is to remove the colon from line 977.
Installing sqlite3
The command for installing the sqlite3 gem is gem install sqlite3-ruby and not gem install sqlite3.Lastly, if you are running Debian or Ubuntu, visit http://localhost:3704 instead of http://127.0.0.1:3704 after starting mouseHole.
One-liners
and Frequently used commands I can’t seem to remember the exact syntax of. Nothin’ fancy.
Linux
find . -name \*.* | xargs grep search_string
- navigate to folder you would like to search, enter this command with the search string you would like to find and this command lists all files containing that string
ps x -Ho pid,args
- lists all of the processes running
find / -name gcc- finds all folders named gcc
sed '/$/,/' /home/Desktop/jessirae > /home/Desktop/jessirae2
- places a comma at the end of each line
paste -sd '\0' - /home/Desktop/jessirae2 > /home/Desktop/jessirae3
- The NEWLINE character of every line except the last line in each input file will be replaced with a separator
Ruby
"<a href=\"http://www.oldurl.com\">JessiRae.com</a>".
gsub(/(http?:\/{2})\S+\.(\w+)(\S+)/,"http://www.jessirae.com/blog/")
- global substitution replaces all instances of some expression in a string with some other string or performs some function on that string
require 'open-uri'
....
open(url) {
|page| page_content = page.read()
page_content
}
- returns html from specified webpage
Older posts: 1 2
