Get floored!

This another episode of friends don’t let friends commit bugs into main. I was reading a previous post here on the FAM blog. It gave me a flash back of the one time when I discovered hash tables.

…to bucket a String, s, say in the jvm, you might like writing “s.hashCode() % bucketCount”

Except that expression will produce, as you will quickly discover if you had the whole hash table, negative numbers half of the time for strings with just a few characters.

The ‘%’ operator returns a remainder that has the same sign as the dividend of the division in question, and in this case the dividend is the hash code which is negative sometime due to overflow of 32-but integer range. One replacement operator you probably can use is “math.floorMod(s.hashCode(), bucketCount)”. The floor modulo operator produces remainders that always has same sign as the divisor, in this case the bucket count. This behavior is well documented since C and backwards, so hopefully you will find this information corroborated by many webpages.

Python, (and other scripting languages like Perl and Ruby) on the other hand, has the opposite convention. ‘%’ operator is C/Java’s floorMod. In the python ecosystem, ‘numpy.mod’, ‘tf.math.mod’ and ‘torch.remainder’ all correspond to floor division and return remainder having same sign as the devisor. Confusingly, to get C/Java ‘%’ method in python, you have to call something these all call ‘fmod’.

Some websites suggest masking the number to take the lower bits then %, which may be slightly different from computing the hash in long integers followed by %. Another (stack) overflow post adds the module calculation inside the String.hashCode implementation so that only remainders accumulate, thus avoiding the negativity entirely.

In any case, if you had to write this, mostly likely the slight imbalance between positive and negative numbers would not bother you and floorMod is easiest method to call on any generic “hashCode()” implementation.

Friends don’t let friends drink and drive.

Friends don’t let friends err and merge.

The sad thing about sad things

A few years ago, I stopped being a W4 employee. I had a midlife crisis that I feel too much of me do not want to work in this economy and politics. (That was long before this post-Covid anti-Asian movement) I am sad about it, as we Chinese-Pennsylvanian Americans are steeped, doubly , in work ethics indoctrination. It is the modus operandi for generations and it is for me.

But the opposition in my mind was great, and for many varieties of reasons, and so I stopped working.

Recently, President Biden announced a second round of raising benefits for seniors. The first round already hit my parents monthly deposits. This is some serious money movement that people can see and feel. I feel it because my parents spends more on me, yes even when I’m fast on my way to my semi-centennial.

Today, I feel an ever so slight bump within, like that earthquake I felt sitting on the toilet, it shook me in a weird way: a sudden thought of, “wait, I want to do that.” stirs. I don’t resent taxes as much as before. (Don’t worry, I’m sure that will recover though) It feels good that this happened. It feels good that a suffering populous is treated with dignity and deserved priority.

The sad thing about this is that I can definitely see my own and many other peoples selfishness eventually push us all to vote against the next president who want to continue these elderly benefits.

Sad that it is good but will surely be both hated and terminated. Even sadder, is the fact that I actually like these increase in elderly benefit. Am I so old? Or am I dreading poverty in old age? Are my happiness mere faint echos of those of my parents? Why do I like it? Is it because I’m Chinese ?

So sad !

And I don’t even know why.

When you can’t beat them

First instincts are, as Jackie Chen suggests in one movie of his, “run!”

But there are other options. The less manly men might be able to conjure the idea to “get help” before the rumble.

Also, my contemporaries may know of many forms of bribery or coercion available to them that work great without the actual physical act of conflict and infliction. (Most prominently things like dozing, hacking,… and other forms of intimidation)

And if all that fails, maybe then join them, huh?

Or, I guess the thing that can happen is one can just take a beating. But we probably want to avoid that if possible.

What? But why? Wow! Wow! Wowah!!!!

Interesting news late Q3 2021, the US federal just reached some kind of agreement with a Chinese company named Huawei to release her by requesting extradition from Canada.

It’s kind of strange to think the whole thing through. On the one hand, she was captured due to her involvement in a company that allegedly sells equipment to Iranian government. Iran was then a terrorizing enemy of USA and… presumably stopping Huawei from selling equipment to Iran because that equipment when used in Iran could cause USA harm.

However, at the same time, under the same former president Trump, the US lead several countries such as Canada, France and England to officially ban purchase of Huawei equipment for use in their countries. Because presumably the equipment is substandard for some reason.

The details of these political decisions are not clear. From a technical perspective, it might be really interesting to know exactly what spying capabilities Huawei equipment has. On the other hand, it would also be very interesting to find out why that same disabling capabilities are not useful to us when sold to Iran.

The US being unable to deal with Huawei network equipment might be a technical failing as well. One wonders why we couldn’t develop mitigating systems to counter sabotage the alleged spying capabilities? I may be very naive, but honestly, didn’t the US invent wire tapping? I mean we invented the wires and telephones to start with… and who invented the internet but the American military? why is it that we can’t deal with a few piece of internet equipment ?

Overall, another aspect is that the lack of serious competition will also slow down the democratization of internet services. In all honesty, a country like America, shouldn’t we have had a mini-musk or a mini-jobs that comes to the foreground to kick that PRCPLC company’s ass? It can even be lead by a former soldier in the Is army! Or maybe the much lauded marine can have an ex that creates a company and fights back, the proper capitalistic way.

Because for gosh sakes I sure can appreciate cheaper, or at least slower appreciating, cellphone and internet prices, equipment, subscription and all. (and I will quickly hope superfluously that it is a result of free market competition)

The fact that American intelligence can’t get basic information from Chinese counterparts about Iran, once their equipment is deployed, is quite troubling.

I would have thunken that the two country were on better terms than this. Bombs exploding on home soil is to be prevented, and our super powers should absolutely be aligned on this matter. If China knew Iran has a very successful plan to sail a ship into the Statue of Liberty, wouldn’t they tell us? It sure doesn’t hurt them any, but would save innocent peoples’ lives—obviously many of those tourist had been mostly Chinese nationals anyways. And if US has eyes o a Uighur faction setting up a bit rocket to blow up Ürümqi wouldn’t we tell somebody so all those innocent people, and many tourists of American origin, don’t have to die?

Perhaps with a new era being ushered in by this radical president Biden, the world can move to a significantly more peaceful and happy time for all. Ending the war in Afghanistan, ending this stupid and self-contradicting extradition of Huawei, … man, this real world is more exciting than watching all the Star Trek series coming out on NBC! More exciting than Dune and Foundation debuting in the same week! And definitely much more exciting than billionaires flying themselves and friends to “the space.”

Real world radical changes are afoot!

Let’s see what happens next!

A Little Vegan Recipe

Cauliflower cut into rounds of about a cubic inch in size and shape. Scallion whites cut to inch lengths, greens kept whole. Sapphire grapes washed and separated from vine. Heat a thick pan with scallion whites, grapes and oil until oil is popping hot. Add generous amount of oregano, let grill for 30 seconds or just before anything is burnt which ever comes first. Dump cauliflower in to the pan. Let it fry for a bit before stirring. Periodically stir in more salt, oregano, dill, oil, black pepper, and splashes of water for up to 30 minutes. Each time ingredient is added, turn on high heat while storing, then low to medium heat to cook. The scallion greens may be mixed in to add to the taste during cooking and removed before serving.

Serve steaming hot over steamed rice or bread.

The grape and spices all add depth to the flavor of cauliflower. An added benefit is that there is a beautiful purple color to the dish after cooking the ingredients through.

Ulteriorly, this is a good way to use that expensive organic grape you bought from farmer’s market but left out of the fridge overnight… maybe some fruit flies have developed, but it all adds to the taste and color once fully cooked through. It may work differently if you have all fresh ingredients, but what we had was dried oregano and dill.

The Rule of 240

No! It isn’t where a Chinese chef requires no more than 239 grains of sesame to be used on a 烧饼(barrel toasted pancake) lest one achieves 240 and expel excessive wind.

Instead of an undirected 20% project, one may plan for each employees to participate on two projects investing 40% of their effort into each. The extra 20% is headroom for coffee/tea drinking, context switching, teaming and other human overheads. (Such as your 20% project)

Obvious tunable parameters include whether the tasks are performed exclusively or simultaneously with prioritization at any moment. The interval of processing—beginners should start with 1 day for each task switching 4 times a week for a normal work week. Staggering project phase is usually a big plus. The usual management tools like OKR’s, setting deadlines and priorities, having daily blocker analysis, and standing up once in a while all apply.

Effectively, a lot of people already do this maybe with even more tasks at different stages of completion out of self-optimization or joy. It has similar effect as computer multitasking. When one of the tasks becomes blocked, often due to either externalities, monotony or fatigue, a different task can be worked on using available resources. It is reported by researchers that human have yet to developed widely deployable means of correctly and efficiently multitasking with one brain. But for most people, switching between just two tasks balancing cognitive and physical load is doable.

In the post-COVID work from home era, we lose some valuable commute time where our mind and body recover its depletions, this 240 rule can produce superior personal aggregate performance over extended period of time.

Let’s get 240!

Sample witch

Alice the witch no longer apprentice, space pirate empress presumptive, has come to visit the old man. Her investigation into the simultaneous attack on earth and the destruction of lunar pirate base by parties unknown has yielded no results so far.A

lthough she has aged none , her magical powers have become out-of-this-world, quite literally. The space pirate empress, second sister of her witchcraft teacher, the old lady, has taught her much about doing magic in space. Since the inertia references and spacial conditions are all different, the physics and chemistry are all different, and therefore relevant magic about those are also very very different.

But Alice has learnt them well. She can drill a hole through the core of a planet, for purpose of loot and plunder, with a mere affectation of a spell. She could put a habitable bubble around ten thousand people. Of course, most important of all, her broom now flies in space. That was one of the first things she learned from the empress. It felt like the most liberating skill she has ever learned.

“I can offer you one of two aids,” said the old man, who is known to be the oldest and most powerful wizard on earth. “I have the capsule of knowledge, and I have the eel of action.”

The attack on earth was brutal. It was focused on the old witch mountain where the witch academy and many wizards live. It was all but impossible for the old lady and old man to organize a defense in the matter of a minute’s time, and a defense they did put up, consuming much of the old wizard mountain’s magical supplies.

The attach on the moon base was even worse. Because the empress was very happy that day, she had taken Alice to the far side of the moon’s dark side to practice her drilling magic. The empress is not the same emotionlessly controlled teacher that the old lady is, she can sense Alices excitement for new knowledge and new powers. She baths in Alices joy and excitement. When Alice succeeded in descending into the moon, the old lady’s sister bursted out in laughter of maniacal joy. But then, she sensed the attack and that it was too late to rescue any one from her beloved crew. The two of them hurried back to find the devastation caused by energy weapons I know to them.

“The capsule of knowledge grants you knowledge about everything you consider, you will know all that has past, all that is present and all that will be in the future.” Old man states, staring at Alice with muted but bemused eyes, as if watching the same flashback as Alice. “The eel of action grants you the right actions, your body will move and perform magic as it is right to do in a timely manner.”

Alices mind gradually pulls back to the present… as she slowly realizes that the old man’s explanation required more of her mind than she could easily give it in one breath, she breathed.

“So, I would choose the eel of action, for action is what matters.” Alice felt confident that this was wha the old lady emphasized in her training.

“Admittedly most alluring,” says the old man, “but you may discover that lack of understanding for your own actions can be restrictive, frustrating and ultimately painful.” Warns the old man as he reaches for the eel, “and often it is laughable,” he looks away front the eel, “the right action often is absolutely silly.”

Alice suddenly felt the urgency in the old man’s warning. He is practically in tears. “Okay, then I will take the capsule of knowledge.”

“But be warned, that knowledge cannot help you to act. I believe you understand the importance of action, but from knowledge to action is a wild chasm that can never be filled.” The old man relaxed, but seemingly in hopeless despair, “knowledge is maddening when there is no right action.”

Alices pulled back her hand from the capsule realizing the help from old man is a challenge that she is not prepared to take. She bids the old man farewell and continues her effort to discover the attacker of her worlds.

… the pirate armada that the empress revealed to her, could it have attacked the earth? Was it the earth witches that attacked the lunar base? These possibilities race in Alice’s mind towards a singular conclusion,… the ever peaceful witches are actually engaged in multigenerational warfare with space pirates and possibly other alien events…

Why minority stories

I’ve been feeling uneasy about the huge push by big media and Hollywood (neither of whom I associate myself with even on friendly terms) are pushing so hard to have more minority presence in stories they tell. (As in movies, TV shows and other fictional work like novels.

Let’s drop out of warp speed and into a space where we can and do consider race in their self centered perspective. Majority Caucasian people in America decides they want to integrate more of minority and foreign cultures to enhance their own lives. Better stories because of variety. Or perhaps they want to absorb some good bits that foreign people and culture has experimented for a long time (like yoga and meditation). Okay, this makes complete sense.

The minority races, those that do come to America, are eager to provide these aspects of their persons and culture because they were essentially free for them to get and otherwise valueless. It makes sense to dish out the sacred teachings of yogis, mavens and senseis because those wisdom and secrets are kind of useless because everyone there knows them well. But to your red blooded white American boy, it is the heavens and nirvana combined.

At least, that’s what the producers and show creators are thinking when they scream for more minority presence on screen. YMMV though depending on the exact mixture of ingredients.

There could also be rational explanations for why American minority stories are being sought. The essence of this truism, btw, this is one of those cultural secrets from China: is that many minorities suffer from creatively engineered indignities and pains. The centuries or lopsided society created by white majority discriminating against colored people have not only given white people comfortable lives, but also the leisure and freedom to engage in active, sustained and targeted tormentation of minorities. The result is that American minorities had to work much harder to get anything from basic living necessities to comfort items. The net result is that true minority stories tend to be more interesting because of the straining and maneuvering they had to perform to live here.

It’s hard to describe. For example, if white peoples were naughty boys and they had nothing better to do than to rip off two legs from the left side of an insect. They discover that the 4-legged creature, after some struggling times, figured out how to crawl in gradually shifting circles in order to achieve a forward motion towards its food which it continues to strive for in order to bring it to its children. The insect is surely in miserable pain and horrific depression. But to the boys, this dance looks beautiful! He might even reward the insect by feeding it and taking it away from its children to dance for him full time. Modern version of this story may inspire the boy to use reinforcement learning to train a tiny robot that he trains to mimic the biological insect… how absolutely fascinating are our lives!

Of course, it is quite possible that American minorities, despite their sufferings, did not create interesting stories. This would be the ultimate sad story, that we minorities not only got the worst end of the birth lottery, but also that it happened to no greater good that we can claim part of. We suffered for naught.

That insect might have stepped on its trailing entrails and pulled everything out thereby accidentally committing suicide. It’s children eventually finding him will eat his corpse out of hunger. Disgusting and not that interesting… at least not to me atm. Please do not make a movie about that!

All these thoughts, mainly because I see a lot of Asian-centric entertainment coming online in America. But I do not feel like there are very identifiable, trustworthy, reasonable, powerful and honorable cultural leaderships in America.

Maybe music stars and movies stars did this for previous generations? Maybe presidents and other politicians did this for previous generations? Maybe school teachers and maybe even police provided this for everyone in the past? Who is showing us the way today? Who will show modern American minorities the way today?

Flower Teas

After tasting a flower tea recently, I have gained new appreciation for all the foreign (non-Chinese) teas that people drink for fun. During my dear mother’s birthday celebrations, we mixed a gift to her, 龙井茶(aka Longjing, dragon well, etc) with a gift to her dear granddaughter, rose buds. The resulting tea is very aromatic but lacks the strong bitter taste this green tea has when steeped by itself.

I guess I am starting to appreciate some flowers in my tea. Although in this particular encounter, green tea is new crop and rose buds were harvest at least 10 months ago. The rosebuds definitely lost a lot of its original coloration and aroma by the time we used it. This gave the tea a very slight hint of rose flavor, leaving us the palate to enjoy bitterless green tea.

This was vry interesting! But I still can’t stand too much flower in green tea, I still want that translucent scent and transmittance when I drink my green tea. plus the weather here in Northern California is so warm that drinking flower tea with milk, sugar and infused oils is simply too much calories for the taste. Corollarily I now have espressos and no longer drink any of those prepared coffee drinks, milk, sugar, turmeric and all.

If you’re a non-Chinese tea drinker, maybe lighten it up a bit and give rose bud and longjing a try.

The Starfleet Emblem

I know I’ve been complaining that the trek of late 2010’s is bad in many ways.

Subsequent events have revived my believe in the original myth of the Starfleet: there seem to be something rather deep in this whole Star Trek thing… For example the Starfleet emblem. Of two slanted triangular shapes is supposed to represent an asymmetry in the physics of our world’s energy that enables the almighty warp drive to function. This idea seems so deep and have very deep connections with other difficult endeavors into theories of things as well.

Admittedly though, I know of other traditions that have similarly foretold some key elements of what I needed to make gigantic leaps in my own progression. What I don’t know is how to actually recover these wonderful wisdom in the right context for them to be duly useful.

I am in awe of all that we have available in all shapes, sizes, forms and manifestations in our modern lives to live the good life and do the good deeds and to be all that we can be!