I whipped this up to remove all spans and/or divs in an HTML. Don’t ask why. Here’s the regex:
< ?(span|div)[a-zA-Z0-9'" =]+>
Did I mention I love regex?
Enjoy.
- Grab Package from EnterpriseDB.
- Find exact version location in /Library/PostgreSQL/x.x/
- Put above dir + bin in PATH
- sudo gem install ruby-pg
When needing to perform a String.replace() with some regex and globally replace text. You must remember to put the “g” argument like so:
var str = “‘http://www.com/123/123′”
str.replace(/’/g,”")
Spent a few minutes banging my head on this one. So remember the “g”!
Jquery makes a lot of things really easy. This one, not so much. Take this Select as an example:
SOURCE:
<select id="sort_by" name="sort_by"><option value="F%3Dlistingid%3A1%7Csmallphotos%3A1%7Clistingseopath%3A1%7Cpropertyname%3A1%7Cpropertycity%3A1%7Cpropertystate%3A1%7Clistingpricelow%3A1%7Clistingpricehigh%3A1%7Clistingbedlow%3A1%7Clistingbedhigh%3A1%7Cwebtollfree%3A1%7Clatitude%3A1%7Clongitude%3A1%7Cgeocode%3A1%7Ccityseopath%3A1%7Cfrontcover%3A1%7Cmsa_code%3A1%26N%3D5875%26Nao%3D0%26Nf%3Dgeocode%7CGCLT+48.803100%2C-102.245600+5%26Ns%3Dsortpropertyname%7C1%26Ntk%3Dshowapartment%26Ntt%3D1%26Nu%3Dlistingid%26Ns%3Dsortorder%7C0">Best Match</option> <option value="F%3Dlistingid%3A1%7Csmallphotos%3A1%7Clistingseopath%3A1%7Cpropertyname%3A1%7Cpropertycity%3A1%7Cpropertystate%3A1%7Clistingpricelow%3A1%7Clistingpricehigh%3A1%7Clistingbedlow%3A1%7Clistingbedhigh%3A1%7Cwebtollfree%3A1%7Clatitude%3A1%7Clongitude%3A1%7Cgeocode%3A1%7Ccityseopath%3A1%7Cfrontcover%3A1%7Cmsa_code%3A1%26N%3D5875%26Nao%3D0%26Nf%3Dgeocode%7CGCLT+48.803100%2C-102.245600+5%26Ns%3Dsortpropertyname%7C1%26Ntk%3Dshowapartment%26Ntt%3D1%26Nu%3Dlistingid%26Ns%3Dsortpropertyname%7C0">Property Name A to Z</option> </select>
When you perform a selection and want to do some onclick magic, how to get the current selected option text? Like this:
$('#sort_by')[0].options[$('#sort_by')[0].selectedIndex].text
Told it wasn’t pretty. Thanks Troy for helping.
wget -r -p -U Mozilla http://www.modrails.com/documentation/Users%20guide.html
Goals:
- To auto start with init.d, upon westhost restart, etc.
- Use Apache to front end, via mod_proxy.
You’ll have to follow other sites on installing gems, etc. This Site has some very useful info, namely you need to symlink mongrel_cluster_ctl and ruby to /usr/bin/ (you’ll have to do a find / -name mongrel_cluster_ctl). Mine was here: /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/bin/mongrel_cluster_ctl
So I linked into /etc/init.d/ like so:
ln -s /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/bin/mongrel_cluster_ctl /etc/init.d/
chkconfig is not installed on westhost, so you have to do the init.d link/scrips the old fashioned way:
ln -s /etc/init.d/mongrel_cluster_ctl /etc/rc.d/rc3.d/S81mongrel_cluster
ln -s /etc/init.d/mongrel_cluster_ctl /etc/rc.d/rc3.d/K19mongrel_cluster
K = Kill, the number means the order
S= Start, “”
This all came up b/c I wanted to write a shared mixin module to have attachment_fu ready actions for all my controllers that have attachments. No need to put that crap in every controller. So in a mixin module when you want to do some fun reflection/introspection like so:
…
@this_obj = self.controller_name.classify.constantize.find_safe (id,logged_in_user.id)
…
In Dev this worked great. Tests were good, my mostly view/template developer partner, approved. Deploy to test and WHAMMO!
…
"NameError ("Blogs | ListAll" is not a valid constant name!):
…”
What gives? Mmm, seems when you include a mixin, that is included in a controller. The self.controller_name will report incorrectly in Test and Prod. So I had to adjust the code a little using a new method:
@this_obj = self.this_controller_name.classify.constantize.find_safe( id,logged_in_user.id)
Below is the method(which is basically David’s code for controller_name).
###############################
#This method is here b/c it is apparent that Rails #ActionController.controller_name
# is unreliable in Test and Production for some reason.
# attachment_symbol_name: Blogs | List_all_attachments
# attachment_model ERROR: "Blogs | ListAllAttachment" #is not a valid constant name
###############################
def this_controller_name
self_class = self.class.to_s.sub(/Controller$/, '').underscore
end
In a model or util class, parse number to determine the telecom provider (example: http://www.notepage.net/smtp.htm). Create an email message to the respective email @ address for that provider.
Issues:
SMTP is not as time sensitive.
But for a small web app, is this ok?

