Archive for the 'Uncategorized' Category

How to create a list that holds different object types using `void*` in C

Sunday, April 5th, 2015

I remember being in school back around 1998 and not knowing enough about C to do this. After coding in other languages, then going back to C++ and understanding at a lower level how references and pointers work, this was pretty easy to figure out.

In this exercise I store elements of different types in a forward linked list.
In order to know what to dereference as I iterate through the list’s elements, I’ve put a “.type” field, which has an int value representing the type of the object stored.

The “.value” is simply a void*, which lets me store a pointer of any kind, and it works pretty well.

Here’s the code for your enjoyment, I hope this is useful to C apprentices.

The example shows how you can store native types like int, or more complex char* or even a struct person* (which is the more useful probably to your purposes)

It’s a good exercise to see the uses of the “address of” operator “&”, which is used to initialize pointers (the ‘&’ can also be used differently to create references, which I call in my mind as ‘aliases’, but this is not shown in this example)

I also play with a not so popular syntax to access a pointer’s sub-fields:

(*myPointer).structField == myPointer->structField

to teach you that the -> is a short hand for dereferencing a pointer and accessing one of its fields.

// An exercise to play with a struct that stores anything using a void* field.                                                                                                              

#include <stdio.h>

#define TRUE 1

int TYPE_INT = 0;
int TYPE_STRING = 1;
int TYPE_PERSON = 3;

struct node {
  struct node* next;
  int type;
  void* value;

struct person {
  char* name;
  int age;

int main(int args, char **argv) {

  struct person aPerson; = "Angel";
  aPerson.age = 35;

  // Define a linked list of objects.                                                                                                                                                       
  // We use that .type field to know what we're dealing                                                                                                                                     
  // with on every iteration. On .value we store our values.                                                                                                                                
  struct node nodes[] = {
    { .next = &nodes[1], .type = TYPE_INT    , .value=1                   },
    { .next = &nodes[2], .type = TYPE_STRING , .value="anyfing, anyfing!" },
    { .next = &nodes[3], .type = TYPE_PERSON , .value=&aPerson            },
    { .next = NULL     , .type = TYPE_BOOLEAN, .value=TRUE                }

  // We iterate through the list                                                                                                                                                            
  for ( struct node *currentNode = &nodes[0]; currentNode;  currentNode = currentNode->next) {
    int currentType = (*currentNode).type;
    if (currentType == TYPE_INT) {
      printf("%s: %dn", "- INTEGER", (*currentNode).value); // just playing with syntax, same as currentNode->value                                                                        
    } else if (currentType == TYPE_STRING) {
      printf("%s: %sn", "- STRING", currentNode->value);
    } else if (currentType == TYPE_BOOLEAN) {
      printf("%s: %dn", "- BOOLEAN (true:1, false:0)", currentNode->value);
    } else if (currentType == TYPE_PERSON) {
        // since we're using void*, we end up with a pointer to struct person, which we *dereference                                                                                        
        // into a struct in the stack.                                                                                                                                                      
        struct person currentPerson = *(struct person*) currentNode->value;
        printf("%s: %s (%d)n","- TYPE_PERSON",, currentPerson.age);

    return 0;

The output is this:

- STRING: anyfing, anyfing!
- TYPE_PERSON: Angel (35)
- BOOLEAN (true:1, false:0): 1

How to make a “foreach” function in JavaScript

Saturday, April 4th, 2015

I thought this would be a simple exercise in case of having to interview someone for a JavaScript position.

“How would you make your own ‘foreach’ in JavaScript”

I came up with the following solution:

// collection: A list of objects.
// onElementIterationCallback: The function to be called on every element iterated
//    taking the following parameters:    foo(collection : [T], currentIndex : int)
function foreach(collection, onElementIterationCallback) {
    for (var i in collection) {
        if (collection.hasOwnProperty(i)) {
            onElementIterationCallback(collection[i], i);

This is how you’d use it:

var sumOfAges = 0;
var people = [ {name:"Angel", age:35},
               {name:"Paulina", age:33},
               {name:"Nicole", age:16}]

foreach(people, function (person, currentOffset) {
   console.log("("+ currentOffset + ") iterating on " + 
      + ", age: " + person.age);
   sumOfAges += person.age; 


The expected output would be:

(0) iterating on Angel, age: 35
(1) iterating on Paulina, age: 33
(2) iterating on Nicole, age: 16

Hope you enjoyed, just a simple exercise of lists, creativity and callbacks.

How to edit the same word/token in multiple places using Sublime Text

Friday, June 27th, 2014

1. Double click on the word/variable/token
2. Press Ctrl+Cmd+G
3. start editing, it will edit all the ocurrences of the same token within the same file.
4. When you are done, you can click anywhere, or press Ctrl+Cmd+G again to finish the simultaneous edits.

First Impressions Lenovo Yoga Pro and Windows 8.1 with a 2 in 1 device.

Saturday, February 1st, 2014

After now almost 2 weeks of heavy duty use of this machine, I must say Windows 8.1 is not fully baked when it comes to its tiled/touch/app store experience, however it’s not the nightmare I expected.

The FrostWire 5.7.0. currently circulating on the Internet was built on this machine, the experience was quite pleasant as a workstation, and then I carried it around for the North American Bittorrent conference and during that time it was a very convenient tablet while I was doing all the social networking during the event.

WordPress: Cannot create directory error, got everything chmoded to 777?

Monday, January 27th, 2014

So you went as far as chmod’ing your entire folder structure to 777 (very unsafe), you’ve hacked wp/wp-admin/includes/file.php

return new WP_Error( 'mkdir_failed_ziparchive', __( get_current_user() . ' Could not create directory. ('.$_dir.')' )...

to print out exactly what directory it cannot create and what user is trying to create the folder, everything is correct, yet it won’t create the fucking folder?

the issue might be your vsftpd configuration!

Go to /etc/vsftpd.con and make sure that you have this setting uncommented:


restart your vsftpd (sudo service vsftpd restart) and try upgrading again, you’ll want to hit that ‘Donate Bitcoin’ button if I saved your ass today.


How to bulk schedule thousands of tweets in very little time

Wednesday, October 23rd, 2013

Sign up for the beta at

Metrics Gathering notes from Workshop by Aaron Ginn

Thursday, October 10th, 2013

Aaron Ginn from
October 10th, 2013 @ Miami Science Museum / Refresh Miami

Most important metrics?
Number of installations.

Types of metrics:
– Quantitatie vs -Qualitative.

– On Wizard, let them know how to be in touch for Tech Support
via @frostwire and Official.
Task for Marcelina to design that screen on the wizard.

The funnel (Pirate Metric)
Acquisition > Activations > Retention > Referral > Revenue.

User Testing (In Progress)
Study Groups
User Interviews

Stages for companies:

Early Stage involves discovery, validation. Then get Seeded out of pocket and angels.
Qualitative metrics help here.

Later Stage creation and building – Series A, profitability.
Quantitative metrics.

During creation, you want to start doing A/B to grow and see what works.

User’s worth (LTV)
Growth rate

Qualities of a Good Metric
Measurements that are aggressively attacking your product.

Actionable – short feedback loop.
Product Centric – attack core assumptions of your product
Ratio – Compare against competitors performance, industry numbers.
Explainable – simpler the better
(Checkout “Flurry” reports

Key Metrics per business

Marketplace: fulfillment rate, WOW (week over week) growth on both sides, % repeat purchase

Social Product: DAU/MAU, WOW daily registration, % ad impressions

B2B – sales funnel metrics, LTV

B2C – sales funnel metrics, LTV, WOW growth

LTV = churn * avg revenue per customer

Virality = measure the share cycle time is important. The faster, the deeper impact at sub-levels. Time between invites and activations.
Look for vitality equations.

Create your own AARRR

Acquisition – Number of new downloads, newsletter signups, twitter followers, Facebook page likes, community forum signups, Number of displays of our thank you page
Activation – Number of first uses. Displays of our promotions.
Retention – Number of sessions, Number of core actions, Newsletter unsubscribes, Facebook unlikes
Referral – Measure social activity, buzz, cult (pictures, fan art)
Revenue – Daily reports from all revenue channels (some hourly)

Qualitative Testing Schedule

One user a day. Watch them.
Two user sessions a month.
Three usability studies a month.

Important Factors in Quantitative Testing
is it Statistically Significant?
sample size.
sensitivity of the test.
duration of the test.
velocity. How many tests can you run in a period, pretty important. You need to test and get results as fast as possible, to learn more and more.

Good habits
Test the hell out of MVPs.
Kill tech that slows you down.
Validate Instrumentation First. (make sure your test is running well)
The Goal is testing velocity.
Think about your next developer/employee.

Tools we use
Qualitative Testing Tools:
FT User Researcher
MouseOver Videos
User Studies

Quantitative Testing Tools
AB testing
Daily metrics emails
Product dashboards
Team metrics

Rapid A/B Testing Workflow

Test Iteration Implementations -> Rapid implementations.
Full Implementations -> Winner only (clean losers)
Code Fragmentation -> Clean unused test code.

Branch Based Workflow (git based)

Test Iteration Implementation -> Rapid
Full Impl -> Winner only

What will we do differently after this?
Added some new metrics I was missing thanks to this in relationship to acquisition and activations.
Will try new tools like
Will look at what tech might be slowing us down.
Will not build more visualization tools of test data.

How can we all own a robotic workforce?

Thursday, September 26th, 2013

As people become useless, how can capitalism survive?

As technology advances exponentially the fields of robotics and artificial intelligence will start taking over our jobs. More and more people already can’t find work, yet the nation is still very productive.
Yes, a lot in part due to globalization and cheaper foreign labor, but those cheap labor countries will only remain competitive against fully automated factories for so long.

Self driving vehicles will eventually be here, it’s just a matter of time before we think of driving ourselves as the most barbaric thing we ever did, our kids won’t believe we actually drove ourselves.

Self driving vehicles will take the jobs of millions of people, think bus drivers, truck drivers, taxi drivers, and these robotic vehicles will do their job infinitely better, not getting tired and for way less money.

Think Fedex, UPS, USPS announcing their first robotic delivery fleets, an then in a matter of years they start reducing their costs exponentially by letting go of +90% of their human workforce, shipping worldwide becomes faster and cheaper than ever.

If things keep going the way they are as they happen on the internet, only a handful of people will own powerful computers, shrinking economies due to technological efficiency and more wealth will be concentrated in a few.

If the same thing happens to robotized labor, we’ll find ourselves soon in civil war with so many “useless” people unemployed.

But I think there’s another end to it, while keeping capitalism.

If we are all smart about it, as we see robotization happening, we must make the decision to change a few things, without turning completely into a socialist country which in the case of latin america’s implementation of socialism, the result is usually an all too powerful government and oppressed citizens.

I believe that instead of handouts (like having a government that provides everything to people who are just useless thanks to robots being so useful) we should look at this as an opportunity to make everyone in society a stake holder of the robotic workforce.

If things would happen the right way, robots would be doing our job and we’d be getting paid for it while we play outside.

The only way this could happen would be to distribute the ownership of all the robots to as many citizens as possible. The implementation of such distributed ownership is the part that I still don’t have quite clear and I’d love for you to give me some ideas on how this could come true.

Perhaps it could all start with a law to avoid the ultimate inequality gap, as things are today the rich will be the only ones to own the majority of robots, ending up with a robotic workforce that produces goods that nobody will be able to afford since they’re all unemployed, then people would start talking about a communist revolution and we don’t want that, we need capitalism evolved. A nation made from a lot of rich people out of robotic production and a renassaince of American product exports.

I think if the people now living off of unemployment checks would own a portion of the robotic workforce, they would instead get larger and larger divident checks that come off their robot’s productivity (I see this as some sort of Robotic ETF that pays monthly dividends).

This ownership could initially come from a portion of their tax contributions/returns (through some initial law that would make as many americans as possible robotic-workforce-entrepreneurs by force), maybe there could be incentives toward robotic equity, such as people who continue to get a high level education getting tax credits or rebates on the price of the robotic labor ETF.

The first country to figure this out will be king, itwould have a society mainly composed of a highly educated and almost rich middle class, people that don’t have to spend 8 hours a day doing work that’s done 1000 times better by their robotic counterparts.

A society that would have a surplus of money they could use to travel the world, study, research, or invest in whatever they please, being highly educated an peaceful we’d find times to take mankind to far more interesting directions like clean and free energy research, space exploration and mining, medical advances, the pursuit of much longer life spans, and solving real problems affecting developing nations.

But the question remains, how do you motivate the currently rich elite to not eat/cook the whole robotic labor pie, or to somehow share it so that we all get to own a piece of it and live worry free, happily unemployed because robots are the ones that are supposed to work for us?

How to make a Mean Green Juice. #Juicing #Paleo

Wednesday, August 28th, 2013

Green juices are a great complement to the Paleo Diet. Some of us are not that fond of vegetables and while still training our palate to enjoy vegetables, these green juices are loaded with lots of micronutrients that will nourish, clean, and protect your cells. With a lot of ice, they’re not that bad in taste, and the health benefits are absolutely worth it, not to mention how much fun it is to use a juicer.

– 4 celery sticks
– 1 cucumber
– 2 apples
– 1/2 lemon
– 1 tbsp ginger
– 4 leafs of Kale
– Brocolli (optional)

What will you do with an internet and devices millions of times more powerful?

Friday, July 12th, 2013

I keep thinking about the inevitable exponential growth of technology and how it relates to CPU Processing power, Storage capabilities and Data transmission speeds, and then I ask myself what would I do with technology 1 billion times more powerful than the one we have.

If you haven’t noticed, things are getting really powerful, really tiny, and really fast already.

And companies like Google are starting to show hints of what should be done with all these.

Look at the new Google Maps, it’s pretty amazing, and it’s only going to get better.

When you interview at Google there’s one question that keeps coming to you almost from all the people that drill you “How would you make the internet faster?”

It seems Google’s answer is to take over the internet at every layer, they have indexed it like nobody else, they’ve created a browser that’s now taken the majority of the market share and made it really fast, they’ve built application layer protocols faster than HTTP (SPDY), they’ve also seen the exponential adoption of mobile devices and created an operating system for it, and devices for it, and more recently they’re even providing internet access at Gigabit speeds one small city at the time (which is all an experiment for what’s to come)

Then you see them experimenting with very primitive versions of wearable computers (Glass) and if you start putting the pieces together, for example, they were crazy enough to have cars driving around the world to have “Street View” in Google maps… how on earth would you be able to go all the way and digitize reality itself? You put computers on people’s heads and record everything into digital information.

I can see a future where Google will be able to ask you to record whatever you see around you, inside or outside a building, they’ll have your position, your orientation, and best of all, since there will be so many of us willing to collaborate in exchange of some stupid incentive (or perhaps none), they will be able to record reality from almost any angle possible to have a full representation of reality, perhaps even in real time, I think these are the kinds of things that are possible when you have incredibly fast CPUs, incredibly huge storage, and incredibly fast transmission speeds when you have incredibly ubiquitous internet access (remember that Balloon project?)

And that’s just what this little mortal has thought of in relationship to their Google Maps product.

I think Google Glass and an application of this sort will bring forth interesting legal challenges, like, what if you don’t want the inside of your home or office to be in google? how do you prevent anyone from capturing everything and making it public?

Other scary applications that I see possible are real-time face recognition coming from a Google Glass facebook app, then the name “facebook” will really make sense. And best of all, a lot of people (after major debate and laws have been passed with respect of not being scannable by strangers) will actually want to be recognized by strangers, maybe there will be social benefits to complete unanimity, it will all be really interesting.

  • Categories

  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • October 2009
  • September 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004