Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts

  • quinn 2:47 pm on September 18, 2011 Permalink | Reply  

    401 Unauthorized in Omniauth + Devise + Twitter 

    This stopped me up for a few minutes. You have to specify the callback url that devise creates for you:

    http://(domain)/auth/twitter/callback

    This needs to specified in the application config on twitter.com. Without this it will give a 401 for all requests.

     
  • quinn 1:55 pm on April 14, 2011 Permalink | Reply
    Tags: assets, coffeescript, css, jammit, , , , sass   

    CoffeeScript and Sass in rails (compiling assets is the future) 

    I just read on Ruby Inside that sass and coffeescript are being added into Rails 3.1 along with an asset management pipeline. It uses 37signal’s sprockets to compile the assets into compressed files for inclusion in your views.

    I’ve been using this as my default stack for awhile now. I posted the rails template I’ve been using on github (it’s long, so I decided not to embed it): https://gist.github.com/919846

    I’ve always loved using “syntax alternatives” like these but their esoteric nature has really limited adoption so I’ve had trouble pushing them on colleagues / coworkers. It’s validating to see them being moved into rails core and getting such mainstream support.

    Mine is a little different than what is being added to rails so lets take a look at it. I chose jammit instead of sprockets (sprockets always felt a little immature as a project) but it is similar. Basically, it works like this:

    your uncompiled assets start off in the app directory:

    app/stylesheets/*.sass
    app/coffeescripts/*.coffee

    And then barista and haml mirror them in public:

    public/stylesheets/compiled/*.css
    public/javascripts/compiled/*.js

    Neat huh?!? But there are still multiple files, and they are still all uncompressed. That’s where jammit comes in. When in production, jammit takes those to paths above and compiles + compresses them into:

    public/stylesheets/compiled.css
    public/javascripts/compiled.js

    Awesome! Then, in your application layout, all you have to do is:

    include_javascripts :compiled

    The nice thing about this is if there is a single file called “compiled.js” it uses that or if there is a folder called “compiled” it will include everything in the directory. That way in development you have all of the separate files for easier debugging.

    These changes will be hard for some to swallow–but Rail’s purpose was never about catering to the masses. Rails is finally pissing people off again.

     
  • quinn 4:29 pm on October 7, 2010 Permalink | Reply
    Tags: , , jquery   

    faking placeholder from html5 in jquery 

    I just coded up a simple plugin to enable placeholder text for inputs in browsers that don’t support it yet. This isn’t tested thoroughly, please let me know if anything isn’t working properly!

    Check it out on github: http://github.com/quinn/jquery.placeholder.js

     
  • quinn 12:58 pm on September 29, 2010 Permalink | Reply
    Tags:   

    this is an amazing little bit of javascript: http://erkie.github.com/

     
  • quinn 11:36 am on September 24, 2010 Permalink | Reply
    Tags: aws, ec2, , s3, work   

    new website up contactjam.com, built using rails 3 

    Exciting news, my friend Kevin (http://www.linkedin.com/pub/kevin-incorvia/20/339/508/) just launched an alpha of his new site: http://contactjam.com. Cool! In a nutshell it is a “foursquare” that also ties in the time and the locale of other people. Its really neat, but I don’t want to give too much away because it is still in a closed alpha. I had the privilege of building the first iteration using rails 3, datamapper, and deploying it on aws using ec2 and s3. I’ll keep you posted with updates about it as it develops.

     
  • quinn 10:51 am on September 21, 2010 Permalink | Reply
    Tags: bash,   

    Quickly search through your Bash history 

    Is everyone up on ctrl+R in bash? It lets you do a reverse filter search through your bash history (kind of like history piped to grep but cooler). It’s really handy, I’m guessing most everyone knows it already but just in case anybody missed it, you should definitely give it a try.

     
  • quinn 8:30 am on August 30, 2010 Permalink | Reply
    Tags: datamapper, geocode, ,   

    Why I think datamapper is awesome 

    I know Datamapper is probably considered “old news” at this point, which is something I think unfortunate considering its low adoption rate. I’m going to re-hash its advantages here just to add my own voice to its fan base. Here are some of the reasons I really like datamapper. In no specific order.

    #1 robust query mapping

    the datamapper API is robust enough that it drastically reduces how much one has to drop down to sql to get the desired results. For example:

    class Book
      include DataMapper::Resource
    
      property :published_at, DateTime
    
      belongs_to :author
    
      def self.published_recently
        all :published_at.gte => 1.week.ago
      end
    end
    
    Book.all.published_recently.authors
    

    only executes a single query. neat right?

    #2 The property API

    Datamapper favors explicit property definitions rather than attempting to infer them from the table. There are advantages to this, such as easier introspection and tighter control over serialization. Also, one of the ways that Datamapper offer’s to its users to add features is the property api. One can create their own classes to extend datamapper’s serialization and property mapping through a sussinct api:

    module DataMapper
      class Property
        class Geo < Yaml
          def dump(value)
            if value.nil? || value.kind_of?(Geokit::GeoLoc)
              super(value)
            else
              raise ArgumentError, "+value+ must be nil, String or Geokit::GeoLoc"
            end
          end
    
          def typecast(value)
            return value if value.nil? || value.kind_of?(Geokit::GeoLoc)
            geoloc = GeoKit::Geocoders::MultiGeocoder.geocode(value)
            unless geoloc.success
              raise ArgumentError, "+value+ is not a valid address"
            end
            geoloc
          end
    
        end
      end
    end
    

    This piggybacks on the existing yaml implementation that exists here: http://github.com/datamapper/dm-types/blob/v1.0.0/lib/dm-types/yaml.rb . Basically, you get two methods, one for loading (deserializing) from the database and one for dumping (serializing) to the database. Using the above class you can now:

    class Profile
      include DataMapper::Resource
    
      property :id, Serial
      property :address, Geo
    end
    
    profile = Profile.new
    profile.address = "Brooklyn Bridge"
    profile.address.district #=> "Manhattan"
    

    #3 inclusion over inheritance

    I suppose this one is largely a stylistic preference. I like explicitly saying include DataMapper::Resource that way you know where to include your modules. for example

    module DataMapper::Resource
      include MyModule::InstanceMethods
    end
    
    module DataMapper::Model
      include MyModule::ClassMethods
    end
    

    This is about as simple as it gets in my opinion. DataMapper::Resource’s self.included method simple extends the current class with DataMapper::Model and does nothing else. To me this is clean and simple and doesn’t add any fluff on top of what ruby does by default.

    Rails 3

    Rails 3 will fix many of these problems, but I think DataMapper’s api is still unique enough to merit looking into. Despite the improvements to activerecord 3 I plan on continuing to use datamapper in future projects.

     
  • quinn 4:21 pm on August 24, 2010 Permalink | Reply
    Tags: typography   

    added the Tallys font for some headers

     
  • quinn 8:30 am on August 23, 2010 Permalink | Reply
    Tags: deployment, , nginx   

    Switching wordpress to nginx 

    I just updated my server to use nginx from apache/mod_php because loading wordpress on my tiny slicehost slice was tanking the poor thing. Apache was spawning processes like crazy and pages were taking forever to load, even when I am the only person viewing the site. My new setup uses php-cgi based on this tutorial:

    http://tomasz.sterna.tv/2009/04/php-fastcgi-with-nginx-on-ubuntu/

    this is what my nginx config looks like:

    server {
      listen          80;
      server_name     blog.quinnshanahan.com;
    
      access_log      /var/log/nginx/blog.quinnshanahan.com.access_log;
      error_log       /var/log/nginx/blog.quinnshanahan.com.error_log warn;
    
      root            /var/www/blog.quinnshanahan.com;
    
      index           index.php index.html;
      fastcgi_index   index.php;
    
      location / {
        # this sends all non-existing file or directory requests to index.php
        if (!-e $request_filename) {
          rewrite ^(.+)$ /index.php?q=$1 last;
        }
      }
    
      location ~ \.php {
        include /etc/nginx/fastcgi_params;
        keepalive_timeout 0;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
      }
    }
    

    highly recommended.. its amazing how much faster it is!

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel