December 8, 2018

Installing a python client for MySQL

While trying to pip install mysqlclient, I had been coming across this issue for the past two days:

    In file included from _mysql.c:29:
    /usr/local/mysql/include/mysql.h:35:10: fatal error: 'sys/types.h' file not found
    #include <sys/types.h>
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

If I were a more meticulous developer, I would have focused on the exact issue being barfed by the terminal, instead of being easily confused and distracted by the many Stack Overflow and Github suggestions.

Some of the suggestions I tried, and shot myself in the foot:
  • Some SO issues had suggested to brew install mysql, which, of course, began to install the latest version of mysql (8.0), when I already had a previous version installed.
  • While installing 8.0 version, I didn't know how to do an "in place" upgradation from 5.7 to 8.0, or a "logical upgradation" from 5.7 to 8.0. Either of which would have worked, but since 8.0 was installed assuming there were no previous versions of mysql installed, I ended up in a state where neither the 5.7 server nor the 8.0 server would start up.
  • And since I had not taken a mysqldump backup of all my tables before starting this exercise, I had no other go than to remove both mysql versions, along with all the data directories (and thus losing my current tables on localhost), and start from scratch again.
  • But hey! installing from scratch doesn't fix the above issue either!
  • Installing XCode command line tools via xcode-select --install doesn't seem to fix this either!
So what's the issue here? Going through more articles and suggestions, came across this little gem by GitHub user giblfiz, which seems to suggest that the latest versions of XCode doesn't install the system headers into /usr/local/include, where every other build system worth it's salt in portability would look for by default, but instead installs it into some weird macOS specific directory.

Aha. So add this weird directory as well to look for, while searching for system headers:

export set CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.14"

I know how the -I flag works for gcc, but I think the -isysroot and -mmacosx-version-min maybe clang specific flags. Not sure, and not bothered at this point, since hey, pip install mysqlclient worked beautifully after this.

Just throwing it out there into the Ether, so that other confused souls may find it helpful, and since I do not yet have sufficient rep to comment on SO, and neither do I want to sidetrack other bug discussions on GH.

January 21, 2013

Do NOT touch crypto code.

No, I'm not coding any crypto algorithms. Even following discussions about coding them, like gnutls, nettle, and openssl mailing lists, is hard. But just to demonstrate the complexity of coding crypto algorithms, think of side-channel attacks. I quote here from a mailing list on nettle:


Let me first explain what I mean when I talk about a "side-channel
silent" function. That means that if we call the function with operands
which are of the same size, but otherwise different, the function should
execute exactly the same sequence of instructions in both cases, and
access memory in exactly the same pattern.

If one then assumes that the underlying machine instructions have data
independent timing (true for most current cpus), we leak no side
information from timing or cache behaviour. We may still leak
information through power analysis, if, e.g., executing a multiplication
instructions consumes different amount of energy depending on the input
bit patterns.

-- Niels Möller

What does that mean? It means "Do NOT touch crypto code". Unless you understand the implications. And there are too many implications in too many aspects, that laymen like you and me do not understand. I mean, can you even imagine that your code could be susceptible to power analysis? I mean, yes, in algorithms you've been taught that a multiplication is "costlier" than addition, and if you've studied transistors and digital logic and algorithm analysis, you might begin to understand why, because more transistors are needed for multiplication (I'm guessing here), but to think that that cost involves differences in power usage! Well of course, but then to think that that difference in power usage could be used to analyse the number of multiplications used by your code, and hence begin to backtrack the input of your functions! Yeowza. So hey, lesson of the day: "Do NOT touch crypto code".

January 16, 2013

OpenSSL, cURL, and multithreading.

OpenSSL is one of the most widely used crypto library. Supports many digest and cipher algorithms, many types of protocols, very light and extremely optimized for many platforms (take a look at the arm assembly or x86_64 assembly codes for different algorithms.. gives you a sense of the awesome work put into it by experienced people through the years), and yet, out of the box, it is not thread-safe.

Couple of points to note here:
- This does not mean that OpenSSL cannot be used in a thread-safe way. It can be, but a little work has to be put in.
- Related links: http://horstr.blogspot.in/2008/04/on-libcurl-openssl-and-thread-safety.html,
http://curl.haxx.se/libcurl/c/threaded-ssl.html, http://stackoverflow.com/questions/3281373/segmentation-fault-in-libcurl-multithreaded.
- cURL is a URL handler, like wget, and it fetches the contents of urls. For HTTPS connections, you can make curl use either OpenSSL, or GnuTLS, or other supported implementations of SSL. OpenSSL is default.
- When using curl in multi mode, you can create several easy handlers (like one for each url), and attach them  to a single multihandle, so as to give commands to the multi handle which it internally performs on each of the urls. Since OpenSSL is not threadsafe by default, this multi handle usage of curl can cause rare random crashes.
- To avoid all these, OpenSSL provides callback mechanism to set your own locking functions (like simple pthread mutexes, or your own mutexes/locks if you prefer). This will enable multiple parallel initializations and cleanups without causing a hitch.

Now the question arises, who sets these callback functions? Curl certainly doesn't set it, and shouldn't, in my opinion as it should remain light, portable, and shouldn't define its own constraints. The final app can always set its own callbacks. Imagine, then, if multiple apps are running as threads in a single process... like maybe in a browser/platform or something... If each of the apps set their own callbacks, there is the possibility that these locks are not mutually interoperable. So shouldn't the browser/platform set its own callbacks? Should they or shouldn't they be overrideable by the apps' callbacks? ugh. I've never liked mutexes and semaphores. too messy :(

June 1, 2012

Post-post

Like the new look? No? Tough luck. I do. And here're the reasons why:

- It's a mosaic! Who doesn't love a tiling pattern?
- It's monochrome and bleak looking. Suits my emo mood.
- Fragments of broken thoughts, barfed all over the space. My thoughts, exactly.
- My fuggin blog, my fuggin wish!

February 27, 2012

Just realized..



Octennial, Novennial, Decennial - 8th, 9th and 10th year adjectives.
Octal, Nonal, Decimal - base 8, 9 and 10 number systems.
Octagon, Nonagon, Decagon - 8, 9 and 10 sided polygons.


October, November, December - 10th, 11th and 12th months.
AARRGGGHHHH!!!!!!

Frikkin Ceasar and his calendar. His salads are nice, though.

Also, following after decade, decagon, and decennial, I propose that December should be pronounced Dick-ember.


(Also just realized: the song would then go like "This is my dick-ember ...")

February 1, 2012

"Delhi taught me confidence!"

.. is such a paradoxical statement. For once one comes to live in Delhi, one realizes that there is no such a thing as "teaching" confidence. On a regular morning at the breakfast table one might even startlingly realize, that one either has confidence, or one doesn't. One might even come to find that said confidence somewhere around the corner, and simply pick it up, but confidence - one learns - can just not be taught. No predefined rules can be found, nor axioms be defined, which uniformly decide the levels of confidence of a person.

In other news, I would like to present to you a very peculiar idea, which seems to me to be on par with the only ever innovations in the fabric industry:
- the zipper, and
- the buttonhole.
Now kiss (In other words, why not mix the two?)! I present to you, the Zipton (c). Imagine, if you can*, two ends of cloth so adjacent to each other as to facilitate the usage of either the zipper or the button flap, or both!

ʘ_ʘ

The mind boggles!


*If you can indeed imagine such an arrangement, please do approach me. I have a business proposition for you.

December 19, 2011

And it Happened...

So. I think I remember the night now. The night I cried for the fate of the Telugu Language, the night I came to know about the concept of dubbing, and the night that forever changed my perspective of Telugu movies. I'm willing to bet the movie was one of the classics of those eras, either Gharshana or Maro Charitra or some such like, and I distinctlyremember this, crying to my little self at that time, "but I am only 5 years old!'' And here's why.

We were returning from seeing the movie at the town theatre, and were going back to our village. In a tonga, mind you, because autorickshaws hadn't yet hit the scene by then. I AM that old. It was me, my mother, my aunt her sister, and probably my brother and two or all three of my cousins. And the discussion had turned to how well the dubbing was done, or instead how well the other movie had been dubbed! and so on. Intrigued that they were talking about the same movie that I had just seen, and not understanding what exactly, I asked innocently what dubbing was. And I was explained at that age, how movies were dubbed, remade, and essentially copy pasted onto another Language. My simple mind couldn't have understood then, but what I suspect I found aghast, at even that tender age, was the idea that Languages and Cultures weren't one-to-one in the aspect (relation) of influence they have on each other. I couldn't comprehend. Why would we need to steal ideas from other cultures or languages? Couldn't we make our own Telugu movies so well? What could we be lacking in, that would lead us to consider other languages greater than our own? I was outraged. I wept. I wept for Telugu, the Language and the Culture both, the latter as especially manifested in movies.

I wept at the shredding of my innocence, and cried out mentally to the powers that be, ``but I'm only 5!'' Why would you do such a thing to me, universe? I wept so hard that I was relegated to sit beside the driver, as I was making too much of a racket inside the cab. Which is why that thought stuck to me, and even at 5 yrs, I was well made aware of my ingenue in matters concerning others than bats and balls. Which could probably also have contributed to my aversion towards all things concerning physical sports, but that is another story and I digress.

Putting that in perspective, I hope one can well understand why I have had a healthy distrust in both Telugu and Telugu movies until the age of 18, when I left home for the first time. Things have changed now, and I am a strong believer again in Telugu (both movies and the language), but that transformation has not come about overnight, nor easily. I have only come to understand later, the idea that a language's love is like a mother's love, nourishing and nurturing. Ironically after leaving home and motherland (AP). Or maybe not as ironic as all that, seeing as we all miss our moms only after leaving our homes.

And I have realized all this only now, when I am 27 years old, and tripping through old memories. Trying to make some sense of myself and my apparent contradictions. Yes, I do appreciate even dubbed movies now, only because I realize now that Languages and Cultures can never remain one-to-one, Geography permitting. Human indeed is a social animal, and the dubbing of movies from various mother tongues to hindi or vice versa*, is but as symbolic in emotion as a friendly neighbour saying "Good Day!". To quote Donne clichedly,

"No man is an island, entire of itself; every man is a piece of the Continent, a part of the main. If a clod be washed away by the Sea, Europe is the less, as well as if a Promontory were, as well as a manor of thy friends or of thine own were; any mans death diminishes me, because I am involved in Mankind. And therefore never send to know for whom the bell tolls; it tolls for thee.''


Geography willing, no man or language or culture can remain an island, entire of itself. (Examples of untouched unexplored virgin native cultures come to mind, because they have remained resident in unexplored and remote islands). And so I come to understand that yet another facet of myself, that I had heretofore considered contradictory, was not really one. As I have a love/hate relationship with the language, so do I with the movies. The case remains though, of my love for English (both, language and movies), and what kind of a relationship I have with Hindi.





*Yes, I do not still consider Hindi a proper mother tongue. Hindi tongue seems to me to be but an amalgamation of so many different bols and urdu. Representative as may be of the people, as much a republic State is of all the states that reside in it.
**Some parts above are fictitious. :D