September 23, 2016

Why you should forget everything you learned about bed pillows

0 comments
Do you know the history of bed pillows? This is the history according to Wikipedia:
The first people to use pillows were those who lived in early civilizations of Mesopotamia around 7,000 BC. During this time, only the wealthy used pillows. The number of pillows symbolized status so the more pillows one owned the more affluence he or she held. Pillows have long been produced around the world in order to help solve the reoccurring problem of neck, back, and shoulder pain while sleeping. The pillow was also used to keep bugs and insects out of people's hair, mouth, nose, and ears while sleeping.
Pillow use has been associated with the mummies and tombs of ancient Egypt dating back to 2055–1985 B.C. Ancient Egyptian pillows were wooden or stone headrests. These pillows were mostly used by placing them under the heads of the deceased because the head of a human was considered to be the essence of life and sacred. The ancient Egyptians used these wooden or stone pillows in order to provide support to a corpse's head, uphold body vigor, keep blood circulating, and keep demons away. 
The Romans and Greeks of ancient Europe mastered the creation of the softer pillow. These pillows were stuffed with reeds, feathers, and straw in order to make them softer and more comfortable. Only upper-class people typically owned these softer pillows, however all classes of people were allowed to use some type of pillow while sleeping in order to give them support. People in ancient Europe started to use pillows when going to church in order to kneel on while praying and to place holy books on. This is a tradition that still lives on today. Additionally, the Romans and Greeks used their pillows by placing them under the head of those deceased just like the ancient Egyptians did.
Chinese pillows were traditionally solid, though sometimes used with a softer fabric over them. Over many Chinese dynasties, pillows were made from a wide range of materials including bamboo, jade, porcelain, wood, and bronze. Ceramic pillows became the most popular. The use of the ceramic pillow first appeared in the Sui Dynasty between 581 and 618 while mass production appeared in the Tang Dynasty between 618 and 907. The Chinese decorated their pillows by making them different shapes and by painting pictures of animals, humans, and plants on them. One common type of pottery used was Cizhou ware. Chinese ceramic pillows reached their peak in terms of production and use during the Song, Jin, and Yuan dynasties between the 10th and 14th century, but slowly phased out during the Ming and Qing dynasties between 1368 and 1911 with the emergence of better pillow making materials.
So what can we learn from the history of bed pillows? The bed pillow was used to keep bugs and insects out of people's hair, mouth, nose, and ears while sleeping. I'm not sure about this, why can't insects climb up on the pillow? And what about the Chinese use of ceramic pillows? This is how they looked like:

Source: Victoria and Albert Museum

Who on earth would you like to sleep on a ceramic pillow? According to this article, the author speculates that they were used to encourage a better sleeping position for the body, or to maintain the highly complex hairstyles worn by women during the Ming dynasty. Other reason might have been that the material qualities of ceramics were thought to have health benefits for the sleeper, and that bed pillows were thought to influence and guide dreams in the hope of producing male heirs.

But back to the present. This happened: my bed pillow was torn apart (it was old so I didn't have a pillow fight), and after cleaning the pillow material from the floor, I had to sleep without a pillow. After a good night's sleep I asked myself: why are we using bed pillows? So I decided to do some research. According to this article, the benefits of sleeping without a bed pillow are:
  • It will save you money. But bed pillows are not expensive, and even though every cent counts in the end, you shouldn't sleep without a pillow just to save money.
  • It will lead to less neck, back, and shoulder pain, higher quality sleep, and even fewer wrinkles.
...and the benefits of sleeping with a bed pillow are:
  • It improves sleep quality and fits more physiologically and mechanically with the natural curve of the cervical spine. Sleeping on your back without a pillow changes your neck angle from its normal daily position. When standing, your neck also has a certain curve to it. If you sleep on your back, that curve is also distorted.

So if you sleep without a pillow you will get a higher quality sleep, and if you are sleeping with a pillow it will improve sleep quality? So instead of listening to articles that argue back and forth, the human guinea pig in me decided to experiment to sleep without a bed pillow.

Three weeks have now passed, and I can say that I'm not missing my pillow. I feel a little bit more rested, I feel that my posture has improved, and my neck hasn't begun to hurt even though I sometimes sleep on the side. One of the articles argued that "Sleeping on your back without a pillow changes your neck angle from its normal daily position," but if the bed is soft, won't that compensate for it? Anyway, it's hard to tell after just three weeks because other conditions might have changed, such as the weather. It's a little bit cooler these days and that might have made me feel more rested. So I might do a follow-up to this article in a few weeks.

If you want to take it to the extreme, some argue you should sleep on a hard surface:


But I think I have to wait until my bead breaks until I begin to sleep on the floor...

September 8, 2016

How can engineers solve a problem like ISIS?

0 comments
I'm an engineer so I like to solve problems - not only smaller problems but also more global problems. There are a lot of global problems out there, like North Korea. I don't think I can solve a problem like North Korea, even though there are peaceful solutions. But it can't possible hurt to think about the solutions in the back of my head, and maybe one day I will come up with a solution no one else has thought about. What if Elon Musk had said: "It's not possible for one man to solve the problem of expensive rockets, so I will not try!" But it turned out it was possible for one man to solve that problem: SpaceX.

Another global problem we have is terrorism. While the probability that the North Korean problem will affect me personally is low, the probability that terrorism will affect me is still low, but considerably higher.


To come up with a solution to terrorism, I decided to read the book The Great War of Our Time: The CIA's Fight Against Terrorism - From al Qa'ida to ISIS. It is written by Michael Morell, who has had several high ranking positions within CIA, including the job as he who had to give the President of United States his daily briefings on terrorism threats. So the book includes several anecdotes from George W. Bush, including what really happened when Bush's dog Barney got a piece of plastic stuck in his throat during one of these intelligence briefings, and the quote by Bush himself: "Fuck diplomacy. We are going to war."

The book is not including any details on how CIA is working to solve problems like terrorism, because that's classified. But the book will give you an overview of terrorism, from 9/11 to ISIS. This overview includes stories such as why CIA failed to predict 9/11, why CIA failed to find any weapons of mass destruction in Iraq, what are some misconceptions regarding the embassy attack in Libya, that cyber crime is now generating as much money as the illegal drug trade, and an entire chapter on Edward Snowden criticism. But it also includes more personal stories, such as the confusions within CIA after 9/11:
I seriously thought a nuclear detonation in New York or Washington was a possibility - to the point of telling my wife that if such an attack were to happen in Washington to put the kids in the car and start driving west and not stop. It was surreal.  

The book argues that it is impossible to beat an organization like ISIS with bombs alone. The reason is, according to the book, that terrorists organizations have "nine lives":
When the West and its allies keep pressure on al Qa'ida, when it has to worry about its own security more than it can about its operations, al Qa'ida loses capability. When that pressure is not there, when it is free to operate, its capabilities grow. It is a pattern that has played out over and over again, wherever al Qa'ida has operated.   
So the west can put pressure on ISIS, but it will not defeat ISIS. The west has put pressure on al Qa'ida since 2001, but al Qa'ida is far away from being defeated.

What you also need is to stop the supply of people who's joining terrorist organizations. This is also more cost effective. The dollars spent by the US government on programs related to stopping radicalization are an infinitesimally small percentage of the government's overall counter terrorism budget. The problem is that it involves other countries, so it's far easier to drop expensive bombs on ISIS than it is to change a country that supply ISIS terrorists.

But one country that has succeeded in stopping the supply of new terrorists is Indonesia:
Between 9/11 and 2006, Indonesia suffered sixteen terrorist attacks, resulting in more than three hundred deaths. In the next eight years, there were only five attacks, causing fourteen deaths. And, as of early 2015, only about 150 Indonesians had gone to fight in Syria, a remarkably low number for its population and for its terrorist past. While excellent intelligence and law enforcement work have played a role - and these tools will remain vital, particularly as many terrorists will be released from prison over the next few years - so have the Indonesian governments's counter-radicalization programs.
At the core of Jakarta's program is a willingness to work with any entity that can reach young people with the right messages. The program is systematic and reaches almost every part of Indonesian society. The messages are essentially two - that the extremist interpretation of Islam is not consistent with the Koran, and that there is great value in tolerance.
Religious organizations in Indonesia are popular within society and are therefore an important channel for delivering the government's counter-narrative to al Qa'ida [for every narrative of al Qa'ida's, there must be a counter-narrative delivered loudly and widely]. Jakarta, for example, works with imams and mosques to offer a variety of perspectives on Islam, particularly to youth and student groups. Schools are also a focus - courses emphasize inclusion and tolerance. All the world's religions are now studied, not just Islam, and schools are working to provide multiple perspectives on some of the issues that have played a role in radicalization, such as the relationship between Israel and the Palestinians.
Popular culture is also used. The government communicates with young people through popular musicians who communicate carefully crafted messages aimed at counteracting radical ideas. Music with lyrics about tolerance as an alternative to extremism has become popular in Indonesia and indeed throughout Southeast Asia. All of this is supported by a variety of media - books, articles, newsletters, the Internet, television, and radio. TV and the Internet focus on urban populations. Radio stations reach rural areas.
All of this, of course, requires focus, effort and resources. It needs to be done throughout the Muslim world. It needs to be led by the governments in question. And it needs to be supported by the United States.

So what can engineers do to stop the supply of terrorists? Yesterday I found the article Google's clever plan to stop aspiring ISIS recruits. It says that Google can use a combination of its search advertising algorithms and YouTube to target aspiring ISIS recruits and hopefully preventing them from joining the terrorist organization. What Google has found is that "there's a lot of online demand for ISIS material, but there are also a lot of credible organic voices online debunking their narratives." This is exactly what the book said: "For every narrative of al Qa'ida's, there must be a counter-narrative delivered loudly and widely."

What the software developed by Google is doing is that it can place ads alongside results for any keywords and phrases it has determined people attracted to ISIS are searching for. When you click on these ads, you arrive at Arabic- and English-language YouTube channels. These channels have videos like testimonials from former extremists, imams denouncing ISIS's corruption of Islam, and videos from inside the ISIS's caliphate in Syria and Iraq showing it is not the paradise they say it is. One of these anti-ISIS videos is showing a line of people trying to get food.

This new software seems to be working. When they tested it during two months, they found that searchers clicked on the anti-ISIS ads three or four times more often than a typical ad campaign. And those who clicked spent more than twice as long viewing the anit-ISIS videos compared with the best estimates of how long people view other YouTube videos.

September 4, 2016

Traffic Light Simulator - a Ludum Dare Game

0 comments
Ludum Dare is a competition where you are making a game in 48 hours. You have to make everything yourself, so you can't download any textures or models from someone else. There's also a less hardcore competition going on at the same time where you are making a game in 72 hours and can use other people's textures and models. In the latter competition you can also work in a team, but in the 48 hour competition, you have to work on your own.

I don't know if it's easier to make a good game if you are living in a time zone in US compared with in any other part of the world? If you are living in Europe, the competition begins at 3 AM on Saturday morning and ends 3 AM on Monday morning. So if you have a job to go to on Monday, you can't work the entire 48 hours. If you are living in US, the competition begins on Friday evening and ends on Sunday evening. So I suspect it's easier to maybe come up with ideas on Friday evening, and then work for "two days" to make the game itself?

Anyway, each competition has a theme, and the theme this time was "Ancient Technology." You can stretch this theme so you won't be disqualified if the game is not 100 percent based on that theme. My original ideas included:
  • Leonardo Da Vinci's tank
  • A ship game where you are controlling one of those sailing ships from Ben Hur
  • A game where you attack a castle with a trebuchet, which is a catapult
But after brainstorming ideas I came up with an ancient technology called traffic lights, so I made a Traffic Light Simulator (click on the link if you want to play it or download the entire source code).


Have you ever heard the history of traffic lights? Neither had I so I decided to read about it on Wikipedia. The story goes as follows:
The world's first, manually operated gas-lit traffic signal was short lived. Installed in London in December 1868, it exploded less than a month later, injuring or killing its policeman operator. 
My original plan was to include exploding traffic lights, but in the end I realized that it wouldn't work. A single exploding traffic light would ruin the game, because all cars and pedestrians would collide with each other. But in hindsight it would be possible for the player to rebuild the traffic light, but 48 hours is just 48 hours so everything is easier in hindsight.

After about 48 hours I ended up with a game where you control 12 traffic lights in an intersection. There are both pedestrians and cars from the era (which I modeled in Blender. The game itself was created in Unity). The game begins slowly with just a few cars and pedestrians, but as you get more points, more cars and pedestrians will arrive. You will be punished (get negative points) if a car crashes or a pedestrian is hit by a car, and you will get points if the cars and pedestrians arrives safely to their final destination. If a car crashed it will begin to smoke and you have to click on it multiple times to remove it or other cars may hit it.

To make the game more stressful, the cars begin to honk if they have to wait for too long. I also added an ambulance that will make an annoying sound I made in a cool software called Bfxr. Remember that you are not allowed to download the sound of an ambulance, so I had to make my own ambulance sound. It all looks like this:





What you win in a Ludum Dare competition is fame and honor, so you are not taking part in the competition to make money. But you will learn something new, you can test an idea you've had in the back of your head, and if the game is good you can improve and sell it. You will also get feedback. A week has passed since the competition and people have had the time to play my game. The feedback so far includes:
  • That was really sweet, although the traffic lights weren't always clear to where they pointed. I think I killed a person or two...
  • I really enjoy this game!!! Best which I had seen on this LD! Fun and difficult. btw. why all drivers are drunk?
  • Very nice idea and well done! And quite difficult to manage after some time. It would be nice though to see where the cars and pedestrians want to go when they approach the intersection.
  • It starts off very slow, and i think it would be a lot more fun had it been faster. Overall, a nice entry.
  • The idea and the game is very fun. I would like some kind of end goal. But overall well done.

So why are the drivers acting as if they were drunk? The cars are following a series of waypoints, but the cars are not that good a driving between the waypoints. The reason is that they are just caring if they should drive left or right to reach the waypoint, so when they realize they should drive in the opposite direction, they have driven a little bit too far. I think the easiest way to solve this problem is by using a PID controller. I tried to implement one in the game, but ran out of time, so I had to leave them drunk. 48 hours is after all just 48 hours... 

September 2, 2016

Why marketing your company by sharing your knowledge is working

0 comments
A few years ago I found a YouTube video where Jason Fried (@jasonfried), who co-founded 37signals, argued that the best way to market your company is by sharing your knowledge. You can find the article here: How to market your company by sharing your knowledge. Among other things, he said that:
  • We tend to buy products from someone who taught us something - not just from big companies
  • You should out-teach your competitors - not out-spend them 
  • We don't want to give away our knowledge because we are afraid that someone will steal it and use it against us, but you shouldn't worry about your competitors - but be aware of them. 
  • PR firms are a waste of money and advertising is expensive and can be difficult depending on the company you have 
  • If you teach, you will get an audience that will come back to you and spread the word about you to their friends 
  • One article by Jason Fried took 15 minutes to write, but more than 800,000 people has read it. How expensive would it be to drag in 800,000 people with ads?

I've tried to apply this since I wrote the article. Not every article on this blog has the purpose to teach something to someone, but most articles have this purpose. I've also extended this to not just write articles on this blog, but also explained how to program complicated games in Unity. Last week I wrote an article about how to Use Linear Algebra to solve problems in Unity with C#, and guess what? Microsoft's official .NET Blog gave it a link: The week in .NET – 8/30/2016.


Why is this link important? Well, Google is using links to determine at which position you should rank in the search results when someone is searching for something related to that link. And links from popular sites, like Microsoft, are more important than links from less-known sites. So even though in might not first look like much with a tiny link, that link is actually really important. And I wouldn't have got the link if I hadn't shared my knowledge to you! Moreover, I didn't spend a single dollar on writing the article and I also learned a lot by writing the article.

August 31, 2016

Can you explain how to use PID controller to follow that path?

0 comments
I few months ago I wrote an article about the Hybrid A Star pathfinding algorithm for self-driving cars. It turned out to be a popular article, and someone asked in the comments section: "Can you explain how to use PID controller to follow that path?" And the answer is: yes I can!

PID controller is a technique to minimize an error you have. If you have a self-driving car, this error is the length of the difference between the car's actual position and the position it should have. This error is called Cross Track Error, or just CTE:


The math is simple and you just need a few lines of code to make it work, but the technique is not commonly known among those who haven't taken a course in control technology. I took a course in control technology, but I forgot about the PID controller, only to rediscover it last year when I took a course in self-driving cars.

The PID controller consists of three parts: the P, the I, and the D. I made a video to explain why you need the P and the D, and you only need the I in real-life if there's an error in the technology you have. There aren't many errors in the computer so you will not notice why you need the I in the video:


This was just a tiny introduction, but I've written an entire tutorial on how you can write your own PID controller in Unity (with C#): Minimize an error with a PID controller.