Wednesday, December 28, 2016

Using Lenovo ThinkPad USB 3.0 Dock on a Mac

The dock uses the DisplayLink driver to enable docking. The main dock product support page lists the DisplayLink windows driver but not the Mac driver. If you want your dock to work with Mac, you need to download the Mac driver directly from the DisplayLink website here.

Once it's installed, your computer should restart and your dock should work with your Mac!

PFTGU: Indexed addressing mode explained in more detail

"In the indexed addressing mode, the instruction contains an address to load the data from, and also specifies an index register to offset that address. For example, we could specify address 2002 and an index register. If the index register contains the number 4, the actual address the data is loaded from would be 2006. This way, if you have a set of numbers starting at location 2002, you can cycle between each of them using an index register."

Lets say we have the following numbers in memory: 10, 15, 20, 23. The size of a single unit of storage is a byte which can represent up to the number 255 (1 1 1 1 1 1 1 1 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255!). In this case, lets assume each number occupies a single byte of storage.

If 2006 is the location of the number 10, then 2007 is the address of 15 and 2008 is the address of 20. Using indexed addressing, if our instruction specifies the address 2002 and an index register with the value 4, we just need to increase the value in the register by 1 three more times to access all of our numbers!

"On x86 processors, you can also specify a multiplier for the index. This allows you to access memory a byte at a time or a word at a time (4 bytes). If you are accessing an entire word, your index will need to be multiplied by 4 to get the exact location of the fourth element from your address. For example, if you wanted to access the fourth byte from location 2002, you would load your index register with 3 (remember, we start counting at 0) and set the multiplier to 1 since you are going a byte at a time. This would get you location 2005. However, if you wanted to access the fourth word from location 2002, you would load your index register with 3 and set the multiplier to 4. This would load from location 2014 - the fourth word."

If our numbers didn't take up one byte, but instead took up four bytes of storage, then we can't just increase the index register by 1 every time. If the number 10 takes up four bytes and begins at address 2006, then it occupies addresses 2006, 2007, 2008, and 2009. Updating the index register by 1 if it starts at 2006 means it's still pointing at the part of memory being used by the number 10.

This is where the multiplier for the index is useful. Instead of saying, "move N bytes", we can now say, "move N*M bytes". In our case, M = 4 because there are 4 bytes in a word. Therefore, each time we up the value of N by 1, we jump one word instead of one byte. In this case, since our first word is at location 2002, our second word is 4 bytes away. Our index, however, is going to be 1 and not 2 because we start counting at 0 (the address 2002 already points directly at our first word with an index register of 0).

One reason why I believe that talent is overrated

In the middle of cleaning today, I found a stack of old SAT exam booklets and reports. I think I kept them back in high school because I had a rude awakening of how behind I was in every subject compared to my peers, and so I wanted to keep track of my performance on the test as I worked on improving my scores. 

I tabulated the scores I got on official PSAT/SAT tests between my freshman year and junior year: 


I was doing poorly in my classes during my freshman year and wasn't a very good test taker. "Talented" is not a word my peers or teachers would've used to describe me. More like lazy and spacey. But once I learned that I needed a decent score to get into a good college, I got to work. This leap in score was the result of very hard work, focus, and tremendous support from teachers, parents, and friends on the Internet (I'm looking at you, www.collegeconfidential.com).

A year after my last test, I received this letter:



It was one of the happiest moments of my life and every time I look at this I'm reminded that it's not always where you start, but how hard you work and who you work with that will dictate what can be accomplished.

Monday, December 26, 2016

Programming from the Ground Up - Chapter 2 (Computer Architecture)

Describe the fetch-execute cycle.

In the Von Neumman architecture of a computer, there is a central processing unit (CPU) and then there is memory. These are the two primary components that deals with computation. The CPU is further divided into several sub components:

  • Program counter
  • Instruction decoder
  • Data bus
  • Registries 
  • Arithmetic logic unit
The fetch-execute cycle of the CPU describes how the CPU processes instructions issued by programs. In the fetching part, the CPU looks at the program counter which is the location of the next instruction it needs to interpret and execute. It then fetches the instruction containing the operation to execute and the data, which is then decoded using the instruction decoder. If the instruction points to data with memory addresses, it goes and gets them using the data bus. Once it has all the data it needs to run the operation on, the operation is then executed by the arithmetic logic unit. 


What is a register? How would computation be more difficult without registers?

A register is a memory location that's on the CPU itself. The purpose of the registers is to store data that the CPU is currently working with. Kind of like the items that's currently on a work bench. Since it's on the CPU, the CPU is able to process information in the registers more quickly than if they were located elsewhere.

How do you represent numbers larger than 255?

A byte is the smallest unit of storage on most computers. A single byte represents eight bits. A single bit can represent two things. 2 ^ 8 = 256. Therefore, it can represent 256 things or the numbers 0 - 255. Those things can be numbers and if you want to represent a number bigger than 255, you must add another unit of storage, which is to say you must add another byte.

How big are the registers on the machines we will be using?

4 bytes or 32 bits or a "word". When we say that a computer has a 32 bit processor, it's referring to the size of the registers on the CPU.

How does a computer know how to interpret a given byte or set of bytes of memory?

It knows how to interpret it based on the instructions given to it by the program. The instructions issued by program A might tell the CPU to treat the byte of information as an address whereas another instruction by program B might tell it to treat it like an integer.

Put another way, you can have two bytes that are exactly the same but used completely differently. And it's in how they're used / interpreted that makes it useful. Having just raw numbers is not useful as far as we, the end users, are concerned.

What are the addressing modes and what are they used for?

They tell the CPU how to access data. Does it treat the byte as an address or as a number? In other words, does the data come with the instruction or does the instruction contain an address to the data that lives elsewhere?

  • Immediate
    • Data is in the instruction
  • Register addressing
    • Data is in the register specified in the instruction
  • Direct addressing
    • Address to the data
  • Indexed direct addressing
    • Address to the data and the register (AKA index register, a special purpose register) containing an offset number
  • Indirect addressing
    • A register containing a pointer to the data 
      • The pointer is not the data - it points to the data. So if the pointer is 2002, it will go to the location 2002 to fetch the data. The indirect part refers to the indirectness of the memory address - not to the data!
      • Pretty much any address in memory is a pointer. Whether that's an address in the register or an address in the instruction. 
  • Base pointer indirect addressing
    • A register container a pointer to the data and an offset number. Kind of like an indexed indirect addressing. Except instead of pointing to an index register, it includes the actual offset number in the instruction. 

What does the instruction pointer do?

Instruction pointer is a special purpose register than containers a pointer to an instruction.

Thursday, December 22, 2016

Brands Bird's Nest Drink, Yo

My mom recently bought my sister a case of birds nest drink. I remember drinking this when I was younger but I never questioned what it was. I was just told to drink it because it was good for me. I also knew that it was really expensive (~$10 per small bottle) so it's gotta be good right? This time I'm going to do a little bit of digging to figure out what the heck this drink is.

The main ingredients listed are:

  • Water
  • Rock Sugar
  • Dry Bird's Nest
  • Gellan Gum

The two unknown ingredients in this list are dry birds nest and gellan gum. So what are they? So turns out the dry birds nest is exactly what it sounds like. It's a birds nest. But what's with the word "dry"? Well, turns out - this is a special kind of birds nest that's not constructed out of mud, twigs, leaves or feathers. It's made of bird saliva. Yup. It's created by a bird called a swallow that uses its saliva to build a nest that eventually dries up and solidifies. If you look inside the drink, you'll see a bunch of semi-transparent, gelatinous substances floating around. Those are pieces of dried birds nest.

Gellan gum is a type of gum that's used as a stabilizer in this case. A stabilizer is an additive to food used to preserve its structure. In this case, I think it's dissolved in the drink to prevent the dry nests you see in the drink from settling at the bottom.

The company behind this drink, Brands, claims that this drink helps reduce "heatiness". Heatiness is a topic that seemed to come up all the time in my household that nobody could really explain. It's supposedly bad. French fries are heaty. Chicken wings are heaty. Chips are heaty. Apparently anything fried was heaty and heaty is bad. Anything that reduces heatinesss, like bird saliva, was good.

So what's this mysterious heatiness?

Some answers I came across:

Source #1:
"The heatiness and cooling effect of foods refer to their capacity to generate sensations - either hot or cold in our body. They do not refer to the state of the food but its effect on our bodies. For example, tea is a cooling food. This means that it generates cold energy in our body." - http://www.benefits-of-honey.com/heaty.html
Source #2:
“Heatiness” and its opposite, “coldness” (not “cooling”, which is actually a traditional Chinese medicine treatment method), is a classification system that describe the factors that cause certain types of illnesses, says Lau Kiew Teck, a TCM practitioner at Raffles Chinese Medicine. 
And those factors can be food- or weather-related. For example, durians and chocolates are considered “heaty” foods because they possess factors that cause ailments that are associated with excessive “heatiness”, such cough with sticky phlegm, chapped lips and mouth ulcers. " - http://www.menshealth.com.sg/health/what-do-heaty-and-cooling-tcm-really-mean
Source #3:
characteristic of certain foods or stimulants said to cause emotional or physical reactions associated with temper, fever, passion, excess, or true heat. Editorial Note: From Chinese culture and medicine.  - https://www.waywordradio.org/heatiness/
Source #4 (most accurate):
a female gangsta; causes jealous bitches to hate because they're bitch ass cunt motherfuckers. - http://www.urbandictionary.com/define.php?term=heaty
Most of the answers I came across seem to agree that heatiness is not so much about the actual heat quality of the food (whether it's actually hot or cold) than it is about the effects of the food. In traditional chinese medicine, the consumption of a food that are likely to cause certain effects or symptoms such as mouth ulcers or yellow urine are considered "heaty". From what I've read so far, it's not clear whether or not there's consensus within TCM about what symptoms associated with heatiness are and the types of foods that cause them. I'd also be curious to know how that attribution is established. Like, is it scienced or nah?

Sunday, December 18, 2016

Rails active record migration commands I just learned!

I've been working on a side project in the last two days that's build on rails and it's been a great learning experience. Today I dealt mostly with active record migrations. Here are some that I had to use!

Adding a new table and model


> rails g model critic name:string

g is alias for generate. This command will create a model called Critic, a corresponding test, and a migration file with code for creating a new table called critics with a field named string that accepts string data types.

Adding a new table


> rails g migration CreateCritics name:string

Unlike the command above, this will only create a table.

Changing existing columns


> rails g migration ChangePosterImgSrc

This will allow you to apply any changes to columns in an existing table.

Adding new columns


Reference type

> rails g migration AddCriticToReviews critic:references
or
> rails g migration AddCriticToReviews critic:belongs_to

These also create migrations that use the change method. The only difference is that they go one step further by generating the actual addition syntax for you as well. This will generate a migration that will add a foreign key reference called critic_id to the reviews table, establishing a one to many relationship between critics and reviews.

String type

> rails g migration AddPosterImgSrcToMovies poster_img_src:string

Same as adding a reference field. Except thing time we specify a string type for the field we want to add.

Running specific migration


> rails db:migrate:up VERSION=<version_number>
> rails db:migrate:down VERSION=<version_number>

Sunday, December 4, 2016

Basic Sublime Selection Shortcuts

Here's are a few basic selection shortcuts that I think every sublime user should know.

Select characters
SHIFT + LEFT / RIGHT / TOP / DOWN

Useful if you want to be much more specific about what you want to select. For example, maybe you want to cut out half of a word so you'll go to the beginning of the word and use SHIFT + LEFT to highlight up to the character that marks the end of the text you want to delete.

Select word
CMD + D (repeat to select more instances)

Convenient shortcut for not having to do SHIFT + RIGHT / LEFT multiple times if you just want the whole word.

Select all instances of word in file
CMD + CTRL + G

Very useful for finding where a variable is referenced. Also useful if you want to do a name refactor of a variable in the current file.

Select line
CMD + L

I usually use this when I want to delete or comment out an entire line of code.

Select everything inside current parenthesis
CTRL + SHIFT + M

Very useful if you need to copy or modify the parameters of a function.

Select everything inside file
CMD + A

Delete and start over!

De-selection: UNDO
CMD + U to de-select the most recently selected

Sometimes you'll accidentally select more than you wanted!

Saved $100 on my internet plan with TWC

Thirty minutes ago I was paying $50 dollars for 30 mbps internet. After one phone call, I'm now paying $40 dollars for 100 mbps internet. With a single phone call, I just saved $100 a year. Check out this awesome post on how to do it.

Your main goal is to reach the customer retention department of TWC and get a deal that's comparable to what they offer new customers. The most efficient way to do this is to dial their customer support number and note "cancel service" as the reason for your call. If you make the mistake of saying "billing" like I did the first time I called, you end up talking to a representative in the billing department and they'll be far less sympathetic to your demands. Even if you manage to break through, they'll still end up transferred you to the retention center anyway.

Friday, December 2, 2016

Key Dates in Trumps Rise to becoming President Elect

Our current president elect is Donald J. Trump. He will officially be president in a few months on Inauguration day. How did he get here? Lets look at some key dates and events in his campaign run starting at the present and working backwards in time.

Nov 9, 2016: Trump first post-election tweet

Nov 8, 2016: Trump wins the general election and becomes president elect

During the general election voters all around the country casted their ballots for one of five presidential candidates. One candidate, Evan McMullin, ran as an independent. In the end, Trump won with 306 electoral votes (though an ongoing recount initiated by the Green Party candidate Jill Stein might change this).

Jul 20, 2016: Trump becomes the republican party's nominee for president and Pence becomes the parties nominee for vice president

Delegates at the convention voted for one of seven republican candidates. The delegates are elected through primary elections or caucuses in their respective states. A candidate needed a majority of 1,237 votes to win and Trump won with 1,725 votes in the first ballot. Texas senator Ted Cruz came in second with 484 votes although he had already dropped out of the race a month earlier.

May 3, 2016: Trump becomes the presumptive republican presidential nominee after winning the republican primary in Indiana

Indiana holds open primaries and follows a winner-take-all rule for awarding delegates to winners of the primary. Trump won the primary with a popular vote of 53.3% and this win in Indiana caused Ted Cruz (his main competitor) to drop out of the race. At this point, Trump was on track to possibly becoming the second person who has never held an elected office position to serve as president since Eisenhower.

Apr 14, 2016: Indiana GOP names 57 delegates to the National Convention

The republican party in Indiana followed the following rules: 30 delegates must vote for the winner of the primary in the first ballot. 27 must vote for the winner of their congressional districts. After the first ballot, they are free to vote for whomever they want. Since a number of these delegates in Indiana did not support trump, had trump failed to clinch the nomination in the first ballot, he may have seen his support go the other way.

June 16, 2016: Trump announces that he will run for president as a republican candidate

Of course, it was also kicked off with a tweet.