Why do escalator handrails move at different speed?

Did you notice that the handrails on escalators are moving at a different speed than the stairs? Well I did too and it bugged me enough to do the research on why is that happening.

There are many different theories around the interwebz to answer the question. One of the most popular one is saying that the slight speed difference is there on purpose to prevent the tired traveler from falling asleep / not paying attention and hurting themselves (basically to prevent lawsuits). I do refuse to believe that theory. My reasoning is simple: The same speed difference exists in Budapest’s metro system and I’m 100% sure they don’t give a rat’s ass about the safety of the travelers.

If you look at the picture above one thing is obvious. The distance that the handrail have to travel is longer than the distance the stairs need to do. Now imagine two circles (or ellipsis rather) that only have one touch point.

If you put a motor at that single point to spin both circles the speed of each circle will be very different. They will be approximately the same speed as you get closer to the touch point but will differ wildly when they are farther apart.

Now you can obviously modify this behavior by adding gears and essentially changing the speed each circle does on a per section basis, but surprisingly enough escalator manufacturers tend not to do that. Instead they have two motors running each thing.

And here is where the speed difference comes in: Turns out when an escalator is new both the handrail and the stairs are running at almost exactly the same speed. But since the handrail motor is doing more or less work it’s gears will degrade at a different rate and sooner or later the handrail will be slightly out of sync from the stairs.

Every day we learn something new (and useless)

Be Sociable, Share!

Writing my first iPhone app – Day 6 – Its all coming together

Finally managed to unpack everything after moving flats so no more boxes, yey! Unfortunately somehow managed to lose the box with my socks and underwear tho. Oh well, you win some you lose some. Anyway, had some time today to work on this app of mine.

First of all I wanted to pretty it up a little bit. I have no sense of style at all (don’t think any coder does) but I do not like working with anything too messy. So here are a couple of things I did to make me feel more comfortable:

I’ve reordered my tabs in my TabBarController to make the “Play” item to be in the center. For much of my surprise the storyboard editor doesn’t let me select the default tab. I realized that I have to extend the TabBarController. So after much research I found a code snippet that did the trick

I’ve also made the tab bar’s color scheme inverse so the above code takes care of the font colors as well. I also wanted to display a heading on all pages with a title so dragged in a Navigation Controller and connected it to my Tab Bar Controller. It displayed the heading placeholder but I couldn’t find a way in the storyboard editor to set the text for each tab element. Clever people of stack overflow said that i can set the title from the ViewDidAppear method of each controller. Here is an example of how:

Since I really don’t like the UIColor API (coming from web development background I think it’s understandable) I was looking for an easy to use alternative. Thats how i found UIColorExtension. Its a simple extension that allows me to use RGB(a) hex codes in my color definitions. So I can write stuff like this:

Winning (except for the 15 minutes it took me how to do # on a mac keyboard)

Also replaced my label that was used for the countdown with a Progress View. Progress View’s are really straight forward to use:

All right. I think I’m done with prettying stuff up. It is still ugly as fuck but bit easier on the eye:

Screen Shot 2015-06-14 at 15.49.32

I hooked it up with the question API I made in my previous post and it worked like a charm. Except one thing: Since the API was using random sometimes it gave me the same question twice. In order to avoid that I needed to log the user’s answers. So created a new table:

And a new class:

The PHP API has been modified a little as well to able to record answers + avoid sending the same question to the same user again:

Great, now the only thing left to do is to make the app send home the user’s answer for logging. In my PlayViewController I modified the logic that happens when the user clicks one of the answer buttons:

When the user hits the button it just checks against self.currentCorrectAnswer and depending on the result it sends home the questionId, userId and 0 or 1 for logging.

Finally I decided to make this project fully open source. Please feel free to fork / do a pull request / whatever, but keep in mind it is very much a work in progress and I have literally no idea what am I doing in Swift

Repo for the app | Repo for the PHP Api and scraper(s)

The game is actually playable now and it is moderately entertaining. Will need to find a new source of questions because the current ones are way too British.

What is next? The gameplay is pretty much ready now. It needs some refactoring and some security on the API but its ok for now. Next time I’m going to work on the leaderboard view. Deal with some TableViews in xcode and probably implement Facebook friend list somehow.

Be Sociable, Share!

Writing my first iPhone app – Day 5

Ok, I’m cheating a little bit here. I did not work on the app during the past two weeks or so but I have very good reasons. First of all I moved to a new flat (which I absolutely love btw) and as you know moving is hard. Secondly the Macbook I borrowed from work pretty much died under me. It kept presenting the so called “black screen of death” 9 out of 10 times I tried to boot. Tried to do all the PRAM resets and mental keyboard combos I could find online but no joy. Anyway, bought the new generation Macbook Pro now (force touch trackpad rulez btw) so I’m back in business.

That being said yesterday I only worked on the back-end of the app. In order to go forward with the actual iOS development I needed some questions and answers in my database so I decided to look around to find a site which I can scrape. I’m really surprised that there are no good quiz sites around with 4 answers for each question and the correct answer included. Found some databases for sale that would fit my needs but the sales page were either crappy or the database was ridiculously overpriced. The only site I could find that met all my requirements is PubQuizArea, which ticks all the boxes, however it is really British. Oh well, it should do for now.

First of all I need a table structure:

The model for this is written with my No-BS Framework. It does not need to modify the base model at all, just need to define the table fields and some validation rules (question needs to be unique:

The main part of the job is writing a simple scraper. Luckily the site’s structure is pretty well thought out so it makes it easy to scrape:

I know I know. Heard it million times: my scraping style is really old school. Guess what? I tried all those hipster libraries for scraping which promise you bells and whistles, none of those worked for me. Every once in a while they stop working and it is really hard to find the actual issue under the hood. As always I’m using my trusty curl class to fetch the data.

The script is just looping through the subpages of the category url from the command line argument and get the question / answer data from them. Luckily the correct answer is highlighted with a separate class (“blue”) so it is easy to recognize. $question->validate($db_data); takes care of removing dupes too.

That site gave me about ~1,800 questions. Obviously not enough, but will do for testing.

Last thing was to add an endpoint to my api. My __construct became:

And the implementation is:

Obviously this logic will change as I hook it up with the app (rand() doesn’t exactly prevents the user from getting the same question over and over again) but again, its ok for testing. If you fancy trying it out, click here

Be Sociable, Share!

Crappy Fizz-Buzz

Read this article today on HN about 5 alternatives for fizzbuzz for coding interviews. The last one was to write the worst fizzbuzz program you can come up with. It sounded like something i should do before my morning coffee so here is my entry:

Can you do worse?

PS: No movement on my iPhone app today since I decided to get drunk yesterday

Be Sociable, Share!

Writing my first iPhone app – Day 2

I have to say so far I’m liking Swift a lot. It is a nice, straight forward language with some awesome feature like conditionals.

Ok so what I did today? (well yesterday, but whatever)

First of all I added some new views to my interface. I realized that i will need to record the user’s activity on the server so I will need some sort of identifier to them. Of course I could just use the device’s ID but its better to make them create an account and use their login name / user id as the identifier. Anyway, I needed to add a login view as the first responder of my app. For now I will just add a simple button to redirect the flow to the “play” view, will deal with the actual registration later. Also added a new view to my tab controller for editing the user profile / view activity. Here is how my storyboard looks like at the moment:

Screen Shot 2015-05-23 at 21.12.25

The code for my LoginViewController is really just a placeholder now

loginOverride just redirects the user to my tabController where the game code kicks off.

Made some good progress with the game itself as well. Actually pretty much the whole game logic is done. I did set up a fake API for getting the questions. Here is the not so interesting PHP code

Turns out implementing async requests in Swift is fairly simple. Just have to call NSURLConnection.sendAsynchronousRequest and parse the response. 

One thing I’ve learned about this and it is very important: never ever (EVER) try to update UI elements directly from the async request’s callback because it won’t take effect. It took me like half an hour to recognize that my code in fact works, but the UI elements are not updated. Clever people on stackoverflow told me that I should use dispatch_async to with dispatch_get_main_queue() to tell the main execution thread to update the UI.

As for rendering the question, it is pretty straight forward:

I want to allow the user 30 seconds to answer each question. I really hoped that the SDK has some sort of built in timer object, otherwise I should have implemented my own recursive async thing which I really didn’t want to do. Fortunately the SDK in fact has an NSTimer class so implementing the countdown was easy:

The only thing left to do is to hook up the answer buttons and check if the answer is correct. I simply added a tag to each button 0,1,2,3 and linked the touch up event to a new custom action:

Simples. If the clicked button’s tag equals to the one got from the (fake) API display a big green message, otherwise a red one. In the future the app will report the result to the server for logging purposes and of course to move the player on the global board but that is for the future.

Tomorrow I’m gonna start building the server side a little bit and try to make the registration / login view and hopefully add Facebook login too

Be Sociable, Share!

Writing my first iPhone app – Day 1

So I decided to step a little bit out of my comfort zone professionally and try myself outside the scope of web development. I took a beginner course on Udemy about developing iPhone apps using Swift, but up until today I didn’t write a single line of Swift code. I hereby challenge myself to write my first app in 14 days. Now the app itself most probably won’t be ready for the app store straight away since I’m mostly focusing on functionality and not usability / design but it will be a good learning experience for me.

The app: The app will be a very simple game. Imagine a massive, 1 billion step board game with one single player. Everyone who is using the app will move the same player by answering trivia questions. If a given user answers the question correctly the player moves forward 1 step, otherwise it moves backwards one. I know, not the most original idea but it really is just for learning.

So here is what I did today (keep in mind I have literally no idea what I’m doing so probably I’m doing it all wrong)

I started off building a basic interface. What really surprised me, coming from web development, is how un-intuitive xcode’s interface (storyboard) builder is when it comes to “responsive” design. It took me ages to figure out how to make a single button stretch when I switch the emulator from iPhone 5s mode to iPhone 6. Basically you have to define the relative distance between the elements and the main view and the buttons will stretch to fill the space. I mean it kinda makes sense but how hard would it be for to allow defining sizes in %? Anyway my lame interface looks like this at the moment:

Screen Shot 2015-05-23 at 17.17.33

I know, it looks fugly but it renders properly in the simulator (still fugly but at least symmetric)

Screen Shot 2015-05-23 at 17.19.06

I can’t believe I spent like 3 hours on this, but at least I learnt something. Besides the interface I defined my outlets and set up a base controller which will handle my interaction with the (so far non-existent API) and update the interface elements as needed.

Screen Shot 2015-05-23 at 17.22.55

It really is a frustrating yet very fulfilling experience to code for iOS. I mean it is one thing to switch from PHP to Python but it is completely different when you are switching from web dev to desktop / mobile dev. I think the last time I had to deal with pointers and complex types was when I was like 14 coding in Borland Pascal.

Tomorrow I’m gonna hook up my class with a stub API and do some actual work on the logic. Will keep you posted (not like anyone is reading this)

Be Sociable, Share!

That perfect ding

If I would ask you to think about the most used app on your phone and recall it’s most defining characteristic I guess most people would think about the icon or the app’s color scheme. But I do think that the most important feature of an application is the noise it makes.

When the Facebook app makes that “ding” noise it triggers and almost emotional reaction and excitement. Next time you are travelling by bus and hear that sound just look at the people. Guarantee you that more than a few of them will reach to their pockets with a hopeful expression on their face hoping they are the chosen one who got the message. Literally a pavlovian reflex. I think this is the reason why most of the popular apps are using custom sounds. Instant and free viral marketing.

Now, I never worked in the app business and definitely never worked for a multi billion dollar business like Facebook but I’m really interested in what kind of research these companies do to decide on the sounds.

  • Is it a single person who decides or is it a team?
  • How the hell those brainstorming meetings go? (“hey i have an idea. how about a swooshy noise?”, “don’t be ridiculous, that will never work. i think it should be more like a badabum sound”)
  • Are they using psychiatrists to maximize the viral effect?
  • Do they user test the noises with focus groups? (must be the weirdest temp job ever)

If you work for an app company please comment because I’m really interested.

PS: If you frequently use mass transportation please have the curtesy of muting your phone. It’s nice and all that you have a life but your Facebook app is giving us the false hope of someone thinking about us for a few seconds, and that constant disappointment is not a good way to start a day.

Be Sociable, Share!

Dear eBay, it’s 2014

<tldr> both eBay and PayPal should implement MANDATORY 2-step auth to protect both their buyers and sellers.</tldr>

I’ve never been a big fan of PayPal. The first ever decent money I made online was frozen by them and I never managed to recover the funds. It is the single worst payment system when it comes to sell digital goods. No matter what happens they always favor the buyer.

It is kind of OK when you sell software or ebooks:

  • When someone asks for an (un-rightful) refund for your software it sucks, but you don’t actually lose money. Also you can cancel the software’s license, if you have proper licensing
  • There are plenty of alternatives to process payments
  • You don’t have to rely on eBay’s buying power, you can just sell on your site or other marketplaces

But it sucks balls when it comes to sell products which you can’t recover after the transaction.

A couple of week ago I came up with a pretty profitable way to make money on eBay. I started selling voucher codes from cex.io. CEX is a cloud mining platform where you can buy hasing power to mine Bitcoin. You can only buy the hashing power with Bitcoin itself and Bitcoin is still fairly hard to aquire. So I was like what the hell, let’s buy a lot for cheap and try selling it on eBay for more. It is not against CEX’s nor eBay’s policy to sell such item.

And it worked. I had days where I made over £500 profit with very little effort. Nice passive income.

Then the kaka hit the fan. A bunch of “Unauthorized transaction” claims started coming in and PayPal always refunded the money to the buyers. Of course I had no way to recover my vouchers. Money down the drain.

Even at the beginning I was trying to be careful. Compared the buyer’s eBay details with their PayPal details and sent the codes to the PayPal email address. So a potential scammer should have access to all 3 accounts (eBay, PayPal, email). But its apparently wasn’t enough. It is kind of annoying that PayPal actually favors the buyer who is stupid enough to get 3 of their accounts hacked against the seller who did everything (almost) in his power to protect against scam, but that is a different story.

Since then I improved my verification method. I still do my email verification but I added 2 new ways of verification which my customers can choose from:

  1. Ask my customer for their Facebook account, if it’s match the name and the city of the PayPal details and it is relatively active I send the voucher as a Facebook message.
  2. While browsing the (surprisingly good) eBay knowledge base, I found an interesting link. This forms allows sellers to ask for the customers contact details. And guess what? eBay requires phone number on sign up. And that phone number is really hard to change. A 4 digit pin sent to the phone number and all is verified. Easy.

Well, it is not that simple. Turns out lots of people uses landline numbers for eBay so I have to call them up and ask them if they made the transaction or not. Since about 3 out of 5 times it is a hacked account this phone call takes ages. About an hour ago I had a 15 minutes conversation with a technologically impaired women explaining to her why she should use different passwords for all her accounts, and why should she change her password right now. Sigh.

So dear eBay (and PayPal): You are a billion dollar company dealing with millions and millions of transactions. Why? Why the hell aren’t you implementing a mandatory 2 step auth system? Would it so bad if both your sellers and buyers were happy and make transactions without any doubt that the person they are dealing with is legit? Would it be so bad to re-train the people in your payment review team to do something actually useful instead of clicking the “refund” button mindlessly?

</rant>

Be Sociable, Share!