Denis 'jumph4x' Ivanov

Hey there. I'm a full stack web developer for FCP Groton. Currently in CT. I am generally an arrogant freethinker and a frequent linestepper. These are my notes, ProTips (R) and LULz.

Ensuring a Trailing Slash in Rails W/Out Dependencies

For some reason this is more difficult in rails than it should be.

The semantic value of the concept of having a trailing slash in the URL is basically one of representing a folder, a virtual directory. In RESTful terms, this represents a collection route, or an :index action. Exhibit A:

GET /products/

This page will list many products as links. In restful terms, this will lead to the :show action. In this instance, we are representing a final destination, a member route. This dictates no trailing slash, semantically speaking:

GET /products/some-permalink
GET /products/some--ther-permalink

So how to deal with this in Rails? Rails will naturally favor slash-less versions of all URLs, unless specified otherwise. Step one is to generate all internal links the correct way, to do this, simply pass the :trailing_slash => true key-value pair to your named route. You ARE using named routes like you should be, right? Good.

member_path(object, :trailing_slash => true) or
collection_path(:trailing_slash => true)

This will generate the correct link. Excellent. However, when you write your routing or functional tests, like you should be, testing the extreme input, you will notice that the slash-less routes work just fine and Rails acts as if everything is normal.

I expected to be able to find a way to deal with this cleanly, by accessing a hash of sorts in the Rails’ request object, but nothing came up. the params hash omits this. As does request.request_uri, request.path and even request.fullpath. Well, shiet, what’s a bro to do?

Well, take a look at my solution in the form of a pair of private methods in ApplicationController:

class ApplicationController < ActionController::Base

private
  def ensure_trailing_slash
    redirect_to url_for(params.merge(:trailing_slash => true)), :status => 301 unless trailing_slash?
  end

  def trailing_slash?
    request.env['REQUEST_URI'].match(/[^\?]+/).to_s.last == '/'
  end
end

Then, when we need to use this in any actual controller, we simple declare the following:

class ObjectController < ApplicationController
  before_filter :ensure_trailing_slash, :only => :index
  [...]
end

Notice I am using 301 redirects here, as a sound SEO measure.

Hope this helped, until next time.

superamit:

Many of you have asked, so here’s what’s going on with me.
WHAT HAPPENED BEFORE
8/1979: Born. Grew up in CT, built a killer eraser collection, fell in love with computers.
Left college to start a company. Fell hard. Fled to India for 3 months.
Started 2nd company. Learned to be an adult. Fell in love with NYC.
Moved to SF, discovered burritos &amp; some of my fave people on Earth.
9/2011: Got diagnosed with Leukemia!
Cried. Went through 3 cycles of chemo. Hurt. Thought hard about what I want out of life. Grew up a second time.
TODAY
… After over 100 drives organized by friends, family, and strangers, celebrity call-outs, a bazillion reblogs (7000+!), tweets, and Facebook posts, press, fundraising and international drives organized by tireless friends, and a couple painful false starts, I’ve got a 10/10 matched donor!
You all literally helped save my life. (And the lives of many others.)
WHAT HAPPENS NEXT
Tomorrow, I’ll be admitted to Dana Farber in Boston for 4-5 weeks.
First I’ll get a second Hickman line to allow direct access to my heart (for meds and for nutrients if I’m not able to eat). Over the next week, the docs blast my body with a stiff chemo cocktail to try and eradicate all traces of cancer cells. In the process, the immune system I was born with, and my body’s ability to make blood, are destroyed.
Next Friday, I get my donor’s stem cells by IV. I start on immunosuppressants to prevent my body from rejecting them (I’ll be on them for 12-18 months). For these weeks I’ve no immune system, so I’m severely vulnerable to viruses and bacteria. My hospital room and hallway become my world.
Meanwhile, the stem cells make their way to my bone marrow and, with some luck, start producing platelets, red blood cells, and white blood cells. At this point, my blood type changes to the blood type of my donor. And my blood will now have my donor’s DNA, not my own.
This is science fiction stuff. I can hardly believe it’s even possible, and there’s lots of chances for things to go wrong. It’s frightening.
AFTER THE TRANSPLANT
Recovery to a new state of “normal” takes about a year, but there’s a few storm clouds hovering:
My immune system is new, like a baby’s. I’m prone to getting sick.
Just as with any organ transplant, there’s a chance of rejection. Except in this case, it’s my blood that’s the foreign body, and it touches every organ. They call it graft-vs-host-disease and it can cause health issues and organ complications for the rest of my life.
Successful transplant or not, Leukemia can relapse. Stubborn mofo.
Overall, 75% of AML transplant patients survive year one, 50% make it through year five. My odds are a little better since I’m young.
THE GREAT NEWS
I’ve got a long road ahead. But I’ve got a donor &amp; amazing family &amp; friends. A few months ago I didn’t have many options. Today I have a plan.
I am alive. I start tomorrow. Wish me luck!
Thank you.

Reblogged from superamit

superamit:

Many of you have asked, so here’s what’s going on with me.

WHAT HAPPENED BEFORE

  • 8/1979: Born. Grew up in CT, built a killer eraser collection, fell in love with computers.
  • Left college to start a company. Fell hard. Fled to India for 3 months.
  • Started 2nd company. Learned to be an adult. Fell in love with NYC.
  • Moved to SF, discovered burritos & some of my fave people on Earth.
  • 9/2011: Got diagnosed with Leukemia!
  • Cried. Went through 3 cycles of chemo. Hurt. Thought hard about what I want out of life. Grew up a second time.

TODAY

… After over 100 drives organized by friends, family, and strangers, celebrity call-outs, a bazillion reblogs (7000+!), tweets, and Facebook posts, press, fundraising and international drives organized by tireless friends, and a couple painful false starts, I’ve got a 10/10 matched donor!

You all literally helped save my life. (And the lives of many others.)

WHAT HAPPENS NEXT

Tomorrow, I’ll be admitted to Dana Farber in Boston for 4-5 weeks.

First I’ll get a second Hickman line to allow direct access to my heart (for meds and for nutrients if I’m not able to eat). Over the next week, the docs blast my body with a stiff chemo cocktail to try and eradicate all traces of cancer cells. In the process, the immune system I was born with, and my body’s ability to make blood, are destroyed.

Next Friday, I get my donor’s stem cells by IV. I start on immunosuppressants to prevent my body from rejecting them (I’ll be on them for 12-18 months). For these weeks I’ve no immune system, so I’m severely vulnerable to viruses and bacteria. My hospital room and hallway become my world.

Meanwhile, the stem cells make their way to my bone marrow and, with some luck, start producing platelets, red blood cells, and white blood cells. At this point, my blood type changes to the blood type of my donor. And my blood will now have my donor’s DNA, not my own.

This is science fiction stuff. I can hardly believe it’s even possible, and there’s lots of chances for things to go wrong. It’s frightening.

AFTER THE TRANSPLANT

Recovery to a new state of “normal” takes about a year, but there’s a few storm clouds hovering:

  • My immune system is new, like a baby’s. I’m prone to getting sick.
  • Just as with any organ transplant, there’s a chance of rejection. Except in this case, it’s my blood that’s the foreign body, and it touches every organ. They call it graft-vs-host-disease and it can cause health issues and organ complications for the rest of my life.
  • Successful transplant or not, Leukemia can relapse. Stubborn mofo.

Overall, 75% of AML transplant patients survive year one, 50% make it through year five. My odds are a little better since I’m young.

THE GREAT NEWS

I’ve got a long road ahead. But I’ve got a donor & amazing family & friends. A few months ago I didn’t have many options. Today I have a plan.

I am alive. I start tomorrow. Wish me luck!

Thank you.

False Positive Tests in Rails, ProTip

False positive tests are a special kind of evil. This is the kind of stuff that will cost you your annual raise.

One of the ways this has recently crept up and done me wrong is very intuitive, yet so hard to find if you look in all the wrong places: caching.

Specifically:

# app/controllers/your_controller.rb

Rails.cache.fetch(you_key) do
  # testable code
end

At this point, make sure your environment is set up to do what you want:

# environments/test.rb

config.action_controller.perform_caching = false

Also take a look at my new and improved test helper. I use TestUnit with Shoulda:

# test/test_helper.rb
class ActiveSupport::TestCase
  setup do      
    Rails.cache.clear
  end
end

class ActionController::TestCase
  setup do      
    Rails.cache.clear
  end
end

Good luck, hope you never trick yourself into false confidence inspiring tests.

"How are you doing?"

Asked by Anonymous

Better than most, thank you!

Checking for Select.h… Rake Aborted! AKA Wrong Number of Arguments (3 for 2)

Was trying to build Webroar on our virtualized box for internal deployments and ran into this.

Required directories created successfully. Building executables...
checking for select.h... rake aborted!
wrong number of arguments (3 for 2)

First World Problem

An hour later…

This is a rake version mismatch. The stuff expects 0.8.7, I had it installed along with 0.9.2 which was where the executable symlink was pointing to.

gem remove rake -v=0.9.2
gem install rake -v=0.8.7

Doneski.

Current status: 3yr girlfriend anniversary. Hung up the piece above bed.

Current status: 3yr girlfriend anniversary. Hung up the piece above bed.

Testing Rails 3.0.9 w/ Spork and Spork-TestUnit: no such file to load — test/unit/testresult (LoadError)

Heyyo all,

Quick one. Has this happened to you recently?

/home/denis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load --     test/unit/testresult (LoadError)
from /home/denis/.rvm/rubies/ruby-1.9.2-    p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/denis/.rvm/gems/ruby-1.9.2-p290/gems/spork-testunit-0.0.6/bin/testdrb:7:in `<top     (required)>'
from /home/denis/.rvm/gems/ruby-1.9.2-p290/bin/testdrb:19:in `load'
from /home/denis/.rvm/gems/ruby-1.9.2-p290/bin/testdrb:19:in `<main>'

Lock your spork-testunit at 0.0.5 and use:

bundle exec spork T
bundle exec testdrb -I test/ [...]

Alternatively you can remove wrong version of testdrb executable:

 gem uninstall spork-testunit


Select gem to uninstall:
 1. spork-testunit-0.0.5
 2. spork-testunit-0.0.6
 3. All versions 
 > 2
minusmanhattan:

Exploring Abandoned Teufelsberg by Eddie Codel.

Reblogged from minusmanhattan

minusmanhattan:

Exploring Abandoned Teufelsberg by Eddie Codel.

Reblogged from whatelseiscool

(Source: whatelseiscool)

Me. In salem

Me. In salem

Me.

Reblogged from b14nc44

Me.

(Source: b14nc44)

Current status: pimpin. Valvecover + Wheels + Bike.

JPEG Compression w/ ImageMagick (convert) thru Paperclip

So this has been bothering me for a while: 175x85 JPEG weighing in at 84kB.

But I didn’t really get off my ass and do anything serious until now that the Google PageSpeed Tool has been released: https://developers.google.com/pagespeed/

So it tells me this is complete garbage and that I can save quite literally, shit you not, 93% when recompressed losslessly.

Are you serious?

Turns out the image is nicely compressed to 2.5kB and the rest 80+ kB are wasted by embedded profiles?

convert E320BELTKIT.jpg -quality 40 rite60q.jpg
ls rite60q.jpg -la
-rw-rw-r-- 1 denis denis *84289* 2011-10-19 17:45 rite60q.jpg
convert E320BELTKIT.jpg -quality 40 -strip rite60q.jpg
ls rite60q.jpg -la
-rw-rw-r-- 1 denis denis *2467* 2011-10-19 17:45 rite60q.jpg

Reference Paperclip configuration:

has_attached_file :attachment,
              :styles => { :mini => {:geometry => '48x48#',
              :convert_options => { :mini => "-strip"}