Rails 3 Memcached Session Store

23 08 2011

Couldn’t be simpler in Rails 3.

Dalli is the new standard gem for dealing with memcached.

Gone are the days of “memcache, memcache-client, memcached” clusterfuck. Just use Dalli.

All theses steps are outlined in the Dalli README.

So if you don’t want to read the README here you go:
1. drop gem "dalli" in your Gemfile
2. In config/application.rb or config/environments/*.rb drop in config.cache_store = :dalli
3. In config/initializers/session_store.rb put the following:
require 'action_dispatch/middleware/session/dalli_store'
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 30.minutes





Show last two directories of pwd in BASH prompt

21 09 2009

Problem: Show current directory and one above it in bash prompt.

finished bash prompt

finished bash prompt

So ok googling for a few hours produced a failed attempt at using PROMPT_DIRTRIM=2 (which only works on bash v.4 which is not installed on OS X, you can get it from macports so i wish you good luck)

Found a post here that looked like it might have worked… nope. Then I looked this post which was sort of unrealated but there was a useful comment from swobodin which i used to get this to work.

The function is:

function last_two_dirs {
pwd |rev| awk -F / '{print $1,$2}' | rev | sed s_\ _/_
}

So I dropped that in my ~/.bash_profile and I call the function from my export PS1 line (with colors and git functions too):

export PS1='\[33[0;32m\]$(date +%H:%M:%S) \[33[0;36m\]$(last_two_dirs)\[33[0m\]$(__git_ps1)\[33[0;33m\]$(git_dirty_flag)\[33[0m\] ➡  '





MacPorts MySQL + MySQL Gem Install Protips

6 07 2009

We moved off of MySQL at work and I hosed my machine, so I never reinstalled mysql.

The I started working on the upgrade to Rails 2.3 for Rentmappr.com and I realized I needed mysql.

So you know, port install that shit right?

sudo port install mysql5 mysql5-server mysql5-devel

Ok that took forever boo. Yay for PostgreSQL’s quick port and gem install! I suggest moving big projects to that if you can and small ones to sqlite, ditch mysql people its not really worth it.

So now, we need the mysql gem. Gem install that shit.

sudo gem install mysql

uh fuck...

uh fuck...

uh fuck…

So I need to pass it some flags because MacPorts installs everything in /opt

Uh ok… so let’s try –with-opt-dir

almost

almost...

Closer but no cigar.

Now what? Google!

Finally googled for “macports mysql gem split TrueClass” and found the solution:

sudo gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

credit: http://codeintensity.blogspot.com/2007/09/installing-ruby-mysql-gem-with-macports.html

Yay!

almost...

fucking finally!





Engineering Goals

16 03 2009

I got a lot of good stuff out of going to Mountain West Ruby Conference this weekend. Sitting here this morning I’ve come up with some goals I have for myself and my engineering team.

  1. Excel at usability
    • This is more a personal goal than anything
    • But its important for us to get right
    • If people can’t fully use our software they find shortcuts and often break things
  2. Improve cross team understanding
    • More pair programming – if we can each better understand everyone’s code, we can make sure we are doing things correctly, in a sane way, and we can better maintain each others code
    • I have learned so much from just spending a few hours looking over other team members shoulders. This helps me come up with new ideas and I better understand our complex code base and algorithms
  3. Improve testing
    • We have really great coverage on our models, i.e. we’ve unit tested the shit out of our code (mostly). However, these tests are way to close to the metal, we need a higher level set of tests (using something like Cucumber and WebRat). We need to know exactly how new features will affect the entire code base from a very high level.
    • This will help in organizing new features, instead of a bunch of us in a room going, “uh, well, uh I think that shouldn’t break anything”, we can say, first, “why?” and then second “this feature will break these X number of things and will take X number of hours to complete”
  4. More Instrumentation
    • how much load can our systems handle?
    • where are our bottlenecks and what pieces of infrastructure need to be retuned/replaced/recoded?
    • who actually uses each product?
    • this will also help us say either “yes, we can add more load, more data, new features, etc…” or “no we really can’t add X feature until we’ve fixed X piece of code/infrastructure”




Helper Methods for render :update do |page|

10 02 2009

@aneiro showed me this the other day and I just got it to work. So here’s what’s up.

Instead of having a metric crap-ton of rjs files I just started doing render :update do |page| in my controllers. This lets you do, as some people complain, javascript view logic in your controller. So I ended up with three actions that each call the same set of JS. Hide that thing, replace this div with a partial, show some stuff, fade some things, change the css class of that table row, etc…

So what you can do is this: define a method in your controller and put all the page.replace_html and page.hide calls in it. Do it. Ok so then in your render :update block you just call that method and pass page to it.

One caveat is you have to actually define your new method as a helper method, which is super easy. Just call, in your controller, helper_method .

Check out the gist: http://gist.github.com/61454





Design By Management = Bad Idea

5 02 2009

Management didn’t get to where they are by being good designers. They do not know what looks good and what looks bad. They do know, I hope, how to run a business.

You should leave complex things like typesetting, color theory page layout, etc to a designer. Management types should worry about getting their khakis to match their wingtips, and what color seats to put in the new Audi.

Steps for not letting management ruin your company’s image:

Step one: DO NOT LET THEM DESIGN THE WEBSITE

Step two: DO NOT LET THEM DESIGN POWERPOINT TEMPLATES

Step three: DO NOT LET THEM DESIGN LETTERHEAD OR LOGOS

Step four: DO NOT LET THEM DESIGN EMAIL SIGNATURES

Management likes to think they can do anything. Its America, anyone can do anything right? No. You are wrong. Management is good at telling people what to do and doing things like quarterly projections and attending bullshit conferences to speak on bullshit panels to other bullshit management people.

They are not designers. They are rarely creative. They rarely know how to even open Photoshop. They need to be told Microsoft Word is not professional design software. They need to be told to not use shitty fonts like Impact and Trebuchet.

If you can’t afford good design help, then fine, leave your image and brand to the wind. Its not like huge corporations ever got anywhere by thinking a lot about how things look and how other people perceive their company through visual mediums. Nope that never happened.





Don’t leave this page cause I said so dialog

26 01 2009

I have a process where I create an object on one screen, and then in the next screen add some information to that object.

Problem is, if you navigate away from that second page I have an object that has no important info attached to it.

My process is a wizard approach to setting up a new account, which only really has a name, and then the account has users and billing info attached to it in separate models/tables. So give it a name and save it, redirect to the next screen and add users and billing.

So I want the “Hey you! Don’t navigate away” dialog to appear on all but a few links and form submits on the add users and billing page. Its actually super easy.


Take a look at this very nicely formated gist
I would put this stuff in code tags and display it here but it looks like crap and I can’t embed gists unless I pay wordpress. And wordpress stripped all my erb and html tags so just go look at the gist.






Give Wikipedia some money, you know its helped you win bets.

22 12 2008

Wikipedia Affiliate Button





Rentmappr.com ToDo

24 11 2008
  • ajax change city
  • lightbox welcome (after choose city) (with a don’t show this again – store in session – if they then login check that option and add to db)
  • get rid of saved_houses div if not logged in
  • scroll_to for images/streetview
  • click city name to choose city in addition to ‘pick this city’ link
  • searching not working







Follow

Get every new post delivered to your Inbox.