Get Familiar with Ruby using EdgeCase’s Ruby Koans

2011.12.04 | Ruby | , , , ,

EdgeCase has published a great walkthrough of the various Ruby language features. They call it Ruby Koans.  The Ruby Koans are a a collection of broken tests.  Each broken test is designed to teach you something about the Ruby language.  Many are fill-in-the-blank, eg:

  def test_every_object_has_different_id
    obj = Object.new
    another_obj = Object.new
    assert_equal __, obj.object_id != another_obj.object_id
  end

To pass this koan/test, you’d replace the “__” with true, because new instances of objects have new object_ids.

I wouldn’t recommend this for people new to programming, but if you’re like me and used Ruby a few years ago but have fallen out of practice, it’s a perfect re-introduction.  If you’re new to Ruby but have a solid background in other languages, this may be of use as well.

Get rid of the green border around links on Android browser

2011.11.30 | Android, Web Development | , , , ,

Want to get rid of that green border that shows up after a user has clicked a link in the Android browser?  Do this:

* {
     -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

The Web App Development Methodology

2011.11.25 | Web Development | ,

Check out 12Factor.net and the accompanying Hacker News discussion.

OS X: Image Capture opens when you plug in your iPhone

2011.11.22 | iOS, OS X | , , , , , ,

Options for Image CaptureWant to stop Image Capture from opening every time you plug your iPhone, iPod, or iPad in, and perhaps have iTunes open instead?  At some point in the recent past I must have accidentally set this option, but having not intentionally done so, I couldn’t recall how to set the default back to iTunes.

To disable Image Capture: With the device plugged in via USB, open Image Capture.  In the bottom left corner of the main application area, you should see the name if your iDevice and the text “Connecting this iPhone opens:” followed by a dropdown.  Click No Application.

To make iTunes open when you plug in your device: Open iTunes with your iPhone/iPad/iPod connected.  Select your device under Devices in the left column.  In the main window, scroll down to Options.  Check “Open iTunes when this iPhone is connected.

Compilation of Very Useful Linux Commands

2011.11.20 | Linux | , , , ,

Someone over at reddit has asked users to “Give me that one [linux/unix command] you wish you knew years ago.

Rapid Javascript Prototyping with jsFiddle

2011.11.18 | Web Development | ,

I’m sure a lot of people already know about this tool, but if you haven’t, head on over to jsFiddle and enjoy being able to rapidly mock up widgets, test third party libs, or just isolate some tricky piece of code to see why it’s going wrong!

Android browser CSS position: fixed bug (solved)

2011.11.17 | Android, Web Development | , ,

There’s a very annoying bug in Android browsers that’s not intuitive to fix: Sometimes position:fixed just doesn’t work right.  For me this manifested as the browser thinking that the bottom of the page was about 40px higher than it actually was, but only in landscape mode.

Without further ado, the fix is simple: set your meta viewport tag to not allow user-scaling.

<meta name="viewport" content="width=100%; initial-scale=1; maximum-scale=1; minimum-scale=1; user-scalable=no;" />

 

Conditionally Display High Resolution Images in HTML/CSS for Retina Displays

2011.11.16 | iOS, Web Development | , , , , ,

Project 365 Day 175: Worth Queueing ForIt’s really easy to do but I tend to forget how to do it since it’s only applicable to mobile projects:

Let’s say you have: 200px by 100px image.png and the same image twice as large (400px by 200px) called image_highrez.png.

First, we can’t just use a plain ol’ <img> tag. We have to use the commonly done trick of creating a div with the same height/width as the image, then setting the background to the image. Anyone who’s used CSS sprite sheets should be very familiar with this process.

HTML:

<div id="our-image"></div>

CSS:

div#our-image {
  background-image: url(image.png);
  height: 100px;
  width: 200px;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) {
  div#our-image {
    background-image: url(image_highrez.png);
    background-size: 200px 100px;
    -webkit-background-size: 200px 100px;
  }
}

Easy!

Heroku Quickstart Tutorial / Guide / Cheatsheet

2011.11.13 | Web Development | , , ,

For those who use Heroku with enough regularity to not need the full beginners guide, but not enough to have memorized the install / setup process, Heroku has published a quickstart guide:

Heroku Quickstart Guide

dyld: Library not loaded: @executable_path/../.Python

| Python | , ,


Problem:

You’re trying to use a virtual environment created on a different computer, or you’ve upgraded / reformated your machine and you’re using the virtenv from your backup of the old machine.

Now you try to do a pip install but you get the following error:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /your/project/path/./bin/python
  Reason: image not found

Solution:

The python executable or libraries in the virtualenv directory are not compatible with your current architecture. This happened to me when I reformatted my Macbook to run OS X 10.7 Lion from an older version of OS X.

To fix, you’ll need to create a new virtual env. What you can do is freeze the packages the current virtualenv is using (if you’re not doing this already), and then install them in the new virtual environment.

pip freeze -E your_old_environment > requirements.txt
pip install -E your_new_environment -r requirements.txt

Now use your new virtual env as you did your old one. it’s also good practice to keep a file with the latest contents of pip freeze in your code repository, in case you need to build new virtualenvs in the future (or deploy them).