My Saturday
I offered to drive my Mom and my aunt anywhere they wanted. They chose to go to Bohemia National Cemetery. It didn’t take too long and we found what we were looking for.
An Accident
I have had two snakes (that I’ve seen) in my backyard for as long as I’ve owned my house. For the most part, they can do whatever they want back there and I don’t care. I usually only see them when I’m cutting the grass and they quickly slide away. Today, the grass was a little taller and I didn’t see one of them and I think I killed him. I feel pretty bad about this.
Ruby Dates
In one of my apps, the price of registration for an event goes up after a particular date. So I have to check if today’s date is after the given date. Here’s how I’ll do this:
A Little Bit More
Had to fill my garbage cans again, so I took out a cabinet. Now I need to put a valve on my gas line, so I can disconnect the stove. And then it will be time to get rid of the sink. At that point, I’ll be sad because washing dishes will be a pain. (I’m thinking I’ll just go and buy paper plates and cups.)
A Fun Vacation
I signed up to the Five Boro Bike Tour in NYC over last weekend. I took my folding bike on Amtrak and it was a pretty good trip. It would have been great, but Amtrak is definitely not the way to travel. (Next time I want to go somewhere on a train, I first need to go to Europe.) As this was my first vacation in a while, I was very much looking forward to it.
Little vim tricks
Our datalogger saves files in a windows format, which means when I open it in a unix program, I don’t see any line feeds. The quick solution to this is to open the file in vim and run:
Little More Work
I took the morning and tried to take down a bit more of the wall in the kitchen. It was nice being able to stand on the counter to reach the high parts. Here’s how things look now.
Libv8 Gem Problems
I had some problems installing the libv8 gem after installing ruby 2.0. The solution was to use yum to install the python26 packages and then make a link from them to /usr/local/bin/python. After that the gem install libv8 command worked.
Requiring https
My apps tend to just be electronic sign-up sheets for various events. There’s no way we’re going to pay for an SSL certificate for a site that will probably be up for a month or two, at most. However, we do require people administering the page to login, which means passwords which need to be encrypted. That’s really all I care about encrypting, not the entire site. So, my somewhat simple solution is:
More Capistrano
Capistrano used to have a pair of tasks called deploy:web:disable and deploy:web:enable that I really liked. All they basically did was to upload a file to the webserver that would be displayed while a new version was deploying. I thought this was really helpful because if anyone visited the site during the deployment, they’d see the message that the site was under maintenance. Without this file, visitors to the site would see a cryptic rails rack error that made no sense. Sometime last year, after a capistrano update, I realized that these tasks were no longer there. By that time, I had understood that it was just uploading a file, so I could duplicate the tasks manually by editing a file to add the current time and then uploading it to the webserver. (In either case, I had to modify my httpd.conf file to reflect the location of the file.) Then, after the update, I’d remove the file. This wasn’t difficult, but it was WAY easier to do this:
Spoke Too Soon
When I came home from work, I was feeling a little full of myself and then I wrote my previous blog post. I spent the past couple of hours watching some Railscasts that were really informative, on using capistrano to do all sorts of things. So I changed my capistrano file quite a bit and do feel that I understand it a bit more.
Advancing
Today, I started a new ruby on rails website for a workshop. It’s a very basic site that just handles registrations and redirects people to the credit card processor that we use. This is the main type of website that I write in rails and it’s probably my tenth site that I’ve written for this purpose. Previously, I had always used scaffolding in rails and then deleted the stuff that I didn’t need. This time, I made a conscious choice to not use any scaffolding and instead generate my own controllers and models. I’m happy to say that I didn’t have any real problems. So I’m thinking that I’m no longer a complete beginner with rails. I might even go so far as to say I’m an intermediate rails programmer. Which means it’s time for me to start advancing some more. I found this website http://learn.thoughtbot.com and was thinking of signing up for the prime program. The intermediate ruby on rails workshop looks pretty interesting. Though, after reading the syllabus, I’m thinking that perhaps I was at intermediate level a while ago. In the listing of things that they plan to cover, I already know a few:
Little Work
My organizing kick really tired me out. I slept for a very long time and didn’t feel like doing anything today. But I felt I should do something today, so I decided to just finish taking the drywall off the back of the kitchen. It didn’t take long, but since I was already tired, it pretty much finished me for the day.
Organizing Kick
Since I was doing a bit of organizing at work this week, it has carried over to my house. This is not a mood I’m usually in, so I decided to take advantage of it and do a little work on my basement. My basement needs a lot of work, so this put a very small dent into it. I’d say I cleaned up about a quarter of the basement. And I’m pretty happy with that.
A Few Good Hours
I woke up and decided I better get started. So, down came the upper cabinets, except for the one with the vent going outside. I’ll do that later.
It Begins Again
It’s March and I’ve finally saved up enough (I hope), so I started work on my kitchen. Here’s a shot of the first two cabinets I took down.
RHEL6 No graphics, error: could not open default font ‘fixed’–SOLVED
After some updates from RHEL6, some users were having problems with X not starting. Looking at the log file, I saw this error:
Ruby 2.0 with Other Versions
Ruby 2.0.0 came out today and I thought I’d install it. I had been using rvm to handle my multiple versions of ruby, but when I tried to do a rvm install 2.0.0, I got a bunch of errors about homebrew. It seems as though homebrew is now required. This is a problem for me because I’ve been using MacPorts for years and I just don’t feel like switching right now. So, I figured that I’d just see if I could compile it myself by hand and come up with a way to have multiple versions of ruby. The thing is, I really don’t switch between versions all that much. I will now, as I slowly convert all the sites I have to 2.0. So I’ll need to go back and forth a little. But once it’s done, I probably won’t switch for a long time. I’ve been on 1.9.3 for a very long time and it worked fine. Anyway, I’m not exactly sure how I’ll do this, but I’m going to give it a try.
First step, was to update XCode and then go into Preferences and update the command-line tools. In the ruby download, my config command was pretty basic:
ant:ruby-2.0.0-p0 $ ./configure --prefix=/Users/maryh/Software/rubies/2.0.0-p0
Putting everything in a Software/rubies/version directory seems to be a good idea. I could be completely wrong about this, but that’s how I’m starting. My first make attempt failed with an error like this:
compiling ./missing/setproctitle.c compiling dmyext.c linking miniruby /Users/maryh/Downloads/ruby-2.0.0-p0/lib/fileutils.rb:111: [BUG] Stack consistency error (sp: 38, bp: 36) ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0] -- Crash Report log information -------------------------------------------- ...
I needed to set CC=clang (it was CC=gcc-4.2) and that fixed this problem.
New error:
compiling readline.c readline.c:1688:9: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'? rl_username_completion_function); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rl_username_completion_function readline.c:75:42: note: expanded from macro 'rl_username_completion_function' # define rl_username_completion_function username_completion_function ^ /usr/local/include/readline/readline.h:449:14: note: 'rl_username_completion_function' declared here extern char *rl_username_completion_function PARAMS((const char *, int)); ^ 1 error generated.
Readline errors are apparently common. Again, I’m pretty sure this is related to the fact that I’m using MacPorts. My fix was to:
ant:ruby-2.0.0-p0 $ export LDFLAGS="-L/opt/local/lib"
Then rerun configure and make and things worked. Everything is installed in /Users/maryh/Software/rubies/2.0.0-p0. And the gem environment is:
ant:bin $ ./gem env RubyGems Environment: - RUBYGEMS VERSION: 2.0.0 - RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [x86_64-darwin12.2.0] - INSTALLATION DIRECTORY: /Users/maryh/Software/rubies/2.0.0-p0/lib/ruby/gems/2.0.0 - RUBY EXECUTABLE: /Users/maryh/Software/rubies/2.0.0-p0/bin/ruby - EXECUTABLE DIRECTORY: /Users/maryh/Software/rubies/2.0.0-p0/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-12 - GEM PATHS: - /Users/maryh/Software/rubies/2.0.0-p0/lib/ruby/gems/2.0.0 - /Users/maryh/.gem/ruby/2.0.0 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/
So, now I think I can just install gems there and see how things go.
More Ruby Notes
I just found out that these two ruby commands do the same thing.
Rails3 form_for vs form_tag
I’ve been advancing a little in my rails work, to the point where I’m making more elaborate forms. So I’ve had to switch to using form_tag instead of the form_for that’s the default when you use scaffolding. I have a pretty good understanding of the differences now, so I’m documenting it here.
Sendmail on Mac OS X 10.8
I wanted to use sendmail to test the sending of some messages in one of my apps. The command I wanted to run was:
Ruby File Open Options
I spent a little time looking for this info, so I thought I’d post it here. Use it like this:
File.open("#{output}","a") do |w| w << "#{Time.now.to_s(:datetime_stamp)} Other text to write end
Remember if you use File.open or CSV.open with a block, the file is automatically closed when the block closes. Otherwise you have to close the file.
Mode | Meaning -----+-------------------------------------------------------- "r" | Read-only, starts at beginning of file (default mode). -----+-------------------------------------------------------- "r+" | Read-write, starts at beginning of file. -----+-------------------------------------------------------- "w" | Write-only, truncates existing file | to zero length or creates a new file for writing. -----+-------------------------------------------------------- "w+" | Read-write, truncates existing file to zero length | or creates a new file for reading and writing. -----+-------------------------------------------------------- "a" | Write-only, starts at end of file if file exists, | otherwise creates a new file for writing. -----+-------------------------------------------------------- "a+" | Read-write, starts at end of file if file exists, | otherwise creates a new file for reading and | writing. -----+-------------------------------------------------------- "b" | Binary file mode (may appear with | any of the key letters listed above). | Suppresses EOL <-> CRLF conversion on Windows. And | sets external encoding to ASCII-8BIT unless explicitly | specified. -----+-------------------------------------------------------- "t" | Text file mode (may appear with | any of the key letters listed above except "b").
Drop a Column in MySQL Table
For some reason, my migration file wouldn’t drop a column when I tried to go back to an earlier version. I fixed this by just going into mysql and dropping the table manually.
Simple Dropdown Menu of Numbers
Every so often I need to make a simple dropdown menu of numbers in my app. And for some strange reason, I always seem to forget how to do this. So here are some examples for myself to use when I forget the next time.
Update Multiple Boolean Attributes in Rails3
We are hosting an event where students need to submit two pieces of paper and pay to attend. The model I’ve created has three boolean values for these three items: safety_waiver, image_waiver and paid. As the forms and payments come in, I could manually edit each entry and check off who has paid or not. But, since I’ve done a few of these events in the past, I know it would be easier if I could just see a list of everyone who hasn’t paid or turned in their waivers and check a bunch at once. I tried following Railscast #52, which was great and almost got me there, but didn’t work for me in the end. So here’s what I did.