Viewing entries tagged


My Science Tattoo: Why I did it, and what it means?

I got my tattoo yesterday, here is how it looks like.

When a close friend, co-worker, or family looks at it for a minute, I get two immediate reactions:

  1. That's a badass tattoo! But what is it? What it means?
  2. Why did you do it? If you change your mind later on what you inked then [blablabla]...

I've always liked tattoos and for some time wanted to get something done that was truly meaningful to me.  I was inspired and got my last bit of courage from the Science Tattoo Emporium Discover Magazine, and decided to materialize it.

Here is what I incorporated in the tattoo and why:

Pi (Π)

Why?: There are the three math constants that blow everybody's mind once they realize how closely connected they are to the universe. They are Pi (Π), Euler(e), and Phi(φ). For my tattoo I decided to go with Pi, since is a universally known constant that doesn't require much introduction, yet is a totally badass one. Here's why:

  1. It's one of the oldest known constants in mathematics. It dates back to 2589–2566 BC, when the Egyptians built the Great Pyramid of Giza, whose ratio between the volume and height is exactly 2Π.
  2. Pi is found everywhere we see a circle shape, since you calculate Pi by dividing the circle's circumference by its diameter (Π=C/d). Many people learn this by memory in school, but never truly get to understand what it means, or even how to interpret what Π represents in the context of a circle. The circumference of a circle is slightly more than 3 times its diameter, and number is what Π represents. Wikipedia has a good animation of Pi 'unrolled'
  3. Pi is both irrational and transcendental, and passes all tests for normality and statistical randomness. These properties make it the only known constant with universal distribution of its digits that cannot be represented by the fraction of any two numbers, or polynomial with rational coefficients.
  4. Pi is part of the most beautiful mathematical equation of all time: Euler's identity
  5. Pi is heavily used in formulas from other branches of science, such as cosmology, number theory, statistics, fractals, thermodynamics, mechanics and electromagnetism.

Carbon Atom

Why?: Carbon element is present in all forms of life. It the most abundant element by mass on the human body, only after Oxygen. Every organic compound is takes form, mass and strength thanks to carbon bonds, making carbon the chemical foundation of all known life.

Fibonacci Tiling

Why?: Fibonacci tiling is the composition of squares whose sides are successive Fibonacci numbers in length (1,1,2,3,5,8, etc). The series F(n) = F(n-1) + F(n-2) is a mysterious one in the world of mathematics. Its exemplar simplicity makes it easy to be understood by almost every body, yet it's found in the most complex settings in science. Here are a few that will blow your mind:

  1. The Fibonacci numbers are also an example of a complete sequence. This means that every positive integer can be written as a sum of Fibonacci numbers, where any one number is used once at most.
  2. Found in the sum of shallow diagonals in the Pascal Triangle
  3. In numbers represented on base 2, or binary, they are spotted quite often. The samples below and the fact that computer science and electrical engineering use the binary system more than I can count every second, makes this sequence far more interesting  and mysterious to me. Check this out:
    • The number of binary strings of length n without an even number of consecutive zeroes or ones is  twice  Fn.
    • The number of binary strings of length n without an odd number of consecutive ones is  Fn+1.
    • Also, the number of binary strings of length n without consecutive ones (1) is Fn+2.
  4. The Fibonacci cube is an undirected graph with a Fibonacci number of nodes that has been proposed as a network topology for parallel computing.
  5. In music, Fibonacci numbers are used to determine tunings, and, as in visual art, also to determine the length or size of content in the formal elements.

Golden Ratio (φ)

Why?: The Golden Ratio is yet another mystical mathematical rarity. Two numbers {a,b} are in the golden ratio, when the sum of the quantities divided by the larger of the two is equals to the larger divided by the smaller.

  1. With {a,b}, with a>b; {a,b} are in the golden ratio <=> ((a+b)/a) = (a/b)
  2. To make it even cooler, it turns out that it doesn't matter what numbers a and b are, if they are in the golden ratio => a/b = φ = "Phi", a mathematical constant calculated by the equation (1+√5)/2, and dating back to Plato's time.
  3. Mathematicians throughout history have obsessed with this constant, including: Phidias, Plato, Euclid, Fibonacci, Pacioli (coining it the "divine proportion"), Da Vinci, Kepler and Ohm.
  4. Fibonacci series have a close relation to the Golden Ratio, so much so, that Kepler observed how consecutive numbers in the Fibonacci series converge to the Golden Ratio. This is both sick and awesome, like some sort of mind game the universe is playing on us:
  5. In art, it is a proportion that dictates aesthetical pleasures to the human eye. It is found in master pieces such as Leonardo Da Vinci's "Mona Lisa" and Salvador Dali's "Leda Atomica"
  6. In Nature, the Golden Spiral (one on the center of the tattoo) is found in the shapes of many living organisms, such as:
    1. The arrangement of branches along the stems of plants and the veins in leaves;
    2. The skeletons and adjacent bone lengths in animals;
    3. The proportions of chemical compounds and the geometry of crystals
    4. Almost all human body proportions between adjacent organs, organ systems, bones, and body parts exist in complete harmony following the Golden Ratio.
    5. The groves of the human DNA's double helix.
    6. The human perception of beauty is based on how closed our facial expressions align with the Golden Ratio.
  7. From cloud formation, to river networks, to craters, lighting bolts and coast lines, the Golden Ratio has a recurring presence.
  8. There are too many manifestations of the Golden Ratio in science to mention here; but one of the most interesting ones is in chaos theory and the fractal sets.
  9. With all the above, you feel there is something magical, mysterious and universal about Phi and the Golden Ratio, that makes it a special science jewel.


Why?: Silicon is a chemical element with atomic number 14, that makes about 28% of Earth's crust. Is also one of the most used materials in the production of semiconductors and integrated circuits used in computers every day. That's where the "Silicon Valley" name comes from. The reasons for choosing this element as part of the tattoo are obvious to those that know me over the years. I'm the ultimate nerd, and I'll be wearing those circuits in my arm with proud.

I think is pretty safe to say these science elements will not change anytime soon, so my tattoo will remain meaningful to me an the world in the foreseeable future ;)

I'm super happy how it turned out... and I'll be sporting my science tattoo for the rest of my life with pride.

There is strong, and then, there is nerd-strong! :P



SQL - Select rows in chaotic order

Ok, another SQL trick. How to get a row set where the rows are ordered by a specific value sequence of a particular column?

This is not a very common problem, but if you happen to need something like this, you may scratch your head for a couple of minutes before you figure it out.

So, the challenge is the following, you have a table like the one below:


If you want to return all rows with ids 4, 5, 7 and 8  in order by any column, you can do so easily using order by [the_column] asc or desc; but if you want to return those same rows in a chaotic desired order is no so trivial.

Say we want the rows ids 4, 5, 7 and 8 and we want them such that the ids appear in the following order: 7, 4, 8 and then 5

Before looking at how to do it, challenge yourself and try to come up with that query.

Ok now let’s look at the solution. It involves the use of the CHARINDEX string function. CHARINDEX returns the starting index of parameter1 in the string given on parameter2, if parameter1 is a substring of parameter2. For example:

[sourcecode language="sql"] SELECT CHARINDEX ( '23', 'AA23BB') --returns 3 SELECT CHARINDEX ( 'abc', 'aapppabcbc') --returns 6 [/sourcecode]

That means we can do something similar with a set of numbers when treated as a strings, like so:

[sourcecode language="sql"] SELECT CHARINDEX ( '7', '7,4,8,5') --returns 1 SELECT CHARINDEX ( '4', '7,4,8,5') --returns 3 SELECT CHARINDEX ( '8', '7,4,8,5') --returns 5 SELECT CHARINDEX ( '5', '7,4,8,5') --returns 7 [/sourcecode]

Now you see how easy is toget order range using this style. Finally, we can create our query using this technique and return our rows in the order we want.

[sourcecode language="sql"] select * from Person where PersonID in (4,5,7,8) order by CHARINDEX(CONVERT(varchar, Person.PersonID), '7,4,8,5') [/sourcecode]

Happy coding!



SQL MaxInt and MinInt functions

Is kind of frustrating when you are trying to write a complex query and there is that one function not provided by SQL Server out of the box to use it right away. This is the case with a function to compare 2 integers to get the Max or Min between them, similar to the Math.Max and Math.Min methods in .NET. You could create your own function and re-use it everywhere, but the first implementation that comes to your mind is a very inconvenient way to deal with this, since you cannot use it (easily) within an inline Sql query. Let's take a look at the easiest way to implement our function:

[sourcecode language="sql"] create function dbo.MaxInt(@int1 int, @int2 int) returns int as begin if @int1 > @int2 return @int1 return @int2 end [/sourcecode]

As I mentioned, there is no easy way to have this query as a subquery in a complex sql statement. And if you make it possible, the performance implications can be kinda bad. But the world doesn't end here! There is a convenient solution that will allow you to write an efficient function for it, or even better, have it inline right within your query. The trick is to double the desired value and then divide it by 2. So if you want to find the max value, find the value that is 2 times the max and then divide it by 2; if you want to find the min value, find the value that is 2 times the min and then divide it by 2. Let's take a look:

Max Function

[sourcecode language="sql"] create function dbo.MaxInt(@int1 int, @int2 int) returns int as begin return ((@int1 + @int2) + ABS(@int1 - @int2))/2 end [/sourcecode]

Min Function

[sourcecode language="sql"] create function dbo.MinInt(@int1 int, @int2 int) returns int as begin return ((@int1 + @int2) - ABS(@int1 - @int2))/2 end [/sourcecode]


And using this doubling notion with the absolute value tricks, we can elegantly write min and max comparisons right inside the Sql statement without the need of a function. Here is an example of an inline Sql statement:

[sourcecode language="sql"] select a, b, ((a + b) + ABS(a - b))/2 as maxValue from myTable [/sourcecode]

Sweet ahh?! Happy coding!



On Hiring: One in the bush... too much to ask?

Today almost any tech enthusiast can say "I know how to program in C#" or "I know how to create awesome websites using RoR". With the evolution and abstraction of programming languages, it is true the knowledge required to make a program writing code on your own has become increasingly easy. My aunt, a 58 year-old catholic woman with 5 children and 8 grand-children just made her own website using nothing else than Dreamweaver. The point I want to make is "with popularity also comes mediocrity". There are a lot of self-titled software engineers in the job market that cannot tell you what a pointer is, nor can explain the basis or recursion. Many of these people make it their goal to memorize and learn a specific IDE, framework or language and then they themselves software engineers. Hey, when I was a kid, I built a tree house with my friends and... IT NEVER CRACKED... I'm a genius! I'm going to apply for an architect position to build the next Trump Tower!

As I'm writing this post, I'm going thru the process at work of interviewing some candidates for 2 openings, one as a Junior Software Developer and another as a Software Engineer with substantial experience and hands on project management. I'm living a nightmare. This is the second time I've had to hunt for people to add to the team, and I'm surprised on how many applicants are out there applying for positions they really cannot fill. After almost 10 days reading resumes, making phone calls and talking to many applicants; I've only been able to handpick 1 out of 57 applicants to move on to the second part of the hiring process. The CEO of the company (my boss) says I'm too rigid with the requirements and too tough with the applicants... I don't know if the expectation is to lower my standards (hard for me) or keep hunting for the right person and sacrifice the lost time for the quality and productivity the jewel will bring when it appears. In the meantime I can keep looking through a pile of stupid resumes full of lies and incredible fictitious accomplishments. This is the process I'm going through for the hiring process. As I said, one position is for a Junior programmer and another one for an experienced engineer.

  • Filter 1: Job applications go first to another guy that filters out the obvious mismatches based on non-technical stuff, such as their VISA status, ability to speak English fluently and so on.
  • Filter 2: Then, this guy sends the resumes to me and I take out those that are really really obvious mismatches based on their previous experience and field of interest. Here is kinda crazy what you find; people that graduated in 1976 from computer science and for the last 20 years they've been a manager assistant at Walmart. I mean, seriously?
  • Phone Interview: At this point we are down about 50% of the initial applicants. Then I order their profiles by the "interesting" factor and start calling them in order. I go through the same script with each one of them, and try to cut them short when I see is not going to work. Here is my script for the phone interview.


  1. Chat about the company, what we do and what type of job the candidate is going to be doing.
  2. Chat about the candidate. Get him/her to relax an feel comfy talking to me.
  3. Question about most recent project he/she worked on. Specifics.
  4. Three questions about OOP.
  5. Three questions about programming languages (references, heap and object creation and disposal).
  6. Three questions about .NET Framework essentials.
  7. Are you satisfied? (the applicant)
  8. Questions and Answers.


  • In-Person Interview: If the person passes the phone interview with a positive outcome, then he/she is invited to the office to continue the screening. An appointment is set.
  • A Day at the Office: the candidate comes to the office. I make sure to ask him/her the same questions I thought they could've been answered better in the phone interview. I chat with them a little bit and introduce the candidate to the team members and people they'll be working with. 2 or 3 of the software engineer team members will actually do like a little personality screening in private with the candidate with the goal of helping me determine if they think it'll be a good addition to the team. They can either give me thumbs up or thumbs down and tell me why they think it may or may not be a good addition to the team. I value a lot the criteria of my team, ultimately they are going to be working together and nobody wants a week link or a introverted soul in the group that doesn't know how to play team sports.
  • The test: After the office showing and team interview and more questions, it comes the written test. IT IS INCREDIBLE HOW MANY PEOPLE WILL PASS THE PREVIOUS PHASES JUST TO FAIL HERE. The test is usually something very generic but that requires a minimum knowledge required for the kind of job we do (and that they are applying for). This time around the exercise is to create a remote application HTTP accessible with a function that, given an integer it returns the second consecutive prime greater than the integer. The second part of the exercise is to create a separate client application that uses such method and provides a minimal UI to use it. I give them 45 minutes to complete and another 10 minutes to explain to me what they did. So far none, not even 1 candidate have completed the such simplistic task in 45 minutes. DAMN IT! I've encountered myself explaining to recent grads and candidates with Masters what a PRIME number is!!! BOOOOOOOOOO!!! WTF is going on?!?
  • Negotiations and Hiring: I've only considered 1 person as a possible candidate so far to fill in the Junior position. Negotiations are straight and very much depends on what skills and drive the candidate shows during the interview process. If I'm sure you are the right person for the job, you'll leave the office knowing that and with a competitive offer in your hand. If you are kinda there, but never got to convince me about you, BUT made a strong point about your will to learn and future, I'll put you in the back-up bucket. The rest of the world will receive an email with a sorry and a good luck on their job search.

At this point there has to be something I'm doing wrong. I cannot believe there are no worthy software engineers out there looking for a job. Is it that the interview is too tough? Am I expecting too much from the marketplace?