Friday, April 27, 2012

Configuring Emacs: TRAMP

TRAMP is an Emacs library that allows you to remotely edit over a number of different protocols including ssh, sftp and scp.   With the later TRAMP libraries you have to list a set of names which define the servers you will be accessing.  The good news is you can use globs.

(require 'tramp)
(set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:"))))

You can edit remotely over an ssh connection by executing find-file and passing it:

/ssh:servername.com:path/to/remote/file

This can be used in conjunction with Transparent Multihop Connections in your ssh config to provide easy transparent access to machines behind ssh gateways.

§

Wednesday, April 25, 2012

An Abrupt Introduction: Scaling


How to scale:
  • Identify your bottlenecks.
  • Identify the best solution for the problem.
  • Check to see if you can implement the the solution.
  • Identify alternate solution(s) and check ability to implement.

Typical Scaling Options:
  • Vertical Scaling (bigger, faster server hardware)
  • Load balancing (active/active, active/passive)
  • Split tiers/components out onto more/other hardware
  • Offload work through caching/cdn

Database Scaling Options:
  • Vertical Scaling (bigger, faster server hardware)
  • Replication (active or passive)
  • Clustering (if DBMS supports it)
  • Sharding
§

Friday, April 20, 2012

Disambiguation: Dependency Injection vs. Avoidance of Globals

Dependency injection is about decoupling code. When you avoid the use of globals by passing arguments you are decoupling code. You are removing the dependency the code has on the globals.

You can generalize this decoupling to more than just the avoidance of globals. Take the following code:

def foo(arg):
   return ClassBar(arg).attr

foo(1)

The function foo is dependent on or tightly coupled to ClassBar. The reason this is not good is you will be forced to update foo when:
  • the arguments to ClassBar constructor changes
  • you want to change the creation of a ClassBar object to something else
  • another piece of code wants to access attr from a different object
If the code was rewritten:

def foo(instanceBar):
   return instanceBar.attr

foo(ClassBar(1))

You've pushed the coupling up to the caller. This removed the dependency from the definition of foo. This frees you from having to update foo in the cases outlined above. The more of your code that is decoupled, the fewer code changes you'll need to make.

§

Configuring Emacs: making TRAMP use ssh-agent

TRAMP provides Emacs with remote editing over ssh and sftp sessions.  We should be able to leverage ssh-agent to eliminate the need for passwords when using TRAMP.  Sometimes it doesn't automatically use the ssh-agent.  It may be because of a custom configuration, old version, or a platform that isn't full supported.  This is one technique that has worked for me.
  • In your emacs config set SSH_AUTH_SOCK.
cat >> ~/.emacs <<EOF
(setenv "SSH_AUTH_SOCK" (concat (getenv "HOME") "/.ssh-auth-sock"))
EOF
  • Start the ssh-agent
  • Add and authenticate your key to the ssh-agent
  • Create a soft link to the ssh auth sock file
cat >> ~/.profile <<EOF
test -r ~/.agent && . ~/.agent

ssh-add -l > /dev/null 2>&1
test ${?} = 2 && ssh-agent -s > ~/.agent

ln -sf $SSH_AUTH_SOCK ~/.ssh-auth-sock

ssh-add -l > /dev/null 2>&1
test $? = 1 && ssh-add
EOF


Now you should be able to test TRAMP.  Access a file on a server with authorized_keys set up and verify you don't get prompted for a password.

§

Wednesday, April 18, 2012

Using Mercurial: Backing out changeset(s)

Backing out changeset is the process of applying the inverse patch of that changeset.  By extension, you can backout a range of changesets by applying the inverse of patch of all the changesets.  This should be the default methodology of "reverting" a change or set of changes as it will maintain the consistency and completeness of the repository.

  • hg pull
  • hg up # Now your working directory and local repo are up to date
  • hg up -r revLast # Update to the latest revision you want to backout
  • hg revert -a -r revFirst-1 # Creates an inverse patch of revFirst to revLast
  • hg ci -m "Backed out revFirst - revLast" # Commit inverse patch
  • hg merge # Merge inverse patch to tip in my working directory
  • hg ci -m "Merged change back into the tip" # Commit inverse patch to tip in local repo
  • hg push # Push to master

Reference http://ehsanakhgari.org/blog/2010-0Whether iWhether i9-09/backing-out-multiple-consecutive-changesets-mercurial

§

Mac Apps I Use

Thursday, April 5, 2012

Fix: SSHKeychain hanging in Lion

Update: I have since discontinued use of SSHKeychainin favor of openssh-agent.

Since upgrading my Mac to Lion I've been having problems with SSHKeychain.  After a sleep the SSHKeychain would be hung (aka. spinning beachball).  I would have to kill it and restart or I would get prompts for my passphrase when I used ssh.


Turns out it is due to the security setting "On Keychain Events".  Since setting "On Keychain events" to  "No action", I havn't had SSHKeychain hang. 

§