Category Archives: Uncategorized

Some ESLint rules to better your React code

ESLint is a tool for analyzing your JavaScript code and finding potential problems. A couple months ago I taught myself how to create plugins for it so I could write my own linting rules. I wound up writing two rules, both of which I’ll go into below.

prefer-use-state-lazy-initialization

React has a neat optimization trick for its useState hooks. When doing something like this:

const [data, setData] = useState(expensiveFunctionCall());

You’ll wind up calling expensiveFunctionCall on every render, when all you really wanted was to call it on the first render. To resolve this, React allows you to pass an initializer function to useState rather than an actual value:

const [data, setData] = useState(() => expensiveFunctionCall());

Now expensiveFunctionCall will only be called on the first render.

I was honestly pretty surprised that you could do this, and it’s such a neat little trick that I thought there should be a linting rule that would detect function calls in useState and alert you to using this optimization… and that’s what this rule does. If you’re not taking advantage of this trick, it’ll alert you so that you can change your code to do so.

I thought the rule was cool enough to submit to the React team, but it’s been languishing for months in their PR queue so I don’t see it getting added to their set of eslint rules.

no-named-useeffect-functions

There are a lot of coding tips out there, and not all of them are good. One such tip is naming useEffect functions. On the surface this might seem harmless, but it bloats the code, puts naming any kind of callback into question (for consistently), and is just in general pretty obnoxious. Now you may not agree with me, but if you do and want a rule to find such cases, well, this is that rule.

Only 2?

Yeah, for now at least. 

Is it easy to write these things?

If you’ve ever wondered about how to write your own eslint rule, just check out the project for the rules above. They’re surprisingly easy to write. Once you have the basic boiler plate down, all you really need is an AST Explorer and you can write them pretty quickly (this generator is also pretty useful).

New patrickgillespie.com

2021 Update: I’ve since re-done the site again, when I get a chance I’ll write something up on it. The post below refers to an older design.

***

Another redesign, this time a good one, I swear! I decided to learn ReactJS, and for my first project I redesigned my photography website, patrickgillespie.com

My previous design was pretty bad, I guess no one had the heart to tell me. For this new one I studied several other designs and took elements I thought worked best. It’s simple, responsive, and the code is up on github if anyone is looking for a portfolio template.

patrickgillespie.com had been pretty dead for about a year, receiving an average of 2-3 visitors a week, probably bots. The domain was about to expire earlier this month, when I noticed a big uptick in visitors leading up to the expiration day (~20 a day). Were these other Patrick Gillespies eyeing the domain? Domain vultures looking to scoop up a site that was about to fall into the abyss? I guess I’ll never know.

patorjk.com, on the other hand, has been alive and kicking, at least visitor wise. No one reads this blog, but the apps on the site see hundreds or thousands of visitors a day, making me feel sort of bad about neglecting the site. It’s like a rudderless ship that has somehow managed to successfully sail the ocean.

Anyway, if you’re reading this, I hope you enjoy the new portfolio site or at least find some use in the code. The most useful piece of it is probably the create-image.js script, which creates multiple sizes of a photo and extracts it’s exif data into a JavaScript object which the application can use.

McDonald’s 2014 Monopoly Game Odds Analysed

McDonald’s is running their annual Monopoly Game until the end of the month. The highest prize is $1,000,000 – which goes to the lucky soul who’s able to find the coveted Boardwalk stamp amongst the 651,841,628 game pieces. That equates to every person in the US eating 2 Big Macs before the prize is guaranteed to be given out. Even the odds of winning the Powerball jackpot are higher (1 in 175,223,510), and its minimum jackpot is $40 million.

Our brains aren’t really wired to intuitively grasp probabilities, and the marketing departments of big companies know this. With McDonald’s eclectic mix of a hand full of large prizes and a ton of small prizes, it’s clear they’ve put some serious research into what will get customers through their doors. And it works. Hell, the only time of year I eat at McDonald’s is when they run this contest – though I always sort of regret it later. It’s a fun contest, but I think knowing the odds gives you a more clear picture of what to expect.

The Basics

  • There are 651,841,628 game pieces in play. Each game piece contains 2 stamps.
  • 156,210,425 prizes will be given out.
  • The prizes falls into 4 categories: food prizes, instant wins, online prizes, and monopoly prizes. See the below table for a statistical breakdown.
Prize Category Number of Prizes Odds of Winning
Food 128,769,022 19.75%
Instant Win 25,780,151 3.95%
Online 1,661,242 ??? (see below)
Monopoly 1,359 0.0002084862245%

Chance of Winning Illusion

There might be some interesting psychology going on with how the game is played. Each game piece is 2 stamps, making you feel like you have 2 chances to win. However, the official rules only talk about the odds of game pieces, not stamps. This makes me wonder if only the game pieces matter, which would mean that at least one stamp on a game piece is always a loser. This would mean that half of the stamps you peel are just there for psychological effect of playing the game. You end up feeling like you have twice as many chances to win, when in reality, its just an illusion.

Unfortunately it’s hard to confirm this hypothesis. If the odds of a game piece winning are 25%*, then each stamp should have an individual winning probability of 13.4%**. This means the odds of both stamps winning on a game piece are 1.8%***. This means you’d need a really large same set to confirm that both pieces can’t win. I have around 56 stamps from friends and family, none of which were double winners – but that doesn’t mean much, since the odds of getting a double winner with 28 game pieces is only 40% (1 – 0.982^28). To be over 99% certain that double winning pieces don’t exist, you’d need to peel at least 254 game pieces.

This is just a theory though, and it could all be easily disproven if a double winning stamp shows up. This should happen 1.8% of the time, so if you’re really hungry you can test this out.

* The rules claim you have a 1 in 4 (25%) chance of being a winner. However, this number is rounded. If you add up the number of prizes and compare it with the number of pieces, you see that the number is closer to 24%.

** I worked backwards for this number by finding the probability of both stamps not winning: (1 – 0.134) * (1 – 0.134) = ~75%

*** Both stamps winning would have a probability of 0.134 * 0.134 = ~1.8

Odds for Rare Pieces

I’ve seen some sites structure their odds around finding a complete monopoly, but that’s just silly. There are only two types of pieces: rare ones, and ones that show up all of the time. If you find one of the rare pieces, you’ve basically won the prize.

Stamp Odds Prize Number Available
Mediterranean Avenue 1 in 651,842 $50 1000
Vermont Avenue 1 in 144,583,163* Free Gas for a Year ($2,350 ARV) 4
Tennessee Avenue 1 in 2,429,970 Mobile Wallet Prize ($3,150 ARV) 238
Virginia Avenue 1 in 690,723,394 $5,000 5
Short Line 1 in 57,833,265 $5,000 Target Shopping Experience 10
Ventnor Avenue 1 in 8,691,222 Beach Resort Vacation ($6,500 ARV) 75
Kentucky Avenue 1 in 32,592,082 Delta Vacation ($7,500 ARV) 20
Water Works 1 in 162,960,407 $10,000 4
Pennsylvania Avenue 1 in 1,686,343,601 Cessna Private Jet Trip ($16,900 ARV) 2
Boardwalk 1 in 651,841,628** $1,000,000 1

What do these odds mean? The best analogy I found was on a page for grasping large numbers. It gave the following example of how big 100,000,000 was: if you stacked 100,000,000 one dollar bills on-top of each other, they would reach 6.79 miles into the sky. That’s high enough to touch an airplane at cruising altitude.

* These odds appear to be wrong, as they differ from Water Works which also only has 4 stamps available. However, this is what the rules page lists.

** The Boardwalk odds come from the rule page, however, the winning stamp is apparently guaranteed to be on a Big Mac. If you focus your energy on eating Big Macs, this means your odds of winning are 1 in 37,955,000.

Online Game

Not much has been written about the online game, there are two main reasons for this:

  • There are no set odds. This is because the chances of winning are based on how many people decide to play their pieces online.
  • The prizes are very “meh”. Most of the 1,661,242 prizes are Red Box Rentals (1,400,000) and My Coke Rewards Points (250,000). However, there are a few decent prizes, and there is a top prize of $50,000.

Your odds of winning the $50,000 prize are the number of stamp codes you submit to the total number stamp codes submitted. Based on the 56 game stamps I’ve entered in, 3 were red box rentals. Extrapolating that out, the red box rental odds could be 1 in 20, which would mean McDonald’s expects 28,000,000 stamps to be entered in. This would mean your chance of winning the 50k per game piece would be 1 in 14,000,000. Now, 3 data points is too small a data set to make this assumption, so this should be thought of as just a back of the envelop calculation.

However, assuming these odds were true, that would mean if you spent the next week buying Hash Browns and entering in the max number of stamps a day (10), you could bring your odds of winning the 50k up to 1 in 400,000. This seems like a neat idea until you consider that if you spent the same amount of cash ($35) on Maryland Monopoly Lotto tickets, you would have a 1 in 385,031 chance of winning twice as much.

Food Items with Stamps

For those interested, Hash Browns have the best price to stamp ratio.

Name Price # Stamps Price Per Stamp
Bacon Clubhouse $4.69 2 $2.35
Big Mac $3.99 2 $2.00
Egg McMuffin $2.79 2 $1.40
Egg White Delight McMuffin $2.79 2 $1.40
Fruit & Maple Oatmeal $1.99 2 $1.00
Filet-O-Fish $3.49 2 $1.75
Hash Browns $1.00 2 $0.50
Large Fries $2.19 4 $1.10
Medium Fountain Drinks $2.49 2 $1.25
Medium or Large Hot McCafe Drink $2.59 – $3.39 2 $1.30 – $1.70
Premium McWrap $3.99 2 $2.00
Sausage McMuffin with Egg $2.79 2 $1.40
10-piece McNuggets $4.29 2 $2.15
20-piece McNuggets $4.99 4 $1.25

For legal reasons, McDonalds also allows you to request free pieces through the mail. A couple of individuals tried this out by requesting 500 pieces and comparing the outcome to buying 500 hashbrowns. It’s neat as an experiment, but unless you’ve got a lot of free time, you’re best bet is just buying Hash Browns.

Conclusion

Unless you’re in the mood for McDonald’s, don’t make your lunch decision based on the Monopoly Game. If a game of chance is what you’re after, you’re better off playing the lottery. However, if you’re going to McDonald’s anyway, get an item with pieces, as the game does make their food experience a little more fun.

Une Bobine Review

phone
My wife’s phone

A couple weeks ago I was offered a review copy of an Une Bobine. The device looked kind of fun, so I decided to try it out.

Une Bobine is an iPhone charger, sync, and stand that’s made from a flexible metal cable. This cable can be bent and shaped to create unique setups. In the pic to the right you can see it twisted both into a practical stand and into a stand where I’m just seeing how high I can get the phone. The pluses for this device are that you can facetime without needing to hold onto the phone, that you can take time lapse photos, and that you can shape the cable so that it isn’t in your way.

The product made its original debut into the marketplace in 2012 after a very successful Kickstarter campaign. This success ended up breathing life into the small company behind the device, and since that time they’ve repeated this recipe by funding most, if not all, of their products through either kickstarter or indiegogo crowd sourcing campaigns. I mention this only since it’s kind of interesting – 10 years ago this kind of company probably wouldn’t have been able to exist.

Anyway, to give the product a thorough look I let my wife take it to work for a few weeks to see what she thought. It seemed pretty durable and she liked that the cable didn’t get in her way. It was also fun to play around with, making it sort of like an adult tech toy. The only negatives either of us could see with the product were that you couldn’t have your phone in its case while charging and that it was a little troublesome to use in the car. If you choose to use it in your car, you will want to test out your setup to make sure it wont fall over or get in the way of the radio.

Overall its a fun product. If you’re looking for a tech device to play around with, it’s something that can provide you some entertainment and utility while you’re at your computer. Lastly, the cable’s name is a little strange, but that’s because it’s French. Translated, “Une Bobine” simply means “a coil”.

Nomad ChargeKey Review

DSC_0082

I don’t normally do reviews of tech devices, but I was recently offered a review copy of Nomad’s ChargeKey, and since it seemed like a neat little device, I decided to check it out.

ChargeKey is a portable lightning cable that fits on a keychain. It comes in both a lightning (iPhone) and micro-usb format (Android / Windows Phone). The idea behind it is to allow people to always have a cable to plug-in to a USB port if they need to charge or sync their phone. If you use a laptop or have a keyboard with a USB port this is really convenient. The cord is also flexible, so technically you could also plug it into the a USB slot on the back of a desktop tower too.

Priced at $29, it costs $10 more (or 53% more) than a normal lightning cable from Apple. This means you’re basically paying $10 more for the added convenience of a short portable cable. That’s a little high, but not too bad.

One thing I’m not completely certain on is its durability. Their marketing material mentions that its made with “high grade plastics from Bayer”, but I wasn’t able to find any information on if it was water proof (so I assume its not). I also wonder about the long term wear and tear the device can take, though for something this new its probably too early to tell. After 3 weeks I haven’t encountered any problems though.

Other than that, there’s honestly not a whole lot to say. It’s a simple product that lives up to its expectations. If you think its something you’d like, I’d definitely recommend it.

Scaling Back Ads

I figured I’d announce that I’ve decided to scale back the ads on this web site. Something about putting ads on this blog has always felt a little odd to me. The extra revenue is nice, but I’m not sure its actually worth the commercialization ads bring.

There are still two ads on the site, the Google Custom Search box on this blog’s sidebar, and an ad on the Text Ascii Art Generator (TAAG). The search box is actually functionally useful and the ad on TAAG will still allow a little bit of change to trickle into the site. I don’t plan on adding any more ads until I need to upgrade hosting services.

Part of me wanted to justify my decision with the idea that “ads turn away visitors”, so I decided to make a chart pitting TAAG (which has an ad) and against the VB Array Tutorial (which doesn’t have any ads). Surprisingly, it appears that the ad on on TAAG didn’t have a noticeable negative impact on the number of visitors it received:

This might be like comparing apples to oranges, since both pages probably appeal to a different group of people. However, TAAG’s ad was added in April, so if it bothered visitors I’d expect its growth to go down after April, but instead it seems to have continued on with the normal growth of this site (the spike in June is due to it being popular on StumbleUpon for a few days). This doesn’t change my opinion on removing ads from the blog, I still feel they add an unwanted commercial element to a personal outlet, however, I figured I’d post up this chart for those of you interested in how ads may/may not effect site growth.

Live.com’s linkfromdomain Operator

Most people are pretty familiar with Google’s Advanced Search Operators. You can use them to more preciously search for web pages or particular data. Anyway, earlier today I discovered that Microsoft’s search engine, live.com, has an amusingly useful search operator that Google doesn’t have. It’s called linkfromdomain. Now, this isn’t new news. I did some Googling and the operator has been around since late 2006, however, since not very many people use live.com, I figured some of you might find this info useful.

The linkfromdomain operator allows you to search the websites that a particular website links to. For example, if you search for “linkfromdomain:patorjk.com“, you’d get a list of all of the sites I link to throughout this website. At first glance this may not seem that useful, however, it allows you to ask some interesting questions as an individual and as a webmaster. Here are some examples:

I don’t think Google currently has the ability to answer any of those questions, which is a little surprising. Anyway, there are probably lots of other neat questions you can form using the linkfromdomain operator. It’s definitely something to keep in mind when you’re surfing the web.

New Web App: Typing Speed Test

I figured a good companion for my Keyboard Layout Analyzer would be a Typing Speed Test. Right now the program is pretty bare bones, however, it does have a few neat configurable options. You can test your typing speed skills against typing words drawn from a database of the 978 most common English words or against words drawn from a database of the 1000 most common “SAT words”. You can also vary the time settings. You can type for 60 seconds or until you’ve finished typing a certain number of words.

In the next week or two I hope to add output stats about which fingers and keys were typed the fastest. I think I also want some more creative text inputs that a user can select from. Maybe programming code, text from popular books, and song lyrics. How fast you can type a given programming language probably isn’t that useful, but it might add to the fun factor. If you have any suggestions or comments about the app please let me know. It was written pretty hastily in my spare time during the past week, so it’s still a little wet behind the ears. However, I did test it in IE 6.0, IE 7.0, FireFox 3.0.3 and Opera 9.24, so it should work fine.

DoFollow WordPress Plug-in

As a way of saying thank you to people who comment and as a way to encourage more people to comment (as long as they don’t spam), I’ve installed the DoFollow WordPress plug-in. Basically, it makes it so linkjuice is passed onto the websites of people who comment. I will nofollow links of people who I think are being spammy, but I figured I’d be a nice/easy way of saying thanks to the people who do decide to say something.

Happy Halloween

Lastly, since the 31st is approaching…

My pumpkin is on the far left, it’s supposed to be two bats. I should probably stick to programming… it was a lot of fun though. If you have a few extra hours, it’s worth revisiting. For me, it’d been almost a decade since I’d carved a pumpkin.

A Round Up Of Updates

Listed below are some small updates that have happened over the last week.

  • The Color Fader now has a neat fade-in/fade-out interface. I figured this was more intuitive than telling the user to scroll down every time they hit the “generate” button.
  • The Keyboard Layout Analyzer now has information explaining what it is and contains a handy chart mapping fingers to keys.
  • I helped out Franz Tarr on a neat little VB app that lets you set the transparency of windows. It’s pretty simple and comes with its source code. I only helped out and didn’t write the app. Since Franz seemed like a cool guy I told him I’d mention his program in my next site update.

Somehow I felt like I did a little more than that, but that’s all that’s coming to mind right now. New stuff is being worked on, however, I’m not sure when it’ll be ready to be posted up.

Is Someone Pretending To Be You Online?

Hopefully I’m not making myself seem like too much of google fanboy, but the other day I found a neat little tool by them called Google Alerts. Google Alerts allows you to monitor search results for key phrases you input to it. When a new webpage gets indexed for that key phrase, and it ranks above a certain threshold, you get an email telling you about the webpage. Though you can schedule these emails to only come at certain intervals. The idea is that you can get the latest info on topics you’re interested in. I thought it sounded useful, so I signed up for a couple of key phrases.

This morning when I opened by email, I found an alert telling me about this website. When I clicked it I found someone with the username “patorjk” was asking a question about Excel. Below you can see a screen capture of the post, my mouse is hovering over “patorjk”‘s username in this shot.

At first I naively thought to myself “whoa, another patorjk, I wonder if its a married couple or something…” So I clicked the username to see the user’s profile. Lo and behold, the user’s profile stated that their name was “Patrick Gillespie” and that they were from Baltimore. What the hell!? The statistical odds of there being another Patrick Gillespie with the internet pseudonym “patorjk”, who lives near Baltimore and programs computers, are basically zero.

I should also note that I had only been awake for about 2 minutes at this point, so I was kind of groggy. At first I thought it had to be some kind of joke, like that fake presidential candidate video going around, but everything I looked at pointed to it being real. So then I wondered what the exact motive for this person was. Was it sinister? Was it that the person was just lazy? Did the person just latch onto my name for some reason (maybe they have a patorjk shrine in their room)? I couldn’t really tell from their posts, but I did notice that they started signing them with the name “Murali Krishna”. So maybe at some point they decided they wanted to be themselves again. patorjk.com doesn’t get massive amounts of traffic, so pretending to be me is really weird and makes me wonder about the mental state of the person. I’ll report the user to the website’s owner if they don’t voluntarily delete their account or change it so it doesn’t look like they’re trying to be me. However, I figured I’d give them a chance to do it themselves or to at least say their piece, since there may be a mix up of some kind somewhere.

Anyway, besides keeping up with the latest trends, it appears as if this tool can also clue you in on when weird stuff is happening regarding your name or website. Whether its someone talking about you or someone trying to pass themselves off as you – whether they’re trolling, trying to slander you or trying to steal your identity. If you run a website or have an online pseudonym, I’d recommend creating a Google Alert for them. And although this post has focused on the negative, most alerts will probably bring you positive news.

Sept. 2, 2009 Update: About a month after this post was made the site owner contacted me to figure out what was going on. We did a little detective work and discovered that the problem was due to some database issues he had when he moved his site. Apparently I had created an account for his forum around 7 months before making this post, but never made any posts (I probably created an account thinking I’d post something, but then forgot about the site). When he moved the site, some accounts ended up getting mapped incorrectly, and the “patorjk” account ended up being one of them. He had been fixing the accounts manually when people complained, but “Murali Krishna” didn’t come forward wondering about his old posts, so they remained under “patorjk”. When Google saw the newly updated posts had “patorjk” in them, it alerted me via its Google Alerts. So “Murali Krishna” isn’t an impostor, his posts are just the result of a database mix-up.

When what had happened had been figured out, I think the webmaster was kind of embarrassed, though he didn’t say much. I didn’t want to do a post saying “hey, look at this guy’s mistake”, so I figured I’d say what happened if someone asked me. However, this post still gets a little bit of traffic and the “Murali Krishna” posts are still under “patorjk”, so I figured I’d put a small little update in this post for those of you who are curious as to what happened afterwards.