Saturday, January 30, 2016

Hypothesis: bootstrap.min.css is a micro-optimization

Disclaimer: This is a random, untested idea that came into mind, and I just felt like writing about it.

Hypothesis: Bootstrap.min.css is a micro-optimization

As stated alot, premature optimizations are the root of all evil. Programmers suck at guessing where performance problems are going to be, and often spend alot of time optimizing spots that they think are going to be performance problems. I recently was reading a thread about an algorithm implementation (Mod 10 credit card number verification), and I saw people making optimizations and gloating with such nonsense as "I shaved 3 ms off the runtime!" (unstated: while making the code unreadable). I'm not talking down about other programmers, because I include myself in strange behavior. I often catch myself optimizing something when I haven't proven that it needs to be optimized. Why? BECAUSE IT'S FUN!

Ok, now that i've blabbed on and on about that crap that everyone has repeated over and over, I'll get down to the main idea here: Bootstrap.min.css is a micro-optimization.

If you don't know, Bootstrap.css is a CSS framework, and it's 143 kb. Someone came up with the idea of making a "minimized" version of this CSS file called Bootstrap.min.css. It removes all the whitespace and ends up being 121 kb (and becomes an unreadable nightmare, at least for humans). This means 22 kb won't be traveling from the webserver to the web browser.

In order to know if this 22 kb really makes that big of a difference, we have to look at the total size of the page being transmitted, and figure out how big of a savings % the 22 kb leads to.

According to this:, the average web page size is 2099 kb.

22 kb / 2099 kb = 1%

Ouch... that's basically nothing.

So what's taking up all that space? (again, according to that link above)

Images = 1310 kb / 2099 kb = 62.4%
Scripts = 329 kb / 2099 kb = 15.6%
Video = 227 kb / 2099 kb = 10.8%
HTML, CSS, Other combined = 5.8%

I've shown that bootstrap.min.css is a 1% savings. It's been suggested to use bootstrap.css during dev and bootstrap.min.css in production. Why bother? It makes the CSS file unreadable, and adds a bit of overhead, since you have to make sure you're using the right version in the right environment.

Instead, if you're trying to minimize the size of the payload transmitted to the browser, you're better off focusing on images. Most likely you are required to use all those images (because if the don't then the web designer will get really mad at you). So the only thing you can do is make the image size smaller. I can think of only one way to do that: come up with an image format that is super compressed. I'd leave that up to the researchers...

So that leaves us with scripts. Does each page really need 329 kb of javascript? Probably not. Most likely the page needs a small subset of the functions in the script files.

Let's say your page only uses 1 kb of the functionality in the 329 kb js file. You could make a copy of the 329 kb file and remove any functionality that's not used by your page. With a super simple page, that's easy. With a more complex website where templating is being used, or pages are generated dynamically on the server-side, you'd probably need a tool that loads all of your pages, exercising 100% of the website's functionality, and then builds a list of all the javascript functions used. From that list it could generate the minimized version of the js file you need. You'd need to update this anytime any page changes, and swap in the 329 kb version of the file during analysis.

From this contrived example, you'd save 328 kb. That's 15.6% of the total payload. That's pretty awesome. And this would lead to alot of overhead and most likely you'd create bugs.

In conclusion
Bootstrap.min.css is definitely a micro-optimization.

Saturday, January 23, 2016

PyCharm context menu says "run unittests for ..." when I have no unit tests

I have no unit tests and PyCharm is annoyingly saying "Run unittests for" in the context menu, instead of "Run"

I had two functions with the word "test" at the beginning, and PyCharm apparently uses that as a flag to determine what to say in the context menu. Not very charming. The solution was to change the name so that they didn't start with "test."

Friday, January 22, 2016

The function attempted to use a name that is reserved for use by another transaction.

When trying to add a Windows feature, I'm getting the error "The function attempted to use a name that is reserved for use by another transaction."

Turn off antivirus.

Note: I specifically have Avast Free Antivirus


Tuesday, January 12, 2016

Could not find an implementation of the query pattern for source type

Severity Code Description Project File Line
Error CS1936 Could not find an implementation of the query pattern for source type 'Table<MyTable>'.  'Select' not found.

You're probably missing "using System.Linq;" to the top of the file

Wednesday, January 6, 2016

Python - Number guessing game using binary search

I'm doing problems out of the 57 exercises for programmers book and ran into an interesting one. The objective is to have the program pick a random number between 1-n (where n is 10, 100, 1000 based on the difficulty level), and then the player picks numbers. The program reports if they need to go lower or higher. 

So I made the game and made a player that uses a binary search strategy. Pretty fun making this :)

The Code

import random import math class GuessGame(): CORRECT = 0 HIGHER = 1 LOWER = -1 def __init__(self, difficulty): self.difficulty = difficulty self.max = int(math.pow(10, difficulty)) self.number = random.randint(1, self.max) self.guesses = 0 def guess(self, guess): self.guesses += 1 if guess == self.number: return GuessGame.CORRECT elif guess < self.number: return GuessGame.HIGHER else: return GuessGame.LOWER def strategy_binarySearch(): MAX_GUESSES = 100 guessGame = GuessGame(3) ceiling = guessGame.max floor = 0 while guessGame.guesses < MAX_GUESSES: myGuess = (ceiling + floor)/2 print "Floor={0} Ceiling={1}. My guess is {2}".format(floor, ceiling, myGuess) result = guessGame.guess(myGuess) if result == GuessGame.CORRECT: print "I got it correct in {0} guesses".format(guessGame.guesses) return elif result == guessGame.HIGHER: print "The answer is higher" floor = myGuess else: print "The answer is lower" ceiling = myGuess print "" strategy_binarySearch()

Sunday, January 3, 2016

PyCharm - change the default project folder

1. Make sure PyCharm is closed

2. Navigate to the C:\Users\MyName\.PyCharm50\config\options\recentProjectDirectories.xml
(note: read this page to figure out where these settings are on the different OS's:

3. Modify
 <option name="lastProjectLocation" value="D:\Dropbox\Learning\FullStack\Python" />
and set the value= whatever your desired folder is

4. Save the file, then open PyCharm.