Skip to content

Author: lafnlab

Michael Hawkes is a professional computer technician who writes open source PHP code as a side hustle, and spends the rest of his spare time playing with his cats, working in the garden, and attempting to learn the violin. He is the sole-proprietor of 10th Street Media, LLC.

Messing around with code

Coding is something I do so rarely I often have to look online for tips and go through alot* of trial and error to get things done. On the current project, I wanted to do something differently.

Normally, in most database tables, it’s common to create an ID field to hold a number that serves as a unique identifier for that record (commonly known as a primary key). It’s easy to setup because the database does all the work, therefore it’s a very common form of primary key. However, primary keys don’t necessarily have to be numbers. The only requirement is that they be unique within the table.

For this project I wanted each primary key to be 10 characters long and consist of numbers and letters. Ten digits, plus 26 lowercase characters, plus 26 uppercase characters in a ten character string means 141 trillion possible unique keys (10+26+26)10 = 141,167,095,653,412 That should be enough for any database… that I’m working on.

In playing around with the code I realized there were a lot of other possibilities. I didn’t have to limit myself to numbers and the Latin alphabet. In fact, I didn’t need to use them at all. The code below is the same code I came up with, but the characters I used are different.

// generates a 10 character random ID
function id_gen($newid) {
$chars = "⩽⩾⩿⪀⪁⪂⪃⪄⪅⪆⪇⪈⪉⪊⪋⪌⪍⪎⪏⪐⪑⪒⪓⪔⪕⪖⪗⪘⪙⪚⪛⪜⪝⪞⪟⪠⪯⪰⪱⪲⪳⪴⪵⪶⪷⪸⪹⪺";
$tmp = preg_split("//u", $chars, -1, PREG_SPLIT_NO_EMPTY);
$tmp2 = join("", $tmp);
return mb_substr($tmp2,0,10,"UTF-8");

Calling id_gen in some PHP code would result in something like this ⩾⪺⪐⪒⪞⪠⪎⪉⪚⪷. Imagine a table full of those as their primary keys. The key to the function is PHP’s builtin mb_substr function. The normal substr function will take a string and cut it to a particular length, but it doesn’t do well with most UTF-8 characters. The mb_substr function can handle multibyte characters, which is why it’s used in this function.

* Fuck prescriptivist grammarians. “Alot” is a perfectly legitimate English word. If it gets used and is understood in context, it’s part of the language.


没有咖啡因 - without caffeine

新年快乐! 我不是新年决心迷,可是有的年我做决心。三年以前我退出了咖啡因。几年以前在工作我经常正常喝了咖啡。因为周末我不喝了咖啡,星期天我平常有了头疼。退出咖啡因以后我少有了头疼。

Another semester

Another semester, another Chinese class. This semester at IUPUI I’m taking EALC-C 301, Third Year Chinese 1. Classes started last week and I can already tell the class is going to be interesting. This is the first Chinese class I’ve had where I feel like I’m in the bottom-half of the class. Granted, it’s a small class, with only seven students, but some of the students have set a high bar. Two students are Chinese, so I’m not sure why they’re taking the class. Maybe they hope to test out of it. Another student taught English in China for a year. I’m under the impression he hasn’t been there for awhile, but he definitely has more practice.

Still, I’m resolved that the high bar isn’t insurmountable. I just have to work harder.

A Chinese coworker, who’s always good for telling me different chengyu (成语), told me about a saying of Mao that appears in classrooms over there:

Hǎohāo xuéxí, tiāntiān xiàngshàng.
Study well, make progress everyday.

I take it to mean I should study everyday, including weekends, to make progress. To help me in my Chinese studies, I’ve also bought a year-long Chinese course from Transparent language. I’ll let you know how it goes.

Music and the Lollipop Lock Screen

Music and the Lollipop Lock Screen

After the battery started giving me trouble in my THL T6 Pro, I broke down and bought a slightly more upscale smartphone – an ASUS Zenfone 2. Both phones are about the same height and width, though the ASUS seems to be a bit thicker. One of the main differences in the phones is that the THL used KitKat (Android v. 4.4.x) and the ASUS uses Lollipop (Android v. 5.x). Anytime I get a new piece of technology, it takes awhile to figure it out and get it to work the way I want it to. I don’t plan on everything working right out-of-the-box.

Because it’s a good security practice, and because my employer requires it, I always set my mobile devices to require a PIN or password at the lock screen. This isn’t much of an issue, unless I’m listening to music. When I’m walking to or from work, I like to listen to music. The music app is set to shuffle, but it sometimes lands on a song that I don’t feel like listening to. With Android KitKat, I was able to go to the lock screen and fast-forward to another song, but I wasn’t to do this in Android Lollipop. Trying to figure it out, it looks like I’m not the only one with this problem.

Although I tried some of the online suggestions, they didn’t work for me. All of the suggestions I read had the same instructions: go to Settings -> Sound & Notification -> When device is locked -> Show all notification content. I did this but my lock screen was still only showing the time, the temp, and the number pad for the PIN.

To fix it, after doing the step above, I went into Settings -> Lock screen -> Skip the slide page -> Off. The Slide page is where the music widget shows up. Try it out.

Go to Music and start a song, then press the power button on the device to turn the screen off. Press the power button again to get the lock screen. Your song should still be playing, and you should be see the music widget, plus whatever other notifications you have enabled. If you want to unlock the device, you can swipe up from the bottom.

Live Below the Line

A year or so ago I read about a challenge where some people in the UK tried to live on £1 a day for five days. This is the level the World Bank sets as the level of extreme poverty. Nearly 1.2 billion people around the world live in conditions of extreme poverty. In the US it equates to about $1.50. I found out about the challenge too late to participate last year, but this year I’m going to give it a go.

Coincidentally, this morning I read that Gwenyth Paltrow will be taking the Food Stamp Challenge. The Food Stamp Challenge is similar, but it sets the bar at about $30 for seven days, which is what a family in the US would have to live on if they relied on food stamps. Both challenges are meant to draw attention of people living in poverty, though Live Below the Line is an organized attempt to raise money for charities fighting conditions of poverty.

While I’ve never lived in conditions of extreme poverty, I remember we used to be on food stamps when I was a kid, and as an adult, there have been times when I was unemployed and wondered where my next meal was coming from. This gives me reason enough to try and help. The challenge takes place from April 27th to May 1st.

It’s not going to be a true challenge. People who live in extreme poverty have to use that money to pay for food, shelter, clothes, healthcare, transportation, sanitation, and so on. For me, the challenge will just pay for food. I already have clothes and health insurance. I don’t have a car, so I don’t have to worry about that cost. My rent, which isn’t exorbitant, runs about $18.50 a day. Since I don’t plan on living on the streets those five days, it’s not a real challenge, in my opinion. However, I plan on blogging and showing what $1.50 a day buys in the US. The answer is not much.


Today I took the HSK 3, which was a disaster. The character 嗔 (chēn) means angry or annoyed, and that pretty much describes my feelings about today’s test.

The HSK 1 exam which I took last year had a vocabulary list of 150 words, and I passed that test. The HSK 2 test, which I took and passed this past December had a vocabulary list of 300 words. The HSK 3 exam has a vocabulary list of 600 words, and I wasn’t familiar with many of them. My original plan was to take the HSKK (speaking ability) today and take the HSK 3 next fall, but our teacher required us to take the HSK 3. Just taking the exam is 5% of our grade, regardless of our score on the exam. The reason it’s required is because somebody in the department is apparently doing a study to compare our success rate to students at IU Bloomington. The only reason I took the test is because it accounts for 5% of my grade in class and because we were promised reimbursement for the cost of the test. Personally, I have better things to do with my weekends than to take a test I’m not prepared for.

All that aside, the test isn’t what I expected either. It started out fine, beginning with the listening section, which was divided into four parts. The first two parts went fine, but when the third part started, the audio on the test stopped. I double checked to make sure my headphones were plugged in, and they were. I adjusted the audio on the PC, and it was fine. I would hear a ping whenever the volume was adjusted. Despite this there was still no audio from the test, and it isn’t much use having a listening section with no audio. I raised my hand and got the attention of the teacher conducting the test. She got another teacher, and they contacted somebody (I assume someone from Hanban in China). The instructions were to close the browser and restart the test, and it would pick up from where I left off. I followed the instructions and was back in business. Annoying, but no harm done, from what I understand.

The next section was reading, which was fine, despite the fact that I didn’t know many of the words. I’m in my second year of Chinese classes, but felt as if I was asked to take the final exam for a third-year Chinese class. Needless to say, I guessed on a pretty much everything in that section.

The final section was writing. It should have been my best section, but it ended up being the worst. I took the paper practice exams, and did okay because I could write down the characters even if I didn’t know how they were pronounced. I did pretty good at guessing nouns, verbs, adjectives, adverbs, etc, so putting them in the right order wasn’t too hard. On the computer, you can’t do that. You can’t type in something if you don’t know the Pinyin for it. I tried to copy-and-paste, but there was no way to do so. Clicking on the characters did nothing. Double-clicking did nothing. Right-clicking did nothing. Ctrl+C and Ctrl+V did nothing. The only way to input a character is to know the pinyin for it, and I only knew about half the characters.

In the last part of the writing section, they have a sentence, and they give the pinyin for a character they want you to type in. It should have been easy, but as I was getting ready to type in my answer to the first question (it related to the cost of something, and the pinyin was ‘yuan’, so my response was to be 元) it kicked me out. I thought I had a couple of minutes left, but I don’t know if I ran out of time, or if there was an error of some sort.

So, lessons learned. First off, in the future, I’ll only take the tests when I’m sure I’m ready for them. If I’m required to take a test, I’ll a) make sure I don’t have to pay for it, and b) set out to deliberately fail it. I see no reason to try something I know I’m not ready for. Since this was part of somebody’s study, I’d like to fuck up their results out of spite.

Perhaps the most important lesson, however, is that the paper practice exams are worthless for anyone taking a computer-based exam. Supposedly, there is an online practice test at the HSK website, but I’ve never been able to get it to work. Maybe it just doesn’t like Macs. Regardless, if I can’t practice taking the computer-based exam, I’d feel much better taking the paper based test.

Noun + adjective + 得 + 不得了

We just started working on Chapter 19 of Integrated Chinese last week, and part of the homework had us practicing the phrase 不得了 (bùdéliǎo), which means extremely or exceedingly. It usually follows this pattern:

noun + adjective + 得 + 不得了。
Noun is extremely adjective.

Nuówēi lěng de bùdéliǎo.
Norway is extremely cold.

Lǐ Yǒu yònggōng de bùdéliǎo.
Li You is extremely hardworking.

This sentence pattern is very useful. In fact, I’ve even been able to use it with one of my coworkers. If they receive a suspicious email, I encourage the users I support to send the email to me to see if it is legitimate or if it’s a scam. This morning, a 中国人 coworker sent me an email that was suspicious, and I replied:

I think it’s extremely bad.

Maybe it’s overkill to describe a spam email, but it was a good chance to practice, and she complimented my Chinese 🙂

Duration of actions

In Chapter 18 of Integrated Chinese, Dialogue II has a section which describes the duration of an action, and it shows two sentence formulas for it. One of the examples they give is:

She listens to recordings for an hour everyday.

Both of the Chinese sentences say they same thing in slightly different ways. The first one uses verb repetition, and the formula is something like:

Subj + (how often) + verb + object + verb + (how long).

The second sentence doesn’t repeat the verb, but does put a duration of time between the verb and the object. Its formula is something like:

Subj + (how often) + verb + (how long) + (的) + object.

De (的) is apparently optional in the second type of sentence. Our teacher didn’t have much of an explanation for it, other than saying that it sometimes sounds right, and sometimes doesn’t. I guess that is something that comes with experience.

Now for some practice sentences of my own.

I walk for an hour and a half every day.

I review Chinese for 30 minutes every day.

Wang Peng plays basketball for two hours every Saturday.

Li You studies Chinese for twelve hours every weekend.

Verbs are kind of tricky in Chinese, because there are verbs and there are verb-objects. They are tricky because while some verbs are only one character, some are two characters, which means they can get confused with verb-objects, which will always have at least two characters. I guess it’s another one of those things where it will become easier to understand after I’ve learned more.

Time expression + 没 + Verb (+ 了)

I have a test in Chinese class later today, so this post and the next are a couple of things the teacher told us will be on the test.

Chapter 18 of Integrated Chinese*, page 231 (运动 – Sports), the Dialogue I section describes the
following formula:

Time expression + 没 + Verb (+ 了)

It’s used to describe an activity that hasn’t been performed for a certain amount of time. They have several examples, one of which is:

He hasn’t gone online for three days.

On Page 232 it offers a counter example, showing how long something has been happening:

I have studied the Chinese language for two years.

Really? I haven’t studied the Chinese language for two years.

The point of these practice exercises is for me to come up with come of my own sentences using the formula they described, so mine are below.

I haven’t studied French for five years.

I haven’t drunk coffee for the past day.

It hasn’t snowed for a week.

I haven’t been to Norway for two years.

Gao Wenzhong hasn’t called Bai Ying-ai for four days.

* Integrated Chinese, Level 1, Part 2, Third Edition