dseehausen-blog
dseehausen-blog
Wot ==? Wat
3 posts
Don't wanna be here? Send us removal request.
dseehausen-blog · 8 years ago
Text
You’re Trying to Seduce Me, Cython, Aren’t You?
Tumblr media
What is Cython?
ELI5: Cython makes Python execution blistering fast by unpacking Python code into C code.
From Cython’s website: Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself.
What do we gain? Speed, memory, and vector traversing optimization (i.e. types/structures use require and use less space) and more! In essence, we gain all of the benefits of executing a program in C over Python.
What do we lose? While the learning curve when starting out is low-cost, it does climb incrementally with increasing complexity. Additionally, developing with Cython does push the programmer to the more classic Write-Compile-Debug workflow, sacrificing some of the development luxuries that higher level languages afford.
Give me an example where you time the solutions to Project Euler #14, comparing vanilla Python to Cython
Many of my classmates were recently solving Project Euler #14 for mock technical interviews. It has been well documented (specifically with Cython in this blog post http://code.jasonbhill.com/c/project-euler-problem-14/) so we will use that. If you would like more information on Euler Problem 14 (as well as higher level language code solutions), please see the blog post following this one. The following caching solutions use arrays (initialization times included in the benchmark) instead of dictionaries. The indexs act as the keys.
Python Brute Force Solution 21.67 23.09 23.12 (22.63, seconds avg.)
Cython Brute Force 0.53 0.53 0.51 (0.53 seconds avg.)
Python3 Caching Solution 2.24 seconds 2.17 seconds 2.19 seconds (2.20 seconds avg.)
Cython Caching Solution  0.024 seconds 0.020 seconds 0.026 seconds (0.023 seconds avg.)
WOT
As you can see, we have some pretty perverse speed gains. The majority of our gains are coming from use of static types and, in the cached Cython solution, a malloc'd array that won't resize behind the scenes.
0 notes
dseehausen-blog · 8 years ago
Text
A Briefer History of Linux
Linux, (and its various distributions) have been gaining steady popularity for the average computer user over the years. While they already dominate as the choice server operating system outside of the server specific market and the top 500 supercomputers (of which 99.6% use Linux!) as of 2016 under 2.5% of desktop computers were running linux distributions. In considering this low number, it worth mentioning that Linux's greatest consumer market success is much larger than those figures belie. Any takers as to what worlwide consumer electronic uses the Linux kernel? (see bottom)
There are many reasons to consider switching to using a Linux distribution as a consumer, but that is outside of this scope. Maybe someone will .call this blog post with a follow up later and bring more information on the matter. For now, if you are interested in considering using a Linux distribution for personal use (and never have before), consider Ubuntu or Fedora.
Now, as Linux distributions continue to evolve and become more non-server/average consumer friendly, I wanted to share a brief history of Linux:
Why the Penguin?! Because the ultra-gamer who developed Linux, Linus Torvalds, is out of his mind:
"Reportedly, Linus' infatuation with penguins came about after being bitten by one on a trip to Australia in 1993. He jokes that after the bite, he was infected with 'penguinitis' that "makes you stay awake at nights just thinking about penguins and feeling great love towards them."
Who is responsible for Linux? Was it one person? Why was it all men? While the answer to this is largely dependent on who you ask, allow me to give you my naive answer:
Bell Labs, Ken Thompson, Dennis Ritchie These rockstar programmers developed the Unix operating system while at Bell Labs which, if you haven't heard of it, was a compound of insane and talented computer scientists. An incredible amount of developments in the field of computing/programming originated from Bell Labs (including eight Nobel Prizes awarded for work completed there): Bell Labs, once owned by AT&T, was forced to be split off (one of many ways in which AT&T was sliced up) once people got their heads on straight and realized we had an unstoppable tech/telecom monster that had an absolute monopoly on the market.
As a result, the Unix operating system was no longer 'open-source', and it was sucked into the grip of 'proprietary software'.
Enter programming Jesus:
Richard Stallman Richard Stallman is as true as true gamers get. He is idolized, often seriously, sometimes satyrically, in many circles (both for good reason). As Unix slipped from the realm of open source, Stallman was sent by God to die for AT&T's sin of monopoly (and ultimate re-claiming the Unix license, sharing it only with the evil empire aka IBM at the time). Stallman set out, like Henry David Thoreau writing Walden, and created GNU (which stands for 'GNU's not Unix!') GNU is a collection of free software: ultimately, everything an operating system would need to get off the ground. Unfortunately, the GNU Kernel (the core of operating system which exhibits complete control over all things) was subpar and remains under perpetual development. From GNU Hurd (their kernel) website: "The GNU Hurd is under active development. Because of that, there is no stable version."
The software is under active development (since 1990!), therefore there is no stable version...wot?
Richard Jesus Stallman got us far (RIP). While absurdly irradiated and on his death bed, after insisting to see the 'Elephant's Foot' "...in person, face to face...", in 1989, Linus Torvalds visited to him and received his dying wishes: "Linus", he beckoned, "...create the greatest kernel known to true gamers. Put those God damn HURD developing bastards in their PLACE LINUS!".
Linus Torvalds (Honorable mention Andrew S. Tanenbaum) Thus emerged Linus, greater than the sum of his parts: And both his inspiration as well as greatest Rival - Tanenbaum: Their rivalry, over Monolithic Kernels vs. Microkernels, is Desperate Housewives level drama and worth looking into.
I am going to not cheat with Wikipedia and go off of my memory on this one. It should be almost 50% accurate:
Linus, being Finnish-American, was once in the Finnish army and, in being recognized for his true gamer logic/logistics/number crunching abilities, was an artillery officer. While out blowing evergreens up in the Finnish tundra, he read Tanenbaum's book "Operating Systems: Design and Implementation", which used a stripped down, educational version, of Unix called Minix (designed by Tanenbaum). This was part of the inspiration to develop Linux, which Linus did after he went back to University/Stallman gave him his mission on his deathbed.
Ultimately, the first implementations of Linux were written on Minix systems. Linux evolved, and became the De-Facto kernel for the GNU software bundle. Linux was the keystone to GNU, which enabled both of them to rocket forward in use and populatiry. Many non-true gamers out there will tell you "Linux should be described outside of the scope of GNU!", while others will say, "How dare you even refer to Linux without prepending GNU to the name!". Without debasing ourselves and joining either camp, its important to recognize the issue is centered around how closely the two are used and married. When one discusses the use of a 'Linux' system/distribution, remember that (unless some non-true gamer is droning on about how its not GNU behind the kernel), the (linux) kernel is delegating and managing the underlying GNU operating system software.
In conclusion, many were responsible for why GNU+Linux exists, but developers to know were Linus Torvalds and Richard Stallman (without the other, neither could have become as popular as they are now).
While Linus is an absolute rockstar programmer true gamer, he is also a known jerk, stating that he is: "...[a] really unpleasant person...I’d like to be a nice person and curse less and encourage people to grow rather than telling them they are idiots. I’m sorry – I tried, it’s just not in me.", and, “I like arguing...I'm just not a huge believer in politeness and sensitivity being preferable over bluntly letting people know your feelings.”
*Richard Stallman is still alive and, to my knowledge, never visited the Elephant's Foot *Android uses the Linux Kernel!
0 notes
dseehausen-blog · 8 years ago
Text
A Fun Atom Package
I have to thank one of my peer's misfortune for this small programming project: he came into school one day with a computer that just wouldn't turn on no matter how hard he hit it, (later, we realized, it was because he was hitting it that it broke in the first place). Following is actual footage of him handling his computer:
As a consequence, Nick had to bash on the mysterious left over laptop that had been designated a 'loaner' ever since its owner up and left under (what could only be described as) duress.
This prior owner, Accepted into the Flatiron School for his unreal typing speed and micro-management of different terminal windows, (which were strong enough as to void the would be disqualifying fact that he did not speak a lick of english), he up and left in a tizzy, crying out frustrations. Luckily, his lamentations did not fall on deaf ears: one of the co-founders, Avi, would later realize the language to be Korean, and claim that it loosely translated to: "New patch imba four zerg. Supply depot wall no longer works, they say?" To an untrained ear, this may sound like wood level scrub balancing complaints, but not to Avi. He recognized immediately that this was the one and only Lee "Flash" Young Ho. Perhaps the most winning Starcraft player of all time. The bleed blue terran player who, so absolute in his dominance, earned the nickname 'God'.
What providence, in the end, that this loaner computer fell into my fellow classmates Nick's hands. With the backstory made clear, we knew why the 'S' key on the computer had a gentle concave scoop in it. (Flash must have been practicing on the laptop in his spare time, spaming that 'S' key to build more SCV's and Supply Depots...)
Nick, and ultimately I, ended up benefiting from a mysterious Atom package left behind on Flash's computer. It seemed that, given years of rote RTS micro/macro training, Flash required nonstop digital (fingers, not Matrix) stimulation to keep his heart's bpm in a reasonable range. As a result, he hired the most notorious and controversial former Korean pro-sports doctor, Joel Besada, to develop the ultimate training solution. Senor Besada had since fled to Argentina after one too many inquiries about his athletes' illegal use of performance enhancing drugs, (an Adderal/HGH hybrid that he used to mix in his porcelain bathtub).
While relaxing with his friend, Michele Ferrari, on the beaches of South America, Flash commissioned Senor Besada to create ACTIVATE-POWER-MODE®. Unfortunately, Flash had only days to use it before he had to return to Korea to play the most important team match of all time: A winner takes all, North vs. South Korea, Starcraft Broodwar match (A blog post unto its own).
Now, the computer and Atom package had fallen into Nick's hands. As he was smashing away on the keys, I found myself transfixed by a simple yet clean interactive effect. With every key input, the screen would shake, a small amount of particles would emit at the cursor, and a combo counter would modestly rise in the corner of the screen. "My God!..", I thought, "...this could only be the work of Senor Besada!". What came over me was an overwhelming compulsion to get involved. As I stared at the screen and, with trembling hands, probed the source code, I felt a presence loom behind me.
"Is that you Shreck!?...again?", I whispered meekly.
"No, it is me, Steven."
('Thank God') I muttered to myself. He must have smelled my piqued interest in contributing to open source and, like a shark smelling blood in the water, found his way to me. I was transfixed by Senor Besada's coffeescript, which had so imposed absolute order upon javascripts chaotic aesthetic. With my eyes on the screen, and with Steven's eyes on the back of my skull, he gently massaged my shoulders and whispered encouragements:
"Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It’s not a story the Jedi would tell you. It’s a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life… He had such a knowledge of the dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful… the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself."
I knew then what I must do. Senor Basada's work was unfinished, and it was my job to pick up where he left of. I set out to do two things:
1.) Add to Basada's work where I knew I could, helping it grow without taking it too far from its modest roots.
2.) Go way over the top with his package by adding unecessary and distracting additions that force you to work harder through both encouragement as well as derision
While it never feels as though a project is finished, I know both of these goals have been met to a satisfactory degree. I am excited to make a pull request to Senor Besada, before which only small amount of refactoring remains. As far as the over the top changes go, I will be releasing a stand-alone atom package called "Activate-Bedlam-Mode", (wholly based off of the original "Activate-Power-Mode").
I would certainly like to continue making a few changes to both the vanilla additions as well as the the other addition, and hope to be completely finished by the end of the weekend.
0 notes