barely-wait-credit-great-workplaceSometimes you accidentally commit code under the wrong author or committer credentials.  This has happened to me a few times while writing code from computers with global git settings.  By using `git filter-branch` it is possible to rewrite history… muhahahah!

This snippet will run through your branch’s historical commits and rename the author and committer attributes.

It basically looks for all commits containing a given `$OLD_EMAIL` and resets the following properties:

  • GIT_AUTHOR_NAME
  • GIT_AUTHOR_EMAIL
  • GIT_COMMITTER_NAME
  • GIT_COMMITTER_EMAIL

The code:

This code is an updated version of the “nuclear option” code provided in the ProGit book.

Finally just push:

git push --force --tags origin 'refs/heads/*'

There’s an amazing quote I see floating around the Internet sometimes…

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live”

The quote is sometimes mistakenly credited to Martin Golding in 1994.

The reality is that in 1991 John F. Woods authored it in a post to the comp.lang.c++ newsgroup.  The body of his message follows:

>Mark>I was wondering why it seems that the comma operator is so rarely used.
>Mark>The only time I ever see it is in ‘for’ loops. Is it really considered
>Mark>*that* bad by the programming public at large? Any comments?
>Rob>Well, I hadn’t seen it used much either outside of the for loop, but
>Rob>in Plaugher’s latest book I discovered quite a few of the following
>Rob>constructs:
>Rob> if (condition)
>Rob> var = value, anothervar = anothervalue;
>Rob>This does away with the need for braces. I am tempted to use this myself
>Rob>unless someone has a good point agains using this style. Opinions anyone?
>Consider this:
> if (condition)
> var = value; anothervar = anothervalue;
>Only one little dot is changed, but the meaning is quite different. In other
>words, using the comma operator like that makes it harder to read:
Right.

Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live. Code for readability.

 

Amazingly, thanks to Google’s mirror of the comp.lang.c++ newsgroup, you can actually view John F. Woods’ post.

ice_cube_gangster_fishing_at_first_i_was_likeHave you ever had this happen to you?

  1. You finish writing some awesome code.  You’re a bad ass and you know it.
  2. You hit the command line, because you stopped creating GUI interfaces using visual basic a long time ago.
  3. Issue a little “git add” here and there, add some broth, a potato.  Baby, you’ve got a stew going… So you commit!
  4. You do the habitual post-commit “git status” for no good reason and there it is, the file you friggen forgot to add to the commit you already committed to.

Fortunately git has a really convenient way to amend to your last commit!  Just simply stage the file(s) you missed and run:

git commit --amend

Today at AppAcademy we have gone through almost all of Michael Hartl’s rails tutorial.  I just wanted to quote Hartl explanation of what a database index is and how it works.  I love the analogy because it’s probably the most simplistic examples I’ve probably ever seen:

Putting an index on the email column fixes the problem. To understand a database index, it’s helpful to consider the analogy of a book index. In a book, to find all the occurrences of a given string, say “foobar”, you would have to scan each page for “foobar”. With a book index, on the other hand, you can just look up “foobar” in the index to see all the pages containing “foobar”. A database index works essentially the same way.

Bam!

wat-gigantic-duckFirst off, I stole this pic from Greg Pike’s post about Javascript.  Now that the confession is out of the way…

Today at App Academy my pair and I were asked to explain the meaning of Ruby’s “double pipe equals” operator  to our cohorts.  I figured that might be a good topic to post here.

The double pipe equals, which will be referred to as “||=” from now on, is an operator that’s used for conditional assignment.

In a nutshell the||= operator’s usage is something like this:

blah ||= blabbity_blah()

This essentially says: “if blah is false then set it to blabbity_blah(), otherwise leave it set to whatever it was before we started”

Here’s a contrived, but-still-real-code, example lifted (and modified) from Wikibooks:

 

descartes looking flyHere’s a cool chain of info nuggets that starts @ Renè Descartes and ends @ Ruby’s Array.product, lol.

Renè Descartes was a French philosopher and mathematician born in 1596.

He’s known for lots of things but one of the most popular is the following quote  from a passage in his publication Discourse on Method (1637):

I think, therefore I am” (or the corrected version “I am thinking, therefore I exist“)

Renè Descartes  developed “analytic geometry”, an algebraic description of geometry.  A pair of numbers can represent a specific coordinate on a plane or graph.  Sets of coordinates can be represented on a graph as well… and this gets us closer to the end of this nugget chain…

“Analytic geometry” is also known as “Cartesian geometry”… with the name stemming from Descartes’ own name.  In the Cartesian view, when given a plane (think … graph), any point on the plane can be represented by coordinates — in a 2 dimensional plane these might be X and Y, in a 3 dimensional space this might be something like X, Y and Z.

A cartesian product is the result of taking  two sets and returning all permutations of their combined results.  So for example, if you had a set of numbers named X that contained: “1,2,3” and a set of numbers called Y that contained “-5,-6,-7”, their cartesian product would be:

[1, -5], [1, -6], [1, -7], [2, -5], [2, -6], [2, -7], [3, -5], [3, -6], [3, -7]

And finally getting back to Ruby…. this is where Array.product gets it’s name!

Array.product is awesome and will get you the Cartesian product for a given array against a number of other arrays!

/fin

im here to serve and protect and get my treatsRuby provides 3 ways of classifying a methods in a Class: Public, Private and Protected.  These keywords are used to declare a method’s visibility and essentially what you’re doing is restricting access to the individual methods contained in your class.

Here’s a quick and dirty about the differences:

Public

These methods are accessible by anyone who calls your class.  They define your class’s public “interface”.

Protected

Protected methods are accessible by objects of the same class.  By this definition, a good use case is when classes extend your class and want to access those methods.  The subclass will retain access into the super class’s protected methods.

Private

Private methods can mask the gory details of how the public/protected take input and generate output.  One way to look at this is that these methods are essentially for the “author of the object/class”.  And by “author” I do mean the guy who wrote the code.  Because private methods are not publicly exposed — aka someone who calls your class doesn’t have access to them — private can be considered free for refactoring, changing and deletion without worrying that your outside callers are going to have problems.

Here’s a cool trick for dealing with situations where you want to assign multiple values at the same time.

The technique used is called parallel assignment and it looks something like this:

 

 

If you’re working with game boards, this is super useful way to pass around board coordinates!!