Common Mac Accent Marks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
æ = Option (alt) + ‘ à = Option (alt) + ` + a â = Option (alt) + i + a ç = Option (alt) + c é = Option (alt) + e + e è = Option (alt) + ` + e ê = Option (alt) + i + e ë = Option (alt) + u + e î = Option (alt) + i + i ï = Option (alt) + u + i ô = Option (alt) + i + o ö = Option (alt) + u + o ù = Option (alt) + ` + u û = Option (alt) + i + u ü = Option (alt) + u + u « = Option (alt) + \ » = Option (alt) + Shift + \ ½ = Option (alt) + ½ |
Snippets: SVN Delete Missing
September 01, 2007 @ 09:39 AM | posted by carmelyne
(last updated: 09.01.07)Automatically remove files missing from subversion
svn status | grep '\!' | awk '{print $2;}' | xargs svn rm |
Snippets: Rails validates_format_of
August 31, 2007 @ 12:15 PM | posted by carmelyne
(last updated: 09.01.07)1 2 3 4 5 6 7 8 |
# email validates_format_of :email, :with => /(^([^@\s]+)@((?:[-_a-z0-9]+\.)+[a-z]{2,})$)|(^$)/i # url validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix # password validates_format_of :password, :with => /^\w+$/ (alphanumeric) |
Snippets: Rails yield :header_css
August 31, 2007 @ 12:15 PM | posted by carmelyne
(last updated: 08.31.07)1 2 |
<%= stylesheet_tag 'my-site-wide-css' %> <%= yield(:head_css) || (stylesheet_link_tag 'general_header_css') %> |
Restful_authentication & Activation
August 21, 2007 @ 06:06 PM | posted by carmelyne
(last updated: 06.04.08)Extension of Railscasts Episode 67
============================
Update: [March 12, 2008] This blog post is outdated so if you found this page using google, I'd recommend reading something more up-to-date. Unfortunately, I don't know where else to refer you right now. I shared my thoughts and experience with the plugin at the time I was using it for a project. Living in the now, you can grab Obie Fernandez's Book "The Rails Way". That comes highly recommended!
============================
Ryan showed us how to set up restful_authentication a plugin by Rick Olson with his 67th Railscasts Episode: restful_authentication. Pretty awesome! Now, we will extend it to the activation part.
./script/generate authenticated user sessions --include-activation
With the added --include-activation option, more files and codes will be generated to handle "Activation for a User who just registered".
Shall we break them down in steps... baby steps and with codes. I would be happy to do a screencast for this but I dont own a podcast mic yet so lets do it the old school way. I know we're all spoiled by Ryan's RailsCasts and Geoffrey's PeepCodes. We are the little Brats! :)
After generating the files for restful_authentication, follow the 67th episode set up plus these...
Step 1: All about Environment.rb
Open your environment.rb file and set up the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# First, specify the Host that we will be using later for user_notifier.rb HOST = 'http://www.yourrailsapp.com' # Second, add the :user_observer Rails::Initializer.run do |config| # The user observer goes inside the Rails::Initializer block config.active_record.observers = :user_observer end # Third, add your SMTP settings ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => "mail.yourrailsapp.com", :port => 25, :domain => "mail.yourrailsapp.com", :user_name => "carmelyne@yourrailsapp.com", :password => "yourrailsapp", :authentication => :login } |
Note: Just a heads up -- if you're on SliceHost like I am, I can't get this to work on just Postfix on Ubuntu. I needed to set up the SMTP settings on the environment.rb file.
Step 2: All about app/models/user_notifier.rb
Now you can see how we set a dryer way to add the HOST via #{HOST}. The codes below is also an example if you've extended it to handle resetting the passwords. Although you will have to add an additional user migration for "password_reset_code" and adding it to your user model/controller codes and more to your routes....
Anyway, code snippets below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
class UserNotifier < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += 'Please activate your new account' @body[:url] = "#{HOST}/activate/#{user.activation_code}" end def activation(user) setup_email(user) @subject += 'Your account has been activated!' @body[:url] = "Visit #{HOST}!" end def forgot_password(user) setup_email(user) @subject += 'You have requested to change your password' @body[:url] = "#{HOST}/reset_password/#{user.password_reset_code}" end def reset_password(user) setup_email(user) @subject += 'Your password has been reset.' end protected def setup_email(user) @recipients = "#{user.email}" @from = %("/Poke by carmelyne" <CT@yourrailsapp.com>) # Sets the User FROM Name and Email @subject = "[YourRailsApp] " @sent_on = Time.now @body[:user] = user end end |
Step 3: All about app/views/user_notifier/activation.rhtml
This gets sent out for the activation email so you can change the verbiage to something like this:
1 2 3 4 5 |
Thank you! <%= @user.login %>, your account has been activated. You may now start using the member only features. <%= @url %> |
I think that should be it. :)
I wrote this up to give you an idea for activation. If you extended it way beyond for forgot_password/reset_password, make sure you extend your user model and controller to handle these additional functions. More snippets....
Extras
1 2 3 |
# more for routes map.forgot_password '/forgot_password', :controller => 'users', :action => 'forgot_password' map.reset_password '/reset_password', :controller => 'users', :action => 'reset_password' |
1 2 3 4 5 6 7 8 9 10 11 12 |
# app/models/user_observer.rb class UserObserver < ActiveRecord::Observer def after_create(user) UserNotifier.deliver_signup_notification(user) end def after_save(user) UserNotifier.deliver_activation(user) if user.recently_activated? UserNotifier.deliver_forgot_password(user) if user.recently_forgot_password? UserNotifier.deliver_reset_password(user) if user.recently_reset_password? end end |
Update
But of course, there's a much better resource for the plugins, I was just referred to it after this long post from the man himself => Rick's Stikipad for Acts As Authenticated and RESTful authentication.
The additional methods for activation/forgot_password/reset_password does not fall under REST.
New tools new tool new tools
1. Aliases in bash
I'm a mac newbie. It sounds like a bad thing but it's not. Many moons ago, I only watched people type ss on their terminals and tada! it magically starts the built in webrick/mongrel server. I've been meaning to get aliases working since I converted but never got around to actually doing it. Thankfully, John Nunemaker posted his I Can Has Command Line? article. I can do bash magic now. My bash talk: ss sc a e et sup wu omg inbd idk my bff jill tinf! I think I'll use those for shortcuts anyway. ;p
2. Growl
I am a happy peepcoder. I recently saw the RSPEC Basics PeepCode. Geoffrey had a happy face/ sad face flashing bar on his screen when he would run tests. Oh, I so want. I want! You'll just have to buy the peepcode now, dont you? Anyway, it was Growl. I installed Growl but can't get it to work with autotest. Now I just do "a" to run autotest but I get this error: "177 examples, 0 failures sh: line 1: growlnotify: command not found". Obviously, I missed something here. I copied the .autotest file to ~
I'm off to search for a fix and will post it here too as an update.....
Update:
I knew I was missing something. I had to install growlnotify that came with the install files. (http://growl.info/documentation/growlnotify.php). I got my happy/sad bars now!
3.RSpec
New to RSpec and would you hold it against me if I said lazy with writing test? Ok then no, I love writing tests!!! Learning RSpec makes it easier to do test. I find that I do like BDD. I'm no expert but it's very fun to do, that I can say.
High to low precedence of Ruby operators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
::
[]
**
-(unary) +(unary) ! ~
* / %
+ -
<< >>
&
| ^
> >= < <=
<=> == === != =~ !~
&&
||
.. ...
= += -=...
not
and or
|
Source:
http://migo.sixbit.org/papers/Introduction_to_Ruby/slide-21.html
http://www.meshplex.org/wiki/Ruby/Variables_Datatypes_Operators4
Rule Of Thumb:
Use logical operator for logical statements use logical composition sparingly.
ID + permalink. The id gets a to_i
1 2 3 4 5 6 7 8 9 |
# using .join def to_param [id, permalink].join('-') end # just another way to do it def to_param "#{id}-#{permalink}" end |
Snippets: Short list for gems
July 26, 2007 @ 11:19 PM | posted by carmelyne
(last updated: 07.26.07)Generates a gem's list
gem list | egrep -v "^( |$)" |
Snippets: Rails Error on Production
July 05, 2007 @ 05:57 AM | posted by carmelyne
(last updated: 07.05.07)Quick cheat method to see errors on production mode without the Exception Notifier plugin or having to look at the production log.
1 2 3 4 5 6 7 8 |
# application.rb # replace "XXX.X.X.1" with your IP in the local_request method below protected def local_request? request.remote_ip == "XXX.X.X.1" end |
Snippets: Coldfusion Mask Output with *
June 27, 2007 @ 10:57 AM | posted by carmelyne
(last updated: 06.27.07)Peekabooo. Oooops wha? I don't see you.
1 2 3 |
<cfoutput>
#repeatString("*",len(qPayment.CreditCardNumber))#
</cfoutput>
|
Halt who goes there!
1 2 3 4 |
<cfif CGI.REMOTE_HOST IS NOT "127.0.0.1" AND CGI.REMOTE_HOST IS NOT "192.168.0.1"> <cfabort> </cfif> |
Snippets: Javascript Logical Operators
June 25, 2007 @ 02:39 PM | posted by carmelyne
(last updated: 06.25.07)1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// mathematical operators + addition - subtraction * multiplication / division % modulus (this is the remainder when you divide something) //comparison operators > Greater Than < Less Than >= Greater Than or equal to <= Less Than or equal to == Equal to != Not equal to |
Note:
("=" sign assigns a value to a variable, "==" compares two values for equality.)
Snippets: Rails 'A'..'Z' Paginate
June 24, 2007 @ 09:40 PM | posted by carmelyne
(last updated: 06.25.07)'A'..'Z' paging cause I'm being lazy & I don't want to mess around with default paginate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Starts with 'A'..'Z' Paginate / model def self.sort(sort) if sort find(:all, :conditions => ['name LIKE ?', "#{sort}%"]) else find(:all, :order => 'name') end end # index action / controller @models = Model.sort(params[:sort]) # Sort link A-Z / view <a href="models?sort=A">A</a> |
Snippets: Ruby Switch Statements
June 20, 2007 @ 10:47 AM | posted by carmelyne
(last updated: 06.24.07)1 2 3 4 5 |
case foo when 1 then puts "Foo is equal to 1" when 2..9 then puts "Foo is between 2 and 9" when 10 then puts "Foo is equal to 10" end |
Source: http://railsforum.com/viewtopic.php?pid=27834#p27834



