danielsenhwong.com

Would you recognize yourself?

without comments

I’ve recently spent a lot of time thinking about how I’ve changed over the past five and ten years. Arbitrary time points to be sure, but any significant amount more than that, and we’re talking about a middle school-aged kid, and really, how is that at all useful? I think this really came out of interviewing applicants for my undergraduate institution.

To the point: if the person you were five or ten years ago were to meet the person you are today, would you recognize yourself? What would you think? How about the reverse: if the person you are today were to meet the person you were five or ten years ago, what would you think?

Written by dan

February 21st, 2011 at 8:27 pm

Posted in Personal

Tagged with ,

Context is Important

without comments

Judge me all you like for leaving and ending things the way I did, but your opinion is meaningless if you lack the facts.

I was the one being abused in an emotionally abusive relationship. I left.

Written by dan

February 16th, 2011 at 12:22 am

Posted in Personal

Tagged with ,

Comparing Schools

with one comment

This is a work in progress.

If I attend , it might mean that I head down a basic science path. I’m not sure at what point I’d be able to mash tissue engineering into my career, if ever. Angiogenesis comes close, but isn’t really the same thing. Also, lots of friends here, but I’m worried that if I attend and become the ridiculous student I should have been as an undergrad, people will hold it against me. Social currency is money, of which I have and will have little.

If I attend , I can mash tissue engineering into my career immediately. There are at least three different laboratories I could rotate through that, at the very least, have collaborations which involve tissue engineering. I also have a few friends here, but they’re all in school and similarly busy. Social currency is intelligence, which is great.

If I attend , I’m not sure what I’d really be doing. Genetic Medicine research looks very interesting, but tissue engineering is not something that is done here. Few friends in the area. High cost of living without much justification. Social currency: connections.

Table below.
Read the rest of this entry »

Written by dan

February 11th, 2011 at 5:54 pm

Setting up Ruby on Rails in OS X

without comments

I consulted quite a few sources online to try and figure out how to do this, and ran into a few problems that took entirely too much time to solve. Now that I’ve figured them out, I’m writing the solutions here in the event I need them again. Hopefully they’ll be useful to a few other people as well.

Goals

Create a Ruby on Rails development environment with Apache, MySQL, and PHP.

There are several possible ways of doing this, but since OS X is a Unix-based platform, I don’t see any reason to use pre-compiled packages like MacPorts and replacing the built-in software. Plus, this is supposed to be a learning experience.

Sources

http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x-snow-leopard-10.6.1/

Read the rest of this entry »

Written by dan

January 9th, 2011 at 7:54 pm

Counting records by category [RoR]

without comments

In my Rails application, I have an inventory of items described by three models: the items (cryovials), the place they’re stored (dewar), and the information about which vials is stored where (ln2_locations).

The reason I used three models, rather than rolling the attributes of the third (ln2_locations) into the actual item was that in reality, we normally freeze down multiple vials with the same content at the same time.  I would like to implement this kind of mass assignment at a later time.

Anyway, it is often useful to be able to determine what we have stored, and how much of each different type of content is present. It’s one thing to know what the SQL code would be to retrieve these records; it’s another to convert that to an ActiveRecord query when you’re just learning.

What I would like to do is look at my items (cryovials), and pull out the unique content values (e.g. cell types), then go back and count how many vials I have with that content. It would be pretty easy to accomplish this as two separate statements, but that would involve iteration and two separate SQL queries. Best to leave it as one query where I count and select unique fields simultaneously:

Rails:

@summary = Ln2Location.select("count(*) count, contents").joins(:cryovial).where(:present => true).group(:contents)

SQL:

SELECT count(*) count, contents FROM `ln2_locations` INNER JOIN `cryovials` ON `cryovials`.`id` = `ln2_locations`.`cryovial_id` WHERE (`ln2_locations`.`present` = 1) GROUP BY contents

I’m selecting on Ln2Locations because there’s a property, “present,” which I’m using to select only the vials which haven’t been physically removed from the collection. Additionally, the relationship between the models is as follows:

class Cryovial < ActiveRecord::Base
# Relationships
belongs_to :user
has_many :dewars, :through => :ln2_location
has_many :ln2_locations
accepts_nested_attributes_for :ln2_locations
class Dewar < ActiveRecord::Base
# Relationships
belongs_to :laboratory
belongs_to :location
has_many :cryovials, :through < :ln2_locations
class Ln2Location < ActiveRecord::Base
# Relationships
belongs_to :dewar
belongs_to :cryovial

So only the child model, Ln2Locations, contains the foreign key that would be used to generate the join table.

Written by dan

October 19th, 2010 at 2:10 pm

Posted in Projects,Web Dev

Tagged with

Ruby on Rails: Integrating Devise

without comments

It is possible to integrate devise into your rails app as part of your user model in order to provide authentication support.

- add desired attributes to migration file
- make added attributes accessible in model file
- either roll your own views or add fields to generated views

That’s it. It really isn’t difficult or different than making any other model.

I was worried that it would be complicated, and spent a lot of time reading about devise to be sure. It’s so easy, no one writes about it.

Written by dan

October 14th, 2010 at 11:57 pm

Posted in Projects,Web Dev

Tagged with ,

Database Optimization: Indexing

without comments

After installing devise, I was looking through the migration file, and noticed a couple add_index commands. Reading up on what this actually does, I came across a couple interesting articles about database optimization:

Optimizing your MySQL Application

Indexing for DB performance

details: http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001468&name=add_index

I don’t plan to build a giant Rails application, but Rails is known to have scalability issues. Still good to be aware of these points.

Written by dan

October 13th, 2010 at 10:26 am

Ruby on Rails: on shared hosting, user authentication

without comments

* As usual, this post on Ruby on Rails is more documentation of my development process to supplement my notebook and memory. I can try to answer questions, but please keep in mind that I’m learning too.

I’ve bought the eBook version of the 4th edition of the Pragmatic Programmers’ Agile Web Development with Rails. It’s still in beta, but my main goal is to see how things have changed between Rails 2.x and Rails 3. The book also covers some basic user authentication, but it’s very simplistic. In the interest of getting my project up and going quickly, I looked into authlogic and devise/warden.

Both authlogic and devise/warden were highly recommended by mischa after building an application that did some direct comparisons of several different RoR user authentication solutions. Good enough for me. devise appears to be more lightweight, so I’ll try that one first.

A little bit about my server setup: I’m hosted with Lithium Hosting, which is a great deal and has fantastic customer service. They’re not paying me to pitch the service, though clicking the link above and then signing up for a plan gives me referral credits or something. It’s a shared hosting service, so I manage my site with cPanel if I need/want to, and I’ve added on SSH access to my account so I don’t really need to use cPanel.

Once the server upgraded to Rails 3.0/Ruby 1.8.7, a couple things happened: my rails apps stopped starting automatically (cPanel feature), cPanel could no longer start my rails apps, and I couldn’t create a new Rails app with a MySQL database.

Solutions:

1) install the mysql2 gem, which is the new mysql database adapter used by Rails 3. The compilers are disabled on my host, so this was done via support ticket.

2) add mongrel to my Gemfile,

#project/Gemfile
gem 'mongrel'

Mongrel isn’t automatically started in development mode. cPanel still won’t start my application, so starting the server is done via SSH with

rails server --port=[port]

So now I can create a new project

rails new project --database=mysql

and start the server. However, I don’t have a good way of authenticating users.

So, back to the support tickets to have both authlogic and devise installed. Once tech support has done that (seven minutes. really.), check if they’re installed for me:

gem server --port=[port]

and navigate to mysite.com:[port]. They’re not, run a couple commands from the command line:

gem install devise
gem install authlogic

Which should install the gems and make them available to me. Checking again as above, and both devise and authlogic are present. Add the appropriate lines to my Gemfile. Then, since I’m trying out devise first, install it:

rails generate devise:install

That’s all for now.

Written by dan

October 12th, 2010 at 4:23 pm

Ruby on Rails: Migrating data, too

without comments

Sometimes it makes sense to re-organize information in such a way that changing the database structure is necessary. It’s not terribly difficult to do this in Ruby on Rails.

I’m writing this more to file this away somewhere I won’t accidentally delete it:
Read the rest of this entry »

Written by dan

October 5th, 2010 at 11:50 am

Biking Updates

without comments

Cannondale Quick CX RigidThree weeks ago, I finally bought a bike after talking about it for about two years.

Last night, I was almost doored by a guy getting out of his car. He opened his door, then kicked it out open even more without looking back. There were four other people on bicycles in front of me, and a patio full of restaurant patrons who would have seen if I had hit the door and gone through the window. Thank goodness I was already on the brake. Bike lanes are great, but I don’t really like being in the door zone. And so much for lights alerting drivers to my presence.

Written by dan

July 24th, 2010 at 7:18 pm

Posted in Uncategorized

Tagged with ,