Tag: code
I am gonna be forking all night; today
by Idd Salim on Feb.19, 2011, under Coding, Personal
Yeah. Pervert, I know whatchu thinking. Shame on you. This mosprolli sounds like one of those ‘Mrembo shikilia ukuta nikuonyeshe‘ escapades. Call me a motherforker if you like. But tonight, I am going balls-deep into process forking.
I just encountered a very sweet problem today. And I want to solve it in PHP. Yes, I know. Java, C++, Python and .NET can do this in their sleep and with their pants off, but, PHP it is. PHP with JIT support. Compiled PHP scripts.
Not the slow kawaida dot PHP files running on top of Apache in plain-code.
So, what’s the problem?
I faced this system doing a script for YU. DB design issues etc aside, we needed to have a script execute a certain set of functions and commands, then release the resources. The script takes 3 seconds to handle 100 records . But there are 200 new records per second. How do you handle this load. How do you ensure client requests are not delayed. On the same hardware. You fork() off!
The load on the server is like 2%. But the single script is locked on a loop and must complete before doing the next 100. This is a very optimized piece of code and the transactions are complex. But the resultant operation is too slow. What do you do?
Solution
Make the server work. Hard. Fork the processes. Redesign the code and fork off the code and functions that don’t need intervention and a front-face to a thread. Have as many child-threads as the server can handle (80% throttle) and have each report to a master monitor.
The effect
The ability to handle over 15, 000 records over those 3 seconds. Same hardware. Same DB load. Even more. Sijali. Happy clients. Fat pockets. More time to go shoot pool and play foosball with @iTosh.
Talk of an embarrassingly parallel setup.
Now, lemmi fork() her one more time. Now using 0MQ. Will report how sweet she is.
URGENT OT REQUEST:
I am actively and urgently looking for a BigHand printer/supplier. (The big index-finger or thumb foam glove fans wear with team name printed. Like the ones used for the Safaricom Rugby and KQ. Ama zile za wrestling.) Will order in bulk.
Back to code…
Wazi
An orthodox business model to deal with leechers and proposal vampires
by Idd Salim on Nov.01, 2010, under Coding, Personal
Warning : We suck!
Many a times, all coders, entrepreneurs and marketers face a catch-22 situation. You need to pitch for a project and you need to demonstrate to the client that you are the most FIT person to handle the project. But the more information you give, the more you risk plagiarism and IP theft.
Speaking for my own self, normally, when I write a proposal, I put in years of research, experience and precious time to draft an end-to-end. Sometimes I even give a lot of zero-day stuff.
In my time, I have met people/potential clients/leads I can widely classify into 4 categories:
- Serious and willing : These are the kind of clients that WANT the solution and will go with the best proposal. Price will not be a disqualifying factor, but a step II of the negotiations. Kama uko poa, uko poa. And this category will engage you on a professional level. You do not need to know anyone. Your proposal will speak for herself. God bless this lot.
- Serious but broke : This is the type that will invite you to send your proposal, call you for endless meetings, demos and even test-runs. Then, WHEN it comes to the actual installation and start-of-training, they say : “Manze hii system yako ni kali, but we cant afford the USD 5000 that you are charging. Our budget is KSHS 55k. Acha niongee na mdosi/my dad/my partners, I think we can raise it to 57k”. Time wasters!
- Jokers : This category will take you through the same stages as the one above, but when the actual implementation phase reaches, they will respond : “Thank you very much for your time and effort. However, we plan to implement such a system in Q4 2018. We will be in touch.”
- Leechers, Vampires : This is the worst type. They will make you write proposals, call you for demos and call to ‘clarify some little technical requirements’ and even take you out for ‘lunch kiasi ndio tuelewe hii system yako’. Then, they will talk about costs and timelines, they SUDDENLY, they will go silent. Your Emails and phone-calls will go un-answered. Then, a few months later, you will see your proposal on a newspaper. As a solution. Word for word. Even upto the specifications you proposed. A lot of examples come to mind. One is below.

Leechmode
The leechers use you to get information, as much as possible, then give the actual job to their cousin in Sri Lanka or campo. It is very easy to hire coders once you have the system well spec’d.
So, how do you deal with this problem?
- Learn to detect the leechers. You get an email “Dear Coder X, we need to run an SMS campaign Y. Please send us a proposal detailing all we need, the revenues and how long it will take.”. This is a leecher. Run or read on to step 2.
- Be as technically vague as possible : Always give the layman’s view. If you are a coder, get a marketing person to write your proposals. Coders give too much info. No demos, no nothing until there is an NDA. Liko once told me, “Salim Go for all demos with a legal representative.”
- Charge for the proposals : This is tricky. You need to SELL before you can CHARGE. These 2 models might help. Model 1 for eliminating tire-kickers… Model 2 with Pros and Cons.
Nowadays, i do nothing technical, I mean NOTHING for free. “Salim, let us meet for lunch uni-advise what to pick between Python and Erlang.” – Kanja. “Salim, How do I optimize my mySQL Database to handle over 10M requests per hour. Advice tu. Nitajifanyia mwenyewe.” – Kanja. “Salim, How are you?” – Free.
Back to code.
Wazi
Are Kenyan Coders victims of Zeno’s Dichotomy?
by Idd Salim on Jul.27, 2010, under Coding, Personal
In my study of Calculus, I delved a bit into the pre-calculus era and I came across a very interesting concept by Zeno of Elea.
The most famous of Zeno’s paradoxes is a race between a tortoise and the legendary Achilles called, appropriately, the Achilles. Zeno contends that if the tortoise has a head start, no matter how small, Achilles will never be able to close the distance. To do so, he’d have to travel half of the distance separating them, then half of that, ad nauseum, presenting the same dilemma illustrated by the Dichotomy.
No matter what!
A (above) fractal used to explain the paradoxes of Zeno of Elea — a movement can become impossible if its distance is recurrently divided into smaller pieces. The girl is assumed to walk three times as fast as the turtle, but whenever she turns a corner the turtle will, too. Even though she is faster, she will not see the turtle within a finite number of turns.
The Kenyan Coder’s Paradox
As we strive to make it to MkwanjaVille via code, we face a path that is finite, buy has infinite snooker points. As with any journey one takes, Before one can get there, he must get halfway there. Before he can get halfway there, he must get a quarter of the way there. Before traveling a fourth, he must travel one-eighth; before an eighth, one-sixteenth; and so on.
In essence, the journey can never ‘really’, get started!

Every step has a snooker
A client will not give you a job until you propose in their desired format, even if you have the right solution. The proposal will not be accepted until the price is right (favoring the client), the price is right and the proposal is OK, but you must ona mtu kando or kiss the deal goodbye. You have betrayed your anti-corruption mantra and done that evil thing but you now must wait for 1 month for a response. After one month, your well-research proposal is given to a competing company whose MD is a friend of a friend of the project managers.
If you get the deal, you must wait for 60 days to be paid, if you are lucky. The clients never have any qualms authorizing the job but GOD help you if you dare suggest you might need to be paid. And then what? Downpayment? Are you nuttz?
And the best goes on.
More Info on Zeno here.
Ohh Happy day, Ohhh API day!!
by Idd Salim on Jul.20, 2010, under Google and Africa, PayPal and Africa, Symbiotic, Zunguka

One API to rule them all...
Great day today for Kenyan coders. Ok, let us say, EastAfrican Community coders, for political correctness. I don’t even know how to break this news, so I will just do it my plain no-beating-around-her-bushes method. No, the Octopus has not predicted that Safaricom, MTN and Zain will start supporting local innovations. No. The octopus would rather die than err. To err is to human; not to octopus.So, the hustle continues.
As a CSR, being head of a team of very gifted coders at Symbiotic, I had committed to head the Pay.Zunguka Gateway and API development team and see to it that the Pay.Zunguka API was out before Mid May 2010. But one thing did not lead to another, and we had to inevitable delay the launch.
Well, here it is now. The API. The EuberAPI. One API to rule them all.
Download the API NOW!!
So first things first. What is an API, you would ask? Huh? You are having a larf if you expect me to answer that!! The API has been developed in PHP, jQuery and MySQL and the documentation provided with it makes it totally idiot-proof. Anyone and everyone can use the API and start earning from their hustle, Immediately! All transactions from Mpesa/Zap/yuCash will hit your system, via the API in 5 seconds. Anyone who can copy-paste, can use the API.
Safaricom have indirectly played ball this time round, so flawless end-to-end mPesa support is the first feature of the API. I hope this will not make them Mad. My QA team is still testing the ZAP and yuCash modules, but jump to it. Play with the fully working mPesa support and share your thought on the approach, the model, the logic and the illogic.
If you are a ‘BIG’ fish (read a big corporate with a lot of sensitive transactions) and don’t want to use our API as a payment aggregator, we can license the actual product. This would apply to guys like DSTV and KPLC. So instead of waiting for 48 hours for the transactions to hit their backend system, we can guarantee KPLC customers that their bills paid via Mpesa/Zap/yuCash will be reflected in their account within 5-7 seconds. Cute huh!
Like all my friends will tell you (real friends, not facebook jokers), I believe in seeing, showing and action. Si mdomo mob. So dive right into it! Visit http://pay.zunguka.com/ NOW and have a blast !!
Wazi.
-Salim, Idd

