Skip to content

Instantly share code, notes, and snippets.

#debugging node apps

##how to debug node apps w/ node inspector

  • Watch Expression in inspector -- will keep track of the val of something
  • Call Stack then right-click on callbacks you can Restart Frame
  • can edit vars in Scope Variables
  • can live edit source code in debugger
    • an asterisk will appear above file name, command s will save that code
  • debugging mocha unit tests

##obj playground ###functions and methods

  • use strict forces this to be undefined
  • call apply bind allow you to force this to be certain value ###prototypal inheritance
  • js will go as far up the prototypal chain that it needs to in order to find the property, all while keeping the original this intact
  • polymorphism - same name, diff behaviors
  var answer = {
    get: function() {
@sranso
sranso / perl.md
Last active August 29, 2015 14:08

replace all captured strings in a repo with this arg

ls apps/webviews/public/stylesheets/*.less | xargs perl -pi -e 's/imagePath/differentNewPath/'
ls apps/webviews/public/stylesheets/*.less | xargs perl -pi -e 's/\@\{(.*)\}/\@\{hello_$1\}/'
  • -p run file in loop
  • -i modifies file in place. takes optional argument (e.g. create backup file to everything)
  • -e expresion you want to run

what is an MIT license?

  • MIT tldrl
  • MIT is just the name of license
  • it's popular one because it allows people to use/modify/redistribute without needed to contribute changes back to the source (like GPL)
  • if i put MIT on something i build, then i'm saying "people, feel free to use this! no need to come back to me with your changes."
  • by default things things are copyrighted, if you don't specify a license at all, so it means - hey you can't use this
  • MIT/BSD/GPL/etc are "copyleft" type licenses
@sranso
sranso / AMD.md
Last active August 29, 2015 14:08

##AMD: what why how

###what

  • Asynchronous Module Definition
  • a format for writing modular js in the browser

###why

  • overall goal for the AMD format is to provide a solution for modular JavaScript that developers can use today
    • allows the browser to load multiple js bytes at the same time; wont get hung up on one thing (e.g. wont wait to load all of jquery before starting to load google analytics)
  • Provides a clear proposal for how to approach defining flexible modules.

#anatomy of a web request

Web Request

  • let's make request to https://www.etsy.com
  • what does the browser do?
    1. DNS
    2. check to see if it's already looked up the IP address for this host
    3. check to see if the address is the local host itself
    4. look in /etc/hosts to see if there is a matching entry
    5. browser sends a UDP (?) packet to the resolving name server (RNS), asks "do you know where www.etsy.com is?"

##esprima etc

  • use esprima to parse our codebase, then in the AST (abstract syntax tree that represents the code) that esprima outputs, alter the tree by inserting new functions to trace and time function calls and other things we can measure, then recompile the AST back into javascript and run that code as a sort of dev/debug bundle
  • i think a good first step might be to take an inventory of the available tools to profile single page apps and see if there is something out there that can help us so we don't have to do it all from scratch
  • if there is something out there that would work for us, maybe the esprima route might be more trouble than it is worth, but i just don't know what sort of things are out there yet

Instrument the modules to get metrics about what to optimize (1-3 days) how to measure how long it takes for something to be served, rendered in dom

##what we're measuring how long does it take...

  • from eloquent js

    "People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones."

    Donald Knuth

    • reminds me of improv: you bring a brick, i bring a brick, together we build a house
  • it's like group therapy

  • important to be really clear and simple with your ideas: sort of like single responsibility principle, it's easier on your partner if you give them one idea at a time so they can take that result / return, do something with it, and give you another thing for you to then do the same with

    • "you had one job!"
  • each function in improv takes a parameter: what the person before them just said. shouldn't return exactly what the person said, or reject the input. must do something with the input and build on top of it

  • bits
    • any kind of two-valued things, usually described as zeroes and ones.
    • any piece of discrete information can be reduced to a sequence of zeros and ones and thus represented in bits.
  • values
    • chunks of bits that represent pieces of information (easier to manage as values rather than bits)
    • all values are made of bits
    • six basic types of values in javascript
      • numbers
  • strings