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.

Sunday, November 13, 2016

Why does PGP use both symmetric and asymmetric key cryptography?

When I first learned about PGP, I was confused as to how using both encryption methods added security. In PGP, the public keys are exchanged between two parties to encrypt a session key used to encrypt data instead of encrypting the actual data. So when the receiver gets the encrypted content, they will use their private key to decrypt the encrypted session key which can then be used to decrypt the message.

This seemed like an indirect approach to encrypting the message that only added time, not more security. Turns out, the reason both methods are primarily because the current asymmetric cryptosystem, RSA, is a very slow algorithm.

"RSA is a relatively slow algorithm, and because of this it is less commonly used to directly encrypt user data. More often, RSA passes encrypted shared keys for symmetric key cryptography which in turn can perform bulk encryption-decryption operations at much higher speed." (Wikipedia)

Wednesday, November 9, 2016

How PGP works in 5 minutes

To understand how PGP works at a high level, you need to understand two key methods of cryptography:
  • Symmetric key cryptography
  • Asymmetric key cryptography (public key cryptography)
Symmetric key cryptography is analogous to two parties using the same key to lock and unlock a box containing secret contents. It's symmetric because the keys used to lock and unlock are identical. In a an exchange using symmetric key cryptography, Bob encrypts data using key A and sends it over to Alice who decrypts it using key A. Anyone who possesses key A can decrypt the data.

Asymmetric key cryptography is when two parties use a pair of different keys to lock and unlock a box containing secret contents. One key to lock, the other one to unlock. One is known as the public key (shared with senders) and the other the private key (guarded by receiver). They're asymmetric because the locking key is not the same as the unlocking key. In an exchange using asymmetric key cryptography, Bob shares his public key with Alice and Alice uses the public key to encrypt the data. Alice sends the data to Bob and he decrypts it using his private key. Since Bob is the only person with the private key, only he can decrypt the data. The public key is like a mailbox you can give to anyone where anyone can put messages in but the only person who can take messages out is the owner of the mailbox. 

PGP combines both methods to allow for secure communication. Basically, it uses public key cryptography to encrypt a randomly generated temporary session key which is also used to encrypt data. 

Here's how it works:
  1. Bob shares his public PGP key with Alice.
  2. Alice wants to send a message and generates a random session key. 
  3. Alice uses the session key to encrypt her message.
  4. Alice encrypts the session key itself using Bob's public key so that the session key can be sent securely with the encrypted data.
  5. Bob receives the encrypted data and the encrypted session key.
  6. Bob decrypts the session key. 
  7. Bob uses the decrypted session key to decrypt the data.

Why public key cryptography works in 150 characters

"Can the reader say what two numbers multiplied together will produce the number 8616460799? I think it unlikely that anyone but myself will ever know."
                                                                           - The Principles of ScienceWilliam Stanley Jevons

What's the difference between AWS IAM Roles and Security Groups?

What do they have in common? They're both access control methods.

IAM Roles

IAM roles can be assumed by any AWS resource or service on AWS and the policies attached to the roles determine their level of access to various other resources and services. Each role can have many policies. You can either use built in roles with default policies or create ones yourself.

For example, if you configure an ECS service to use a load balancer, the service can use a built in role called ecsServiceRole which has the policy AmazonEC2ContainerServiceRole attached which allows it to makes calls to the Elastic Load Balancer API. You can also create your own role with that policy. What grants the access is not the role, but rather the policies associated with that role. EC2 instances used for running docker containers require a role with the policy AmazonEC2ContainerServiceforEC2Role to make calls to the ECS API. Likewise, there's a default one with the policy you need called ecsInstanceRole but you can also create a new role called myRole and attach the same policy.

Security Groups

Security Groups controls network traffic to EC2 instances. An EC2 instance can have multiple security groups, and each group can have a number of rules specifying what inbound and outbound network traffic are allowed. For example, you can restrict access to port 80 for your instance to requests coming from a particular IP address range.

When you're using AWS, you're almost always using both of these access control methods. Any cloud stack you create will require you to think about the flow of traffic that you should allow to your compute instances (Security Groups) and what other AWS resources and API's those instances need to be able to talk to (IAM roles).



Friday, November 4, 2016

Setting up Amazon EC2 Container Service (ECS)

I've been experimenting with deploying containers to the AWS cloud. There's a really detailed guide on the AWS site that they provide on running containers using their container service, ECS. Yesterday I successfully deploy a couple of containers running a simple ruby Sinatra app! Here's a high level view of what you'll need to do in order to get your containers running.
  1. Create an AWS account 
  2. Sign up for AWS ECS
  3. Create a private docker image repository on ECS
  4. Build and push your docker image to your ECS image repository
  5. Create a task definition using your docker image
  6. Create a cluster
  7. Create an EC2 instance using an ECS-optimized image and register it with your cluster
  8. Create an elastic load balancer (ELB)
  9. Create a container service in your cluster and configure it to use your ELB
By the end, you will be able to visit the public DNS of your ELB which will forward requests to one of the containers you have running inside an EC2 instance. Most of the work lies in the configuration and a lot of that is not fun. I'm trying to reduce the job of deploying containers down to:
  1. Build and push your docker image to your ECS image repository
Everything else will be done automatically based on default configuration. I should be able to just visit a URL and see my running application. Adding more layers of the stack to it will take more work, but just running containers using a single image should be as easy as that.

Some questions I still have are:
  • What's the easiest way to deploy new images for an application to ECS? Ideally I just have to hit push and then the existing containers are replaced by new containers running my new image.
  • How do IAM roles and security groups work? 
  • How do I know requests are actually being distributed evenly by the ELB?
  • How should I stop my running containers? Do I stop it via the service level or the container level?
  • What happens to my containers if I shut down my EC2 instances?
  • Where are my logs located? If my app crashes, where do I look? 
  • How do I connect my app running in a container to another app running in a different container? Say, a database server for instance. 

Tuesday, November 1, 2016

Seasoning a Cast Iron

I bought a seasoned cast iron skillet about six months ago and now it's completely rusty. So I looked up how to re-season my cast iron.
  1. Preheat oven to 325 degrees.
  2. Wash cast iron with stiff brush or sponge. Make sure it's dry and clean.
  3. Apply a thin layer vegetable oil or shortening inside and outside of the cast iron.
  4. Put aluminum in the bottom rack to catch dripping oil and place the cast iron face down in the center rack.
  5. Close the oven and wait for an hour. Bake!
  6. Let it cool for another hour and remove!
There's some debate over the ideal ingredient to use for step 3 to maximize the non-stick property of the cast iron. According to these two articles, flaxseed oil is king:
  • http://sherylcanter.com/wordpress/2010/01/a-science-based-technique-for-seasoning-cast-iron/
  • http://www.thekitchn.com/i-seasoned-my-cast-iron-pan-with-flaxseed-oil-and-heres-what-happened-224612
Since this is my first time reasoning the cast iron, I'm just going to start with whatever works. I'm going to use canola oil and if that turns out to be a bad choice, I'll look into flaxseed. 

Friday, October 28, 2016

Write your Try-Catch-Finally Statement First

In Clean Code, Uncle Bob give the following advice:

Write your Try-Catch-Finally Statement First

Why?
"... it is good practice to start with a try-catch-finally statement when you are writing code that could throw exceptions. This helps you define what the user of that code should expect, no matter what goes wrong with the code that is executed in the try."
I like this because by following this advice, you'll have to start by writing unit tests that handle exceptions for code where exceptions are expected to be thrown. And then you'll have to write the exception handling code which will force you to think about how you may want to handle the error case. In Uncle Bob's words, you'll have to "define what the user of that code should expect".

This is useful from a development efficiency standpoint because if you expect an error, then by writing the test case for when that error is thrown, you can write the code for the Try block with confidence. You know that even if something goes wrong, it will be handled and the current function will execute to its completion.

If you don't do this, then you'll write a unit test case for code that might just blow up your program and crash spectacularly. Then what? You're finally forced to heed the advice of writing the Try-Catch-Finally statement and realize that maybe you should've done that first.

Monday, October 24, 2016

Abstraction Layers

An important skill that I think every developer should have if they want to write cleaner code is to understand what abstraction layers are and when abstraction layers are being mixed in code. 

What do I mean by abstraction layers?
"In computing, an abstraction layer or abstraction level is a way of hiding the implementation details of a particular set of functionality, allowing the separation of concerns to facilitate interoperability and platform independence." (Wikipedia)
Computers don't define abstraction layers for you. Programmers do. When you're dealing with an interface of some sort - whether it's a function or some web API, whatever details that exist behind that interface is essentially a different layer or level of abstraction because those details are hidden from you. One layer (in this case, the layer that your program resides in) is concerned with the what and the other layer (the one that's behind an API) is concerned with the how.

Programmers defines those interfaces that separate abstraction layers. They decide what the public sees. Not only that, but internally they must also decide what every part of the system sees - how the individual units interact with each other - and carve out the layers of abstraction that exist within the system. Those decisions are really important. Good abstractions are easy to understand. Bad abstractions are confusing. This is why using clear and descriptive names are important for writing a maintainable program.

This post isn't about how to pick good abstractions using techniques like writing descriptive names, however. It's about why it's so important to be able to recognize when abstraction layers are being mixed. Why? Because in any program, even if the names are sound, it's still a mess if the names of things that belong in different abstraction layers are mixed!

What do I mean by mixed abstraction layers?

Abstraction layers separate the what from the how. When the what and the how are mixed, abstraction layers are mixed. You see this most often in "god" functions. They do everything. Everything exists on the same plane.

Why is this a problem?

As someone reading the program, you're forced to wrangle with details that you may not care about. Here's a good real world example: say you're looking for a recipe for a grill cheese sandwich. You go on the site, and it's about 200 pages long. It doesn't just tell you the ingredients for a grill cheese sandwich, it tells you how those ingredients can be obtained, the history behind each ingredient, the health effects of consuming each ingredient. Shit you don't really care about if all you're trying to do is to make a damn sandwich!

I just need to know that I need sliced cheddar cheese. Not how it's made or how it's sliced (if I care about either of those things I'll dig deeper myself) what the history is (which is completely irrelevant to my concern). Point is, I don't need to see all of that information at once. It's overwhelming.


Thursday, October 13, 2016

The Law of Demeter

This is a well known software design guideline that helps you write code that is:
  • More readable
  • More testable
  • Less coupled 
It also goes by the following three definitions, ranging from least formal to most formal:

Definition 1

Don't talk to strangers. Only talk to your (immediate) friends. 

Your best friends are Bob, Jane, and Josh. You need help? Talk to them. Don't talk to their friends or their cousins. 

Definition 2

Use only one dot. 

No: SomeObject.doOneThing().doAnotherThing().andAnotherThing()
Yes: SomeObject.doManyThings()

Uncle Bob calls the first NO example a train wreck. Avoid train wrecks. 

Definition 3

Method F of object C may only call methods of objects that are:
  1. C
  2. Ceated by C
  3. Parameters of F
  4. Created by F

Effects of Least Knowledge on Testing, Coupling, Readability


We don't need code samples to consider the implications of this on our code. What all three definitions have in common is that by following them, you're minimizing an objects knowledge of other objects. If you're forced to only talk to your immediate friends, you don't need to know about their friends. If you're only using one dot, you're only ever dealing with the interface of one other object. This is why the Law of Demeter is also known as the Principle of Least Knowledge. 

There's a strong correlation between the amount of knowledge an object has about other objects and the difficulty of testing that object. Think about it. The more things an objects interacts with, the more you have to set up in order to test that objects behaviors. 

When an object has little knowledge about other objects, code also tends to be less coupled. An object with no dependencies and with nothing that depends on it is an object with no coupling. It depends on nothing and nothing depends on it. Systems, however, aren't usually built using a number of completely isolated parts that don't communicate with one another. But the more we can limit the communication between different parts, the less likely any change in one part of that system will affect the rest. 

If you're looking at a code base that adheres to LOD, there's a good chance you'll find it very readable because the less objects know about other objects, the less you have to know when you're trying to understand that object. If you're dealing with a train wreck, to really understand what's happening you have to follow multiple dots and that requires more effort and to change the behavior will require you to understand the interfaces of two or more objects. Again, more mental effort.

Saturday, October 1, 2016

Very bad things you should NEVER do to your window glass at home

Bad Thing #1: Taping shit to the window glass.

Getting adhesives off glass is time-consuming and you risk damaging the glass each time you do it. I once complained to my dad about having too much sunlight in my bedroom (my windows face east) and his solution was to coat them with multiple sheets of thin, light-colored decorative wallpaper. It sort of helped, but it made my room feel like a solitary confinement cell. If you also have too much light in your bedroom, don't ask my dad for advice - get blinds.

If you avoid doing Bad Thing #1 in life, then the rest of this post won't apply to you. However, if you're interested in learning about how much badly you can fuck up your windows following your single biggest mistake, keep reading.

Bad Thing #2: Using a canister stove as a blow torch to loosen the adhesive stuck to your glass.

I finally got sick of looking at the ugly wallpaper in my room today and decided that I was going to spend an hour removing it. I wanted my windows wallpaper free. An hour later, I was hunched over on the edge of my bed in my room with a tiny metal scraper resting in my right hand. At that point, I've already tried a number of liquid solvents to soften and loosen up the wallpaper: water, water with vinegar, windex, and even peanut butter (trust me, it's a thing). None of it worked. The wallpaper was dried, thin, flaky and married to the glass. 

Feeling frustrated, I turned to fire because heat is known to break sticky bonds. I started out small with a stove lighter to heat up tiny spots on the glass with the most stubborn wallpaper. This worked really well and got me excited. However, the lighter kept going out and the process was painfully slow because the flame was so small. So how do I add more heat and do it across a greater surface area without adding more lighters? Well, one popular option is a heat gun. I've seen my girlfriends dad use it on a sticky label once and it was very effective. Unfortunately, I don't own one and I didn't feel like going out to buy one. What's the closest thing I have to a heat gun? A blow dryer. So I plugged in my girlfriends blow dryer and started blasting the glass with it. Five minutes later, I realized the blow dryer wasn't generating enough heat so that wasn't much help. 

I need more then hot air. I need fire. And that's when I thought, "What if I had a blow torch"? Well, I don't. But I do have a canister stove that my girlfriend and I bought for a camping trip that I can probably use as a blow torch. So I unpacked my canister stove, lit it up, and held it up to the glass. It was working! The stuff was coming off fast (and turning into ash in the process). I was like, this is amaz - *CRACK*. Shit, that was my glass. F************.

Turns out there's this thing known as "thermal stress break" that can happen to glass surfaces. Basically, glass expands when heated and shrinks when cooled. When there's a change in heat and that change is not transferred uniformly across a glass surface (in this case, it was a lot of heat concentrated in a single area), one part of the surface will attempt to expand and that creates stress between the heated area and the rest of the glass known as thermal stress. There's a limit to how much thermal stress a piece of glass can withstand before there's a thermal stress break and my glass clearly had a thermal stress break.

Did I stop there? I wish I did. 

Bad Thing #3: Ignoring physics by pouring boiling water onto the glass.

Yup, it got worse. I didn't want to use the canister again because it just generated too much heat in a concentrated area. I did some more research and came across a few articles of people using boiling water to successfully remove wallpaper from their walls. Interesting. At this point I knew that using heat works really well - but only up to a point when it comes to glass. I didn't know what that point was but I soon found out that it was far lower than boiling point.

First, I learned how to remove a double-hung window sash so that I could remove my uncracked top window and use it in my boiling water attempt. After I got it down, I brought the sash into my bathroom and set it down with the glass horizontal to the floor while my water was boiling. Once my water finished boiling, I brought it into the bathroom in a pot and then slowly poured it over the glass and ...



That's it. No more ideas. Time to get new window sashes and blinds. 

Sunday, August 21, 2016

Why is the programming language you choose important?

The topic of programming languages inevitably comes up when you've got a group of programmers talking to each other. What language do you use? What's your favorite language? Omg I fucking hate PHP too. 

Why do so many programmers care about what language they use? If you're a programmer and you don't really pay much attention to the languages you're using to write code, why should you care?

This line in the Structures and Interpretations of Computer Programs does an excellent job explaining why programming languages are so important:


A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize our ideas about processes. Thus, when we describe a language, we should pay particular attention to the means that the language provides for combining simple ideas to form more complex ideas

I love this line: A powerful programming language is more than just a means for instructing a computer to perform tasks. 

Yes, computers interpret programming languages to do things. That's pretty important. But who's writing these languages? We are. And who's reading these programs when they don't lead to the behavior we intend? We are. So yeah, the language absolutely matters. This is why "high-level" programming languages like Python and Ruby were invented. It's far easier to organize our ideas about processes using something that resembles natural language than using ones and zeros.

TinyHabits is not a magic pill

A couple of years ago I was interested in learning about habit development (mostly because I wanted to develop new habits myself) and came across a behavior change method called Tiny Habits by a behavioral psychology research at Stanford named BJ Fogg.

The method is simple. Pick a very small and specific habit. Visualize it. Next, identify ways you can make that small and specific behavior easy to do. Lets say the behavior you chose was to pick up and practice hitting a chord on your guitar after you get home from work. What would make that easier? Well, maybe you can try leaving your guitar next to the door! Finally, you pick a trigger and a reward in order to sustain the behavior.

That sounds pretty simple right? Well, yeah. It is. It's an excellent framework - but that's all it is. A framework. It does not prescribe what the habits should be, what the triggers should be or what the rewards should be. It offers a scaffolding for you to build on. An outline for you to expand upon. That's the hard part that companies spend many years and dollars trying to figure out.

In other words, even though the general mechanics of the habit loop is pretty well understood at this point, the question of how to make a specific behavior stick - namely, what triggers and rewards need to be in place - depends on the person and the behavior. For example, for practicing the guitar, it's not clear what the reward should be. What motivates one person to pick up a guitar is different from what motivates another person. For some, maybe just playing the guitar is reward enough and this whole system is just unnecessary.

Saturday, August 13, 2016

The Slipper Room Show





I just went to a burlesque variety show with my friend tonight. First of all, they need to add more seating because I think a good half of the people who bought tickets were forced to stand. That's just not cool. Also, they said the show would start at 9:30 but it didn't start until like 9:50. We were both pretty pissed before the show even got started.

This was a variety show with mostly burlesque performances. But really, it's a burlesque show. There was some comedy, some satirical magic, and lots of burlesque dancing. The host was the comedian James Habacker and for the whole time I wasn't sure if he was playing himself or a specific character. He had a drink on one hand for every every act and told pithy logic jokes like "I'm not a heavy drinker ... I'm only a hundred and thirty five pounds" and "so ... corduroy pants are making headlines". I thought he was pretty funny but it did bother me that he seemed to forget (disregard?) his hosting role during the show by constantly asking the audience "do you guys want me bring out the next female dancer?" - as if he was the main act. He was clearly in character and was joking but it really didn't do much to amp up the audience for the actual dance performance.

The first performance by the dancer Harvest Moon was breathtaking. She started out doing the typical, sensual burlesque stuff and then transitioned into aerial silks. One moment she was slow dancing and the next moment she was practically flying in the air! It was really an incredible show of both strength and elegance. My favorite move was when she wrapped herself in the silk on her climb up, then let go and dropped down just far enough to catch herself before the silk she was wrapped in completely unraveled.

Then there was also a comedian magician Chipps Cooney. Habacker (the host) introduced him as the world most famous illusionist. At that point I should've known better to know that Habacker was being sarcastic. This guy was not an actual illusionist. It's a comedy act of a pretend-illusionist setting up tricks as if he was going to do a real illusion. For example, in one act he took out a plastic bottle for his magic wooden chest and displayed it to the audience and then violently crumples it. Hmmm, I wonder what he's going to do with that! He then turns around and blows air into the bottle with about as much force and tada! The bottle is back! Yeah, that kind of magic. I especially liked the one where he brings out a snow globe that was not snowing, covers it with a red handkerchief, and then gently shakes the snow globe before pulling it off to show you the show that just magically appeared.

I don't think I'd go to one of these again. I was hoping for more performances like Moon's where there was a combination of both burlesque and stunts. I guess I was hoping to walk away amazed by some of the performances but I don't think this was that kind of show. The comedic portions by the host had a good number of funny short jokes (and one very long bestiality joke that ended in a confusing way) but felt too lengthy, too misogynistic, and too discursive.


Thursday, August 11, 2016

Jia Duo Bao Herbal Tea?

My mom keeps insisting that I drink this thing called Jia Duo Bao because of its many "health benefits". I was very skeptical. Here's what it looks like:


My girlfriend and I looked at the ingredients on the nutritional label the other night and we could not recognize most of the ingredients. The only two ingredients that we knew were water and sugar. She looked at the sugar amount and said "this is just sugar water!". There's 28 grams of sugar and I wasn't sure whether or not that's a lot. Is it? Well, I know that one teaspoon holds about 4 grams of sugar. So there's about 7 teaspoons in this drink.

Okay, that seems like a lot if I imagine myself just putting sugar in my mouth. But is it? According to an article published by the American Heart Association, the recommended upper limit for men is about 150 calories of sugar, which is 9 teaspoons. For women, it's 100 calories, which is 6 teaspoons. So if I have this one drink, I'm already close to 80% of your daily limit. That doesn't seem very good. I'm a pretty active guy, so I wouldn't get too worried having a soft drink every now and then. However, this make me less confident about the "health benefits" that my mom refers to.

In addition to water and sugar, there's seven additional ingredients that neither of us were familiar with. So I looked them up.
  1. Mesona - https://en.wikipedia.org/wiki/Platostoma_palustre
  2. White Frangipani - http://www.allthingsfrangipani.com/frangipanis.html
  3. Microcos - https://en.wikipedia.org/wiki/Microcos
  4. Chrysanthemum - https://en.wikipedia.org/wiki/Chrysanthemum
  5. Japanese Honeysuckle - https://en.wikipedia.org/wiki/Lonicera_japonica
  6. Heal All - https://en.wikipedia.org/wiki/Prunella_vulgaris
  7. Chinese Licorice - https://en.wikipedia.org/wiki/Glycyrrhiza_uralensis
Turns out, all of these are plants, which is probably where the "herbal" part of this drink comes from. In the front of the can, you see this line of text:

JiaDuoBao Herbal Tea - Made from prime herbal ingredients

I did some research on the company behind this product, Hangzhou Jiaduobao Drinks Co, and found that they've actually surpassed coca-cola in terms of sales in China with this product. They market the drink as a sweet drink with many health benefits from the herbal ingredients. In other words, it's like coke, but supposedly good for you. Good in what way? Lowering your internal heat, for example. I don't really know what that means so I can't really say whether or not this is even a real thing (as in can it actually lower your internal heat, whatever that is?), let alone one whether that has any health benefits whatsoever. I mean, maybe you don't need your internal heat lowered, I don't know. 

I'll probably dig into this some more. In the meantime, I think I'll be staying away from this sugar water.

How much money did I save by making a sandwich for dinner?

I recently started making sandwiches for dinner instead of eating out. As I was preparing my sandwich tonight, I wondered how much money I was really saving. So I decided to look at the cost per serving for all of the ingredients in my sandwich. By serving I mean the measure of how much I actually eat rather than what's defined on the nutrition label. For the cost calculations, I'm rounding to the nearest tenths.

Cost of ingredients


Price: $4.49
Total slices: 16

The nutrition label defines one slice as a serving. Like most people, I eat two slices.

Cost per serving of bread = (4.49 / 16) * 2 = 0.56

Price: $5.50
Total slices: 16

I use about four slices for each sandwich. 

Cost per serving of ham = (5.50 / 16) * 4 = 1.38

Price: $5.99
Total slices: 12

I use two slices. 

Cost per serving of cheese = (5.99 / 12) * 2 = 1.00

Price: $4.79
Total amount: 30 tbsp

I use about one table spoon. 

Cost per serving of mayonnaise = (4.79 / 30) = 0.16

Price: $2.99
Total amount: ???

I just finished up this lettuce and I've had it for quite a while. I think it's been used for about 12 - 13 sandwiches. Lets say it's 12. 

Cost per serving of lettuce = (2.99 / 12) = 0.25

Total cost of my sandwich


Total cost = (0.56 + 1.38 + 1.00 + 0.16 + 0.25) = $3.35

Holy shit. 

How much do I typically spend on dinner when I'm eating out? $10 - $12. Lets say $11. That means I just saved $7.65 tonight!

If I ate out every night for a month, I'd spend $330 on dinner alone for that month. If I ate a sandwich (with equivalent cost to this one) every night, it would only cost me $100.5 a month. So in theory (I say theory because I cannot eat sandwiches every single day for a month), if I ate these sandwiches for a month instead of eating out, I'd save more than 200 dollars!


Tuesday, August 9, 2016

Launching Sublime Text 3 from the Mac OSX Command Line

Both Sublime Text 2 and 3 ships with a command line tool called subl that allows you to open the editor from your terminal. Most instructions online teach you how to symlink the tool in a directory that's on the PATH so that you can run it simply by typing subl.

Unfortunately, lots of the instructions that I came across hard coded the tools path for Sublime 2. This failed for me because it turns out Sublime Text 3 uses a different path. To save you a few seconds, here's the symlink command for Sublime Text 3.

ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

Wednesday, August 3, 2016

How to connect an external monitor using ThinkPad Onelink ProDock

I just got an external monitor displaying using my Onelink dock! The dock is connected to my Lenovo ThinkPad Carbon X1.

Here's how I got it setup:
  1. Connected the dock to my X1.
  2. Connected my external display to my dock using an HDMI cable that came with my external monitor and a Rocketfish HDMI to DVI-D adapter.
  3. Scratched my head in frustration because my computer was not detecting the display. I exchanged my adapter thinking that maybe it was faulty, tried a VGA cable and VGA to DVI-D adapter, and plugged / unplugged the connectors a few dozen times. Still nothing.
  4. Thought it might be a software issue and used my Google-Fu. Learned that computers that were recently upgraded to windows 10 had issues detecting external displays with the dock.  
  5. Installed the latest dock driver as recommended.
  6. Dance.

Sunday, July 31, 2016

Inspecting a book

The ultimate goal of reading is to learn something. Maybe you read a biography to learn about someones life. Or you read a how-to book to learn how to cool. You're learning. Now, for any subject that you may want to learn more about, there is likely more than one book written about that subject. Since you don't have all the time in the world, it's important to be able to identify which books will give you the best bang for your buck.

That's the purpose of inspectional reading - to inspect a book and answer the question of "do I want to engage with this book at a deeper level?". There are multiple "levels" of reading that represent how much engagement you have with the book which are indicated by the types of questions you're asking and answering. Problem is that if you try to engage with every single book as fully as you can, you'll spend a lot of time on books that just may not be worth your time. 

So how do you perform inspectional reading? 
  1. Look at the title of the book, the blurb, the authors bio, and the index. The goal is to get a sense of what type of book it is (theoretical? practical?), what it's about, and the sources it draws from. If the book appears to fit the subject you're looking to learn more about or if it interests you, go on to the next step. Otherwise, put the book away. 
  2. Now we want to know the basic structure of the book. Look at the table of contents. Read the preface. How are the ideas structured? Is there a logical order? Is it random? Does it seem easy to follow? Often times the Author talks about how they've organized their ideas in the book in the preface. The goal of this step is to show you a rough map of where things are. It's a little map for your journey. There's no need to study it intensively, just glance at it a few times so you know where you are once you start ...
  3. Peek at some of the chapters. Read the beginning of chapters, end of chapters. Beginning of paragraphs. Get a sense of what the key ideas are. Then read the last 3 pages of the book (for practical books) to get a sense of how the ideas are all tied together. After completing this step, you should have a basic idea of what the book is about as a whole and in parts and how those parts are organized, and whether you're still interested.
  4. Do a superficial reading of the book. This is basically a test run. Don't stop to look up words or ideas you don't grasp. Just make sure you read every sentence. The goal isn't comprehending everything - it's to just finish the book. 
Every step serves the purpose of giving you a clearer sense of what the author is saying and whether or not you're interested in engaging in a conversation with him or her (as deeper levels of reading are essentially conversations between you and the author). Steps 1-3 helps establish the overall structure and the final step of inspection serves to fill it in with the meat of the content which you can later use to identify parts that you need to pay closer attention to (more difficult / interesting parts of the book). 

Tuesday, July 26, 2016

How cruise control works

I learned about cruise control after driving over two hundred miles in my dads car (2011 Honda CRV) on a thruway for about four hours with no cruise control. This was my longest drive ever. I live in the city, so I primarily get around by public transit. In the beginning of the trip, I was having trouble maintaining my speed on the highway and my girlfriend suggested that I use cruise control. My first reaction was: what's cruise control? Unfortunately, even though she knew what it was she wasn't sure how to enable it in my car and we agreed that trying to figure out a feature that can influence the speed of the car while going 60 mph is probably not a good idea.

The first thing I did after the end of that trip was to look up how it worked and now I'm a believer.

Here's how it works in my dads car:

There's three buttons:

  • Cruise control main
  • Accelerate / Resume
  • Decelerate / Set

Press the cruise control main button. This turns on the cruise control feature but doesn't actually maintain the speed of your car yet. In order for that to happen, you need to press the Decelerate / Set button once you've reached your desired speed. Once you've accelerated or decelerated to your desired speed, pressing SET will tell the car to cruise!

Now that you're cruising, you may want to do one of five things:

  1. Accelerate but do not cruise at a higher speed. Just hit the pedal - you'll go faster but once you take your foot off the pedal it'll just return to the current cruising speed.
  2. Decelerate but do not cruise at a lower speed. Hit the brakes. This will unset cruising. If you do not accelerate, your speed will keep falling. If you want to resume your cruise control, just hit the resume button and you'll return to cruising. 
  3. Cruise at a higher speed. Hit the accelerate button until you reach your desired speed or you can accelerate and hit the SET again.
  4. Cruise at a lower speed. Hit the decelerate button until you reach your desired speed or you can brake and hit SET again.
  5. Turn off cruise control completely. Just press the cruise control main button and you should see the cruise control light indicator go off. 
Drive safe!


Saturday, June 25, 2016

Things you should know before buying a mattress from a first time mattress buyer

I recently bought a mattress that my girlfriend and I really, really like. She likes it so much that she's referred to it as "heavenly". I notice myself tossing and turning much less when I try to go to bed and I feel like I'm getting much higher quality sleep. The process of finally buying this mattress, however, was a bit of a headache and I made a few mistakes along the way. I'm not an expert, but here's a bunch of things I learned as a first time mattress buyer that you'll find helpful if you're looking to buy a great mattress.

1. If you don't sleep alone, buy a mattress with motion isolation.

I really can't stress this enough because it's so important. I actually exchanged my first mattress for the one I have now because any movement that me or my girlfriend made were really noticeable and it hurt our sleep the very first night.

Without motion isolation, it only takes one persons movement on the mattress to ruin the others sleep. If you're buying a mattress with a spring support system, make sure you buy the ones that specify "pocket springs". In a pocket spring system, every coil in the system is independent of one another and that prevents the motion from one part of the bed from transferring over to another.

2. Support vs comfort (softness). Go for both but know that support is more important than comfort.

There are different "comfort" categories such as "firm", "pillowtop", and "plush". The industry calls them comfort preferences but that's a little misleading because they don't mean how comfortable the mattress is (since that's subjective), they really just describe the softness of the mattress. Namely, how far any part of the mattress is able to sink down when pressure is applied.

The softness of the mattress is what you'll immediately experience when you try a mattress for the first time. The feel of the softness is important, but don't make the mistake of buying a mattress just because it feels great when you're lying on your back for the first five minutes. Don't let it fool you. What you're feeling is the upper layer of the mattress. What's more important is the middle layers, which are the support layers.

The job of the support layers is to primarily to support your spinal alignment by contouring itself to the shape of your body as if it were standing up straight. You can have a really soft and seemingly comfortable mattress, but you'll wake up with awful back pain if the mattress has poor support.

It's hard to tell whether or not a mattress has good support from lying down on it for a few minutes, so the best thing to do is just to ask. You can change the softness of your mattress but you cannot change it's support (which is what you're paying the most for).

3. A mattress that has a solid support system, comfortable surface, and motion isolation will probably cost more than $800.

I've tried many, many mattresses (20 - 30) while I was shopping for a mattress and I rarely came across one that I really liked that was only for a few hundred bucks. Assume that if it's less than $800, it's likely compromising on one of those three features. Either it has poor support, no motion isolation, or cheap surface fabric. If you're not sure which one from trying it, ask directly. I'm not getting paid by a mattress company to say this - you really do feel the difference. The prices are not arbitrary.

4. Don't be afraid to test the mattress at the store.

Does it claim to have motion isolation? Does it say it has a great support system? Test it. Don't be afraid to try the mattress. When you buy new clothes at a store, you try it out in the fitting room don't you? There's no mattress fitting room, but don't let that stop you from rolling around on the mattress. When I was showed a couple of mattresses that supposedly had reduced motion transfer, I asked the sales person to lie down next to me and and then roll off the bed. I tried this with a few different beds - all promising the same thing on paper but delivering different results - until I found one that I was satisfied with. Don't just take their word for it - try it and experience it for yourself before you decide to fork over your money.

5. Know your budget.

There are some incredibly expensive mattresses. If you're not careful, you could end up spending a whole lot of money for very slight marginal improvements in comfort. For me, the mattress I settled with was within my budget and was good enough for me. Were there better ones? Yes - but it was only slightly more comfortable for twice the price and I wasn't willing to spend more than I allocated no matter how much more comfortable.

Pick a price range and then stick to it. This will prevent you from spending more than you have make your search much more efficient. You can always find a better, however slightly, mattress if you do not budget and that can eat up a lot of your time. By sticking to a range, you're able to compare mattresses in a similar quality spectrum and make a faster decision.

6. You can get a discount if you do your research.

After you've tried a number of mattresses in person and found a few that you like, check the price online with the exact specification. I did this but made the mistake of leaving out one crucial detail and ended up buying a mattress which I had to exchange because it was not the same mattress. A lot of them look the same and have very similar names so you have to be very specific.

Try to get a range of prices for each one. If they're less than the in-store retail price, go back to the store and ask for a discount. I suggest going back to the store because:

1. If it's really the same product and it's cheaper elsewhere, they'll likely sell it to you at a discount because they want to earn their commission.

2. If it's not the same, you'll know because they'll tell you that it's not and refuse to budge on price.

Monday, June 13, 2016

Donating used goods

I've been cleaning out my apartment recently and wanted to get rid of a lot of old clothes that I don't plan on wearing anymore. Most of them were still in very good condition so wanted to donate them instead of throwing them away. I did some research and found a couple of non-profit organizations that have drop off sites in NYC and I highly recommend them if you're looking to donate clothes that you don't wear anymore.

Organizations


The Salvation Army

A non profit that's also a christian church. They provide food, shelter, and humanitarian aid.

Good Will Industries

A non profit that provides community-based programs like job training and employment placement for people who have disabilities.

Both organizations have store operations throughout the country that sell the non-cash donations that they receive. They're essentially non-profit thrift shops. If you're looking to donate your goods, make sure you go to a drop-off location. You can't drop off your stuff at a store.

For example, there's a Salvation Army location in Manhattan called the "Salvation Army Store and Drop off Center" where you can buy used goods as well as donate.

Monday, June 6, 2016

Physique Swimming: Lesson 10

I had my final swimming lesson with Physique Swimming today!

We started off with a variant of the streamline. You take the streamline position and then you take a breath by moving your arms apart to take a breath and then back into streamline. I had a lot of trouble staying afloat after coming up for air. This was due to a few issues:

  • Instead of simply parting my arms I was pulling them too far back. This meant that when I put them back into streamline, I was creating too much drag. The key is to part them slightly and push down slightly to get air. 
  • Don't jerk your head up too high or your legs will sink. That's like the basic mistake.
  • Exhale slowly. Don't breathe it all out at once. This prevents you from feeling out of air too quickly and keeps you buoyant longer. 
We then worked on streamlining and turn. You would swim in streamline on your stomach and then turn onto your back while still holding streamline. Every time I turned, I would keep kicking but my face remain submerged under water. 
  • I'm kicking my feet up - this is sending me into the water. Try to let your legs drop a bit lower and kick downwards a bit. 
  • Your hands are not tilted upwards. Tilting it up will help push you higher in the water. I have no idea why.
  • You are dropping your hips. Don't drop them or else your feet will go up and your butt will go down and cause you to sink. 
  • Maintain your streamline. Keep your arms outstretched.
Note: Not having your arms outstretched makes it significantly easier to stay afloat. 

Finally, we did some treading. I think I finally got it! We started by just trying to keep our head on top of the water. Then we were asked to show one hand. And then the other hand. 

What works:
  • Slow but wide movements. This creates a lot of power while minimizing effort. 
    • Push down with your hands and do a flutter kick with your legs at the same time. 
  • Breath out slowly 
  • Kick a bit harder when you bring your arms outside of the water. 
Next steps:
  • My instructor told me I should continue practicing on my own and maybe come for a private lesson once a week or once every two weeks to make sure I'm on the right track. 
  • Work on my breathing. Stop exhaling so fast and relax. 

Thursday, May 12, 2016

Individual Tax Basics

I recently filed my tax returns on TurboTax. It's so easy - you don't need to know anything about taxes. In my case, all I had to do with import my W2, answer a dozen questions, and I was done. I didn't know anything about the actual calculations, which is really convenient since I don't have to know the specifics but my ignorance also made me uncomfortable. How do I know these numbers are even right? I don't need to be a tax expert but I feel like I should at least know the basics to estimate my tax obligations so I know I'm at least not being cheated. It also seems like one of those things you should know as a working citizen.

So I decided to do some reading about the basics of how taxes are calculated.

Taxes are money collected by the IRS (Internal Revenue Service) to fund public or common resources such as firefighters and police on the city and state level as well as social welfare programs such as Social Security, among many other things. They're collected from both individuals as well as organizations, although not every individual or organization is obligated to pay taxes. Tax exemption is freedom from tax obligations, and many non-profit organizations are tax-exempt. Individuals can also be tax exempt depending on their level of income. 

Other than those that are tax exempt, any entity that's generating revenue in the U.S economic system is obligated to pay taxes. In this post I'll explain the taxation rules for single individuals since that's what applies to me. Different rules may apply to companies or married couple (yes, that matters).

Before the IRS can determine anything about your tax obligations, they need to know your total income or your gross income. This is the total amount of money that you earn in a year. If you work one job, then it's your salary plus any bonuses you received during the year. If you work multiple jobs, then it's the sum of all of your salaries. 

If you're lucky enough to make enough to owe taxes, there are two main types of taxes that you'll have to pay.

Income Tax

This is the tax that is collected from the money you earn from your job. There are two types of income tax. One is the federal income tax and the other is the state income tax. Not all states have income tax so not everyone has to pay state income taxes. However, everyone who is obligated to pay taxes must pay the federal income tax.

The income tax system in the U.S is known as a progressive tax system. In a nutshell, this just means that different tax rates are applied to different levels of your income. Which levels of income those rates apply to depends on your filing status. All of this information is all specified in a tax bracket table. 

Fortunately, for most of us our income tax amount is not collected based off our gross income. They're collected based off of our total taxable income. This is the amount that is actually subject to the income tax after certain deductions are applied. Deductions are any payments that reduce your taxable income. For example, your donations count as deductions and you have the option of claiming donations as deductions. So if you earned $10,000 this year in total and donated $1,000 to charity, you can claim a deduction of $1000 and end up with a taxable income of only $9,000. 

There are two types of deductions: automatic ones and manual ones (I made these terms up). 

Your 401K contributions are automatically deducted from your paycheck. And so are your monthly dental and health insurance premiums. Now at the end of the year when you file your taxes, you can specify more deductions (manually).

You get two options for claiming deductions manually when you file. You can either choose to take the standard deduction, which is $6,300 this year. Or you can choose to itemize. You cannot do both. All itemizing means is listing the payments that you want to claim as deductions (student loans, donations) to be applied to your taxable income. Which option you go with depends on which results in the largest deduction because you want to minimize your taxable income. 

FICA Tax

FICA stands for the Federal Insurance Contributions Act. It's a law introduced as part of the New Deal during the FDR administration in the 1930's when the Social Security program was established to aid retirees and the disabled. 

The FICA Tax today consists of the social security tax and the medicare tax. It's also known as a payroll tax because it's deducted from paycheck to paycheck for both the employee and employer. In 2016, employees are pay 6.2% in Social Security tax and 1.45% in medicare tax. 

The FICA Tax amount is pretty much the same as your taxable income less the 401K contributions. Unfortunately, the FICA Tax applies to 401K contributions.

Other types of taxes

Property Tax

If you own property, then you have to pay taxes based on the value of that property. Depending on where your property is, you may be paying the county or state depending on which has jurisdiction of the property.

Goods and Services Tax

As a consumer, I may have to pay taxes every time I buy a good or service. That's known as a sales tax and it's just one type of goods and services tax. Not all states have sales taxes.


Tuesday, April 26, 2016

Cough Syrup and Antibiotics

Yesterday I visited my primary care doctor for a very persistent, dry cough that I've had for the last week and a half. He prescribed me a couple of things with weird medical names. I had no idea what they were for so I looked them up.

Promethazine DM Syrup

Promethazine is known as an antihistamine. Histamine is a chemical that's known to cause symptoms of allergies like a runny nose or sneezing. Antihistamines don't prevent the production of histamines, they just prevent them from being able to act on the issues which cause the symptoms. This is suppose to decrease post-nasal drips (the mucus secretions that drain from the sinuses into the throat) and therefore also lesson coughing. 

The DM stands for Dextromethorphan. This is a drug that suppresses the cough reflex by affecting the signals in the brain that trigger coughs. The cough syrup that my girlfriend got me (Delsym) contains this ingredient. Delsym doesn't contain promethazine. 

Does that mean there are traces of histamine being produced in my body that is causing my runny nose? Why is it being produced? Ah! I should call my doctor.

Instructions:

Take 1 teaspoon (5ml) by mouth four times daily. 

Azithromycin

This is an antibiotic. It treats all sorts of infections such as respiratory infections, ear infections, and skin infections. 

I came down with a cold. According to this article, since cold symptoms usually last for about a week, the fact that I'm still coughing after a week is a sign that I may also have a bacterial infection. Maybe this will help.

Instructions:

Take 2 tablets by mouth the first day. Then take 1 per day for four days.

Resources:
  • Pronounciations: https://www.youtube.com/watch?v=FDJPDl-yLa8, https://www.youtube.com/watch?v=Cr6Y0zYXPHI
  • http://www.livestrong.com/article/31268-promethazinedm-syrup-used/
  • http://www.everydayhealth.com/drugs/dextromethorphan
  • https://www.youtube.com/watch?v=mmD1en3nClQ
  • http://www.drugs.com/dextromethorphan.html
  • http://www.drugs.com/azithromycin.html

Monday, April 25, 2016

Physique Swimming: Lesson 7

We worked with Fru again today. She's a great teacher - I think she's one of the head teachers in the program just based on the way she talks to the other instructors.

We started of with ... bubbles. As always. My bubbles are a lot more controlled now when I'm swimming. I'm doing a better job pacing myself.

We worked on...

  • Streamline with a kick board. I kept my arms tucked behind my ears and my head facing the floor of the pool. We did it all the way to the deep end and then back.
  • Gliding in streamline position. I think she noticed that our streamlines still needed work so she just had us glide without the kicking. As far as kicking is concerned, she says she wants me to kick wider and slower. I kept running out of breath - I think I was tensing up too much again. It always happens when I don't relax. 
  • Streamline into a back float. We would start off in streamline, then we would rotate our bodies slowly until we're floating on our backs. Then repeat. The purpose of this was get us accustomed to rotating our bodies underwater. 
  • Sidekicks with kick board. Rather than rotating all the way, we would start off streamline, kick, kick, kick, then put one arm on our side and then rotate our head onto our arms while continuing to kick sideways. We kept doing this with both arms. 
    • I stiffen the arm that's on the side way too much. She told me to just let it go and don't tense it. 
    • I rotate too much sometimes end up overstretching my neck. It should be comfortable - your head should be resting on your arm. 
  • Back float kicking off the wall. We held on to the side of the pool and then lifted our feet and put them against the wall while leaning our heads back into the water. Then we gently let go and extended our legs and opened our arms to the side. 
    • My legs kept sinking and she told me to 1. Open them wide and 2. Squeeze my but so I don't bend (huh? tried this but didn't work). 
My biggest problem is the sidekick. I think I'll keep working on it with the board. The moment I lose the board, I feel like it's impossible for me to turn my head and still keep it above water. I'll look up some sidekick drills tomorrow. Pretty tired right now. 

An Afternoon reading about Productivity...

I stopped by Barnes and Nobles today to check out some books on productivity and organization. I've been feeling a bit overwhelmed by the number of things I want to do and it's negatively affecting my work and my relationships. I've never been very good at being organized (my desk is usually messy) and I often do not prioritize things I need to do (I've spent anywhere from hours to entire weeks doing unimportant tasks). As a result, I feel a lot of anxiety when I think about what I want to accomplish, I don't get much important work done, and that in turns fuels the anxiety and saps my energy throughout the day.

Being more productive is something I've thought a lot about but not something I've acted on consistently. I remember coming up with an organization system on Evernote for managing projects that helped me complete a few important goals but it eventually fell into disuse. I went into the store today looking for very action oriented and simple plan to get me back on track.

I just went into the business section and skimmed three books that looked relevant off the shelves.

Here are my notes of some key points:

The Productivity Project by Chris Bailey

  • Know why you want to be more productive. What do you want? When you're able to free up more time, what do you want to spend that time doing? Helps you stick with it. 
  • Focus on three things you want to get done every day (do it day before) as well as three things you want done every week. Why 3? Because that's easy to remember and doesn't overload your brain. We're good at holding groups of 3's in our heads. 
  • When do you have the most energy during the day? For Chris it's about noon - 3pm and 5-8pm. Monitor your energy level. Use this time to work on your most important work. 
  • There's a difference between urgent tasks and important tasks. Just because something is urgent doesn't mean it's important. Learn to say no. No will be the most effective word in your productivity toolbox. 
  • Externalize your ideas about what you want to do so you don't fret over them. But don't go overboard - keep in mind that making todo-lists is not the same as doing. 
  • Have a maintenance day for getting all your unsexy but must do stuff done. These have minimal life level up effects but can impact life negatively if left untend to (like cleaning your apartment). Make it easier by listening to podcasts or some shit. If you can't do it in one day, schedule time each day when you have the LEAST energy to do them. 


7 Habits of Highly Effective People by Stephen Covey

  • Be proactive. We can't control what others (environment, people) do to us. If someone wants to walk up to you and push you, then they're going to do that. We do have control over how we respond. Being proactive is focusing on how we respond to what life gives us. The alternative? Blame and make excuses (reactive). Proactive people focus on verbs. I will. I prefer. I'm going. Not I can't. If only, blah blah blah. We all have a circle of concern and a circle of influence. Being proactive means focusing on what you can control and taking action rather than blaming. Doing so increases your circle of influence because changes take place. Act or be acted upon.
  • What's your center? Are you self-centered? Family-centered? Work-centered? What is your predominant center? Being principle-centered allows you to act with greater consistency and without being swayed by circumstance / emotion. You act according to values that are independent of how you feel at any given moment. 


Organize Tomorrow Today by Dr. Jason Selk and Tom Bartow

  • Product goals versus process goals. 85% of your focus should be on process goals. Focusing on the end result creates anxiety.
  • Productive people get the most important work done, not just as many things done. 
  • Channel capacity = the limit of how much information we can process and retain. You can't get every thing done so don't even try to. Every technique needs to account for channel capacity.
  • List three goals today (preferably noon - 3pm aka middle of day) for tomorrow as well as WHEN you expect to complete it. Then of the 3, identify one MUST COMPLETE goal. Identifying goals early rather than end of the day means maximizing time for your subconscious to work on the goals. Identifying a MUST COMPLETE means focusing on the most important.
  • Don't dwell on your failures. Focus on what you succeed at to sustain motivation and become solution / action driven. Focusing on failures often leads to negative self-talk that does nothing.
  • Keep a success log. What 3 things did you nail today? Doesn't have to be big. What's 1 thing you could improve? What is 1 action you can take tomorrow to make that improvement?  
I've noticed a few ideas that come up over and over again in both the books I looked at today and other productivity books I've read in the past:
  • Externalize your ideas about what you want to do. Make lists. This reduces anxiety, reminds you of what you need to do, and enlists the help of your subconscious.
  • Make a todo list for tomorrow TODAY. Almost every author suggests doing it the day before between noon to evening. 
  • Focus on 3 things. 3 is the magic number, apparently. 
  • Do most important thing when you have the most energy (for most people, this is in the morning). Eat your frogs first. 
  • Less is more. Don't try to do too much or you will burn out / give up / not get much done because your attention is scattered. 
I really, really like the simplicity of the todo system outlined by Jason and Tom. There's two main components:
  1. Identify 3 process goals for tomorrow between noon and dinner time. Write down a short description of each and when it needs to be complete. 
  2. Of the three, mark the most important one that needs to be done. This is one you must try to complete at all costs. 
  3. Evaluate your progress and stay motivated by keeping a success log. What are three things (doesn't have to be related to your goals) that you nailed today? What is one improvement you can make? What's one specific action you can take tomorrow to help make that improvement? 
This will really help me clarify what I want to do and holding myself accountable for it.