Skip to content

Instantly share code, notes, and snippets.

@hartleybrody
hartleybrody / Bitwise Operators.md
Last active August 29, 2015 13:57
While learning about XORs during a basic crypto class, I decided to take a side track and learn about a term that was always shrouded in mystery -- bitwise operators. As always, I wrote these as my own notes for later reference but I'm publishing them here in case they help other people. Happy to accept pull requests for corrections.

(A bit of a tangent from crypto 101)

Bits and bytes

  • Core contepts:

    • Bitwise operators work on bits.
    • Bits are used to express data in binary form.
    • Bits can have a value of either 1 (ie TRUE) or 0 (ie FALSE).
  • Higher-level language constructs like floats and strings can all be represented as a series of bytes

  • 1 byte = 8 bits

@hartleybrody
hartleybrody / Javascript Variable Scoping.md
Last active February 3, 2019 19:13
Variable scoping in Javascript can be confusing so I set out to make notes of the basic rules so that I can reference them later. Hope these are useful to others, happy to talk pull requests for corrections.

Javascript has two kinds of scope:

  1. Local (inside a function)
  2. Global (outside a function)

The var Keyword

  • Using the var keywords creates the variable in the current scope
    • If the current scope is global, then var is unnecessary (see below)
    • If the current scope is local, then you’re creating a local variable in the current scope
  • If you don’t use var, then Javascript goes up the “scope chain” to see if it’s already been declared
@hartleybrody
hartleybrody / new-tab.js
Last active December 15, 2015 17:19
Open all links on a page in a new window, assuming jQuery is mapped to the $ sign. Useful for when I want to leave a page open (ie, GitHub dashboard) and not have to constantly be reaching for my bookmarks.
$('a').each( function(index, item){
item.target = '_blank';
});