MySQL User defined Variables - good thing to know!
Have you ever heard of user defined variables in MySQL? I hadn’t and nearly freaked out when I found out. That’s the thing I was always looking for, that’s so cool, and fasten up your SQL live a lot!
Now, renumbering a table is as easy as never before:
[text]
Set @a = 0;
UPDATE my_table SET id=@a:=@a+1
[/text]
Check out the docu and examples:
http://dev.mysql.com/doc/refman/5.0/en/user-variables.html
Named scopes in Rails are just awesome. They so much DRY and beautify your code! But did you ever had the trouble to create a new named_scope out of others? E.g. aliasing multiple ones to a new one. Luckily I now figured out how this works in a nice way.
The magic key is the method scope( :find )
This method called on a Scope class returns the Hash used for the ActiveRecord .find()
call. First it’s a nice way to debug your scopes, second it’s perfect for our need to chain multiple scoped into one. Check this out:
[ruby]
class Fu < ActiveRecord::Base
named_scope :has_moo, :conditions => { :moo => true }
named_scope :has_foo, :conditions => { :foo => true }
named_scope :has_moo_and_foo, lambda { has_moo.has_foo.scope(:find) }
end
[/ruby]
We chain the two scoped has_moo
and has_foo
together into a new one called has_moo_and_foo
. As the return value can only be a Hash we use the above mentioned scope(:find) to transform it into one.
Now this works:
[ruby]Fu.has_moo_and_foo.all[/ruby]
Sweet! Imagine how great this would be if we can return a scope object instead of a hash as well??
See my pastie here too.
LED Light Towers Installation
Hey, Check this out, a very nice LED tower installation:
http://www.youtube.com/watch?v=FsHMFkJkohM
see more great stuff at http://www.brilldea.com/
How to deal with recurrency in Ruby & Rails
I did a short eval of projects dealing with re currency in Ruby and Ruby on Rails. Here a short list & rough of interesting projects dealing with repeating time (intervals):
Common used lilbrary: http://runt.rubyforge.org
A better runt(?): http://github.com/nickstenning/recurring_event
Date extension, yahoo dev, rspec like: http://github.com/jhubert/ruby-date-recur
http://recurring.rubyforge.org
http://github.com/EdvardM/recurrence
http://github.com/fnando/recurrence
Check this as well:
http://stackoverflow.com/questions/85699/whats-the-best-way-to-model-recurring-events-in-a-calendar-application
Love ActiveScaffold: Show always Searchbox
ActiveScaffold is a great plugin to build edit form easily. Nicely AJAX and nested forms support (well with limits ;-). One thing which bugged me all the time, was the extra click you had to do to show the searchbox. Well I solved it like this:
[ruby]
def index
active_scaffold_config.list.label += render_to_string( :action => :search, :layout => false )
super
end
[/ruby]
I know, it’s kind of bad hack, as the label actually isn’t supposed to contain a form - but it works out quite well!
Here is a short collection of current Content Management Systems (CMS) written in Ruby and mostly suited to use with Ruby on Rails. Check out Ananablau as well for a nice PDF slide.
Comatose (29. June 2007)
Comatose is a micro CMS designed for being embedded into existing Rails applications
http://railsbased.org/projects/8-Comatose.html
Geego
Geego is for developers and designers that want to provide fully updatable websites for their clients.
http://www.geegocms.com/
Mephisto (27. July 2006)
Complete Blog System, Mephisto is a publishing system that makes it super easy to setup a blog or website.
http://mephistoblog.com/
Typo
Complete Blog System, Similar to Mephisto
http://wiki.github.com/fdv/typo/
Radiant CMS
Radiant is a no-fluff, open source content management system designed for small teams.
Looks cool but no direkt RoR integration?
http://radiantcms.org/
Railfrog (3. July 2007)
Railfrog is a user-friendly, open-source website deployment and content management system built with Ruby on Rails.
dead project?!
http://railfrog.com/
Rubricks (31. July 2007)
Rubricks is a component based open source CMS powered by Ruby on Rails.
http://rubricks.org/
Seymore (04/02/2007)
Seymore is an open source content management system which integrates directly into pages.
http://www.slicedsoftware.com/software/seymore/
SimpleCMS , (29. December 2007),
small simple, inline edit. Simple CMS is a very easy to use and pretty advanced CMS plugin.
http://pullmonkey.com/2007/12/30/simple-cms-plugin-for-rails-demo
CMSPlugin
CMSplugin provides your Rails application with a “CMS framework”. That means authentication, authorization, roles, permissions, categories, tags, etc
but from a very flexible scope.
http://cmsplugin.rubyforge.org
open rcms (25.6.2007)
http://rcms.oopen.de/Home/
Roxanne
An in-place editor for your entire website. Roxanne is a simple Site-Management Tool to quickly manage your content. See first steps to get the idea behind Roxanne.
http://www.m42.ch/projects/roxanne/information.php
Substruct
The first and most robust Ruby on Rails open source e-commerce project.
http://code.google.com/p/substruct/
Goldberg (promising)
http://www.goldberg.240gl.org
Beautify your views using "return"
A nice way to keep your views clean and not to spoil them with condition clauses, is to use the ‘return’ statement like you would do in a method:
Take this very simple exmaple:
ugly:
[ruby]
unless @place
end
[/ruby]
nice:
[ruby]
return if @place.nil?
[/ruby]
UPDATE:
There’s one pitfall, I forgot to mention: Every outout BEFORE the return statement will be discarded, so this part:
[ruby]
return if @place.nil?
[/ruby]
Will result in an empty output as well. This is quite a pitty and I’m not sure if it’s a bug or feature. A may raise it soon..
SEO - Notes
This is just a list of SEO Notes I did years(!!!) ago. it’s mainly for me to remember stuff. Sorry this is in german.
guter strukturierter inhalt als text!! gute name/keywords in anker
guter individueller title, description, keywords,
interne links -> grüner, stockstreet, ompro
social bookmarks delicous, digger, mister-wong,
rss feeds -> feedburner
alt und title bei images,
h1, h2 tags
mehr css, weniger tables
check google sitemaps, analytics
linktausch! linkeinkauf!
robots.txt
keine (Wenige) params in URL
URL verlinken mit / am ende
keine frames! schon gar nicht iframes!!
eintragen in profiles flickr,
nutzen mit myspace, wikipedia, ebay, studvz, openbc, foren, protale, amazon??, blogs!!
achtung vor duplicate content!
301/302 weiterleiterungen, keine multidomains
google adsense????
achtung vor code injection -> Suchanfragen!!!!
sessionid killing
gute Kataloge nutzen: dmoz, bellnet, http://dir.yahoo.com/, http://botw.org/
finde den HUB
credit, depotrechner, howto, tutorials fancy mit ajax gut verlinken
yahoo searchbuilder, allregster.com ?? euregster.com ??
Top Words:
Poker, Datenrettung, Kredit, Privatekrankenversicherung
My first AppleScript: Copy Address Book entries
Tatataa! I just wrote my frist AppleScript. For displaying the buddypicture of my Address Book contacts in Adium, I had to copy the ICQ entry to a new Jabber enrty with appending “@jit.jabber.fsinf.de”. The code follows:
tell application "Address Book"
set thePeople to every person whose ICQ handles is not {} and Jabber handles is {}
repeat with eachPerson in thePeople
set icqnr to value of ICQ handles of eachPerson
set jabberid to (item 1 of icqnr) & "@jit.jabber.fsinf.de"
make new Jabber handle at end of Jabber handles of eachPerson with properties {label:"Home", value:jabberid}
end repeat
save addressbook
end tell
It worked out fine. Now I see you all in my buddylist ;-)