Modern Day Software Development

git config core.filemode false

via (Jeroen Leenarts)

“Open Terminal Here”. is a small service which becomes available in the context menu of every file and folder in the Finder with an entry called “Open Terminal Here”.

It’s function is really simple, it activated the Terminal application and changes the current directory to selected directory or the containing directory, depending whether you selected a file or folder.

The linked zip file contains a file named: “Open Terminal Here.workflow”If you would like to change the name appearing in your services menu, just change the name of the file to something else. make sure the extension remains the same. For example: “Any other Name.workflow”.

After you are happy with the services name, copy the resulting file to the directory “Library/Services” in your user’s home directory. Now you can open a Terminal window at the location you’ve just selected, it works for multiple selections too.

Here’s the link to the zip file: Open Terminal Here 0.3.zip

Oh just a little tip, to open the current Terminal.app path you’re at into a Finder window, just type “open .” followed by a return. (Yes, that’s 4 characters, a space and finally a dot.)

SideBarEnhancements: A nice SublimeText extension that I stumbled upon today. It adds a bunch of file operations, that one can easily execute by right-clicking on each file/folder in the left sidebar.

Particularly, I like it because it allows me to duplicate files in a very quick manner.

NOTE: It can be installed directly via Package Control

Instagram’s “white lies”

redhurtmachine:

Mark Wilson, Fast Co. Design:

What Instagram labels as “optimistic actions” really boil down to something far simpler: Always make it look like the service is working, even when it’s not.

Really interesting article on how Instagram decreases frustration through design “white lies.” It’s brilliant - everyone should adopt this way of handling io errors and interface speed.

(Source: fastcodesign.com)

Inverse Self-Referential Relationships in Rails

Removing a friend from our list.

(via RailsCasts)

Inverse Relationships

When creating self-referential relationships it’s important to remember that we’re only creating one side of the relationship. Although eifion has paul listed as a friend above, if we were to visit paul’s profile we wouldn’t see eifion listed unless paul had chosen to add him. We need two Friendship records to create a mutual friendship.

To finish this episode we’ll add a list to the profile page so that a user can see who has them listed as a friend so that we can see the other side of this relationship. To do this we need to add two more relationships to the User model.

ruby
class User < ActiveRecord::Base
  
  has_many :friendships
  has_many :friends, :through => :friendships
  
  has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
  has_many :inverse_friends, :through => :inverse_friendships, :source => :user

  #rest of class omitted.
end

It’s difficult to think up appropriate names to define the other side of the relationship so we’ll prefix both with the word “inverse” to give us inverse_friendships and inverse_friends. We need to specify some additional options to make the relationships work. For inverse_friendships we’ll have to specify the name of the other model as it can’t be inferred from the relationship name and we’ll also have to define the foreign key as friend_id. For the inverse_friends relationship we need to specify the source asusers, as again it cannot be inferred from the name of the relationship.

Quick Tip: Skinning a File input element

I have been using bluimp’s file uploader in a few of my projects. It is a nice, extendable plugin that seems to work consistently among the different browser specs.

It wasn’t until I changed the default template that blueimpUI comes in, with a lighter one, that I realized that my “Add files…” button no longer works under Firefox. That got me into opening the black box, that I considered blueimp to be till then, and start inspecting.

I was sure that to make “Add files…” work, BI must be using a hidden <input type=”file”> element. Indeed, a quick jQuery search ( $(“input:file”) ) indicated the element, wrapped in a series of jQueryUI specific divs. Without much looking at the actual JS code, I assumed that the plugin must be attaching a click handler to the wrapper div, in which it manually triggers the click event of the file input element. That’s why I commented out the initialization of blueimp, and manually triggered a click to the file input element:

$(“input:file”).trigger(“click”)

Then I realized that this can work only under Firefox, and not on any WebKit based browsers (Chrome and Safari). Hmm, there must be something else then. Then it saw it … As I later researched upon, that seems to be a dirty trick, that however seems to work pretty well. 

The whole idea is to wrap the file input element in the div, without applying display:none to it, we will need it to be present in the DOM layout during the whole time … only not visible to the end user. This is the sample layout

 <div class=”btn fileinput-button”>

<span>Add files…</span>

<input class=”file-input” type=”file” name=”files[]” >

</div>

Now, the trick lies in smart styling. In particular: 

.fileinput-button {

  overflow: hidden;

  position:relative;

}

.fileinput-button file-input {

  opacity: 0;

  filter: alpha(opacity=0);

  position:absolute;

  top:0px;

  right:0px;

}

See? We do not take the file input out of the layout, we position it absolutely, so it stays precisely positioned on top of what we see as a button. It is made invisible, so that we can see the button itself. The overflow:hidden protects the the file input element of catching clicks outside of the scope of the button. This way both the button and the file input will register a click 

There are a number of people, myself included, who have been observing for a while now that the current web stack feels like Flash did in 1996. Look at the canvas demos, for example. The canvas demos we’re seeing now are totally reminiscent of the Flash demos we used to see in the ‘96 era, where it was like: “Hey, look! I have three circles and you can grab one with a mouse and flick it. And then it bounces around the box and there’s physics and collision and animation and they’re blobby and woo hoo.