Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
Created April 4, 2011 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikeldridge/902301 to your computer and use it in GitHub Desktop.
Save erikeldridge/902301 to your computer and use it in GitHub Desktop.
toolkit

Tips & Tools

Ack

  • Use less for paging, but still provide ack's nice colored output and per-file grouping, by adding this to .ackrc: --pager=less -r -E

JS

CSS

HTML

Ruby

  • Rails docs w/ nice search: http://www.railsbrain.com/
  • gdb
    • Use "debugger" keyword in script to launch gbd
    • Set autolist to see context: set autolist
  • HTML/CSS sanitizer https://github.com/rgrove/sanitize/
  • Run spec w/ -c option for satisfying red/green output
  • Use rake to rebuild db: rake db:rebuild
  • Show all rake tasks: rake -T
  • Install gems w/ rake: rake gems:install
  • Show rake stack trace on error: rake <task> --trace
  • Build gem: gem build <path to gemspec>
  • Create rvm environment (ruby vm + gems) for ruby v1.8.7:
    1. rvm install 1.8.7
    2. rvm gemset create <gemset name>
  • Show all rvm environments: rvm list
  • Show all rvm gemsets: rvm list gemsets
  • Select an rvm environment: rvm use <rvm name>@<gemset name>
  • Use .rvmrc to tell rvm which gemset to use on a per-directory basis
  • List gems w/ details: gem list -d
  • Install gem w/o docs: gem install <gem name> --no-rdoc --no-ri, e.g., gem install rails --version 2.3.8 --no-rdoc --no-ri
  • Generate rails migration timestamp: ruby -e "p Time.new.strftime('%Y%m%d%H%M%S')"
  • Magic variable to last result: _, eg x = 2 * 2; y = _
  • Use script/console to load rails app in irb

PostgreSQL

Pig

Firebug

  • Use console.debug to get line number and file name in Firebug output: http://getfirebug.com/logging
  • Use "debugger" keyword to launch Firebug debugger at that point in the code

Chrome

  • Command + Option + J opens javascript console (helpful when console is undocked from window)
  • Cmd + shift + delete opens clear cache/cookies dialog
  • To disable cache, click gear icon in lower right of dev tools, and check the "disable cache" checkbox
  • Google I/O preso on dev tools http://www.youtube.com/watch?v=N8SS-rUEZPg
  • Press ? in developer tools to see keyboard shortcuts

Safari

  • Cmd + alt + E opens clear cache dialog

TextMate

RubyMine

Vim

  • Jump to previous edit point: #
  • Edit text in paired delimiter: c i {delimiter}
  • Select text to next character: v f {character}
  • Select text to previous character: v <shift> f {character}
  • Run shell command: :!{command}

Git

  • Create branch
    • In general, branch from master
    • Create a new branch that tracks a remote branch: # from github docs
      1. git checkout -b foo_branch
      2. git push -u origin foo_branch
    • Create remote tracking branch: git checkout -tb origin/foo_branch
  • Delete remote branch: git branch -rd origin/foo_branch
  • Keep in sync with master:
    • Pull method
      1. git checkout master
      2. git fetch
      3. git pull origin master
      4. git checkout <yourbranch>
      5. git merge master
    • No-local-master method
      1. One time, delete local master branch to avoid ever checking into master: git branch -d master
      2. update all branch references (some ppl run this as a cron job): git fetch origin
      3. Merge in master: git merge origin/master
  • Resolve merge conflicts
    1. fix issue
    2. git add .
    3. git commit
    4. save commit w/o message
  • Use .gitignore to avoid checking in files unnecessary for the project
  • Checkout individual file from external branch. The -- helps git avoid confusion by separating branch from paths). Also useful for git reset --hard on a single file. Note: this does not merge, ie history is lost: git checkout <external branch> -- <path to file>
  • Diff w/ stash: git diff stash@{0}
  • Diff two branches: git diff <branch 1>..<branch 2>, e.g., git diff master..head
  • See branch details: git branch -vv
  • Only show your commits: git diff master..head --no-merges
  • Use gui to only show your commits: git difftool master..head --no-merges
  • Run git stat against two branches: git diff --name-status master..head
  • Unstage a single file: git reset HEAD <file>
  • View a single file in a given commit: git show <commit>:<path>
  • Reset a single file to a given commit: git reset <commit>:<path>
  • GitX gui; handy for live editing staged changes
  • Determine if branch exists on remote repo: git log <repo name>/<branch name>

VMWare

  • Mac host, Windows vm network set up:
    1. Set Virtual Machine > Network Adapter to NAT
    2. Get host machine IP via ifconfig (under en0)
    3. In windows, edit C:\Windows\System32\drivers\etc\hosts to point localhost at the host machine IP
  • How to get the ip address of the vm:
    1. launch vmware
    2. launch os in vmware
    3. run cmd (windows) to get terminal
    4. run ipconfig to get the ip address of the machine

General Mac

General Unix

  • Show 3 lines of context w/ grep: grep -a3 action, eg gem list -d | grep -a3 action
  • Re-use the last argument in bash: !$, eg mkdir /foo/bar/baz; cd !$
  • dig can help w/ DNS debugging: dig example.com
  • find file fancy_file.js in current directory: find . -type f -name 'fancy_file.js'

Fonts

Security

  • Sanitize all input from end-users to reduce XSS and DB corruption risks
  • Sanitize all content sourced from end-users prior to display to reduce stored XSS risk
  • Validate all actions affecting privated data to reduce risks to session-fixation
  • Use dynamic config for secure settings
  • Enumerate all 3rd-party assets hosted on example.com
  • Build kill switch into features, so we can turn off compromised product w/o waiting for fix; works well w/ fail-to-zero pattern
  • 2011 CWE/SANS Top 25 Most Dangerous Software Errors: http://cwe.mitre.org/top25/index.html

Performance

General software development

  • Plug two keyboards into macbook pro for super easy pair programming
  • Maintain wiki page for each proj and link to it in code comments
  • Maintain run book for all services
  • Establish code conventions to avoid style-related arguments
    • Strip trailing whitespace, which clutters diffs
    • Use spaces instead of tabs where applicable for consistent formatting across editors
  • Nice git-based flow:
    • each feature has corresponding branch, wiki, throttle key, shortcut url, tracking ticket, reviewboard, etc
  • Docs
    • file-level comment block at the top of files
    • module description in a readme file in the module directory
    • project description in a readme file in the project root
    • cookbook in howto file in project root
  • Name variables to be passed into function to match the function arg names
  • Hudson for CI http://hudson-ci.org/
  • Algorithms for Interviews: http://www.algorithmsforinterviews.com/

Architectural patterns

  • Fail to zero: a service designed for throttling down to zero eg a web app that guarantees at least a static page
  • ? help menu: the '?' key command launches help menu eg gmail github twitter
  • Using tilde for home, ie '/~' instead of '/home'. See paper.li and linkedin

Interviewing

  • Typewithme for live code editing http://typewith.me/
  • Collabedit for live code editing http://collabedit.com/ w/ syntax highlighting
  • Ask combo of:
    • high-level explanatory skills, eg (~5):
      • useful tools
      • describe your most recent project and sketch the organization on the whiteboard
      • what are you looking forward to in CSS3? HTML5? Some other lang?
    • nitty-gritty (~15), eg:
      • change the binding of this element in a jQuery callback
      • target CSS for certain browsers
      • demonstrate two approaches for inheritance in JS
      • calculate the complexity of a given block of code
    • integration, eg (~25):
      • implement a simple button click handler
      • implement a router in JS or Ruby
      • implement a mocking tool for JS testing
  • Check for dogmatism, eg "Is there any other way of doing this?", "What do you think about using another language?", etc
  • Check for debugging awareness, eg "Can you see any problems w/ this approach?"
  • Check for performance awareness, eg "Suppose you had to run this operation thousands of times. What are some issues you might run into, and how would you address them?"

API status

Twitter tools

  • twitter counter
  • isfollowing
  • tweetstats
  • favestar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment