Skip to content

Instantly share code, notes, and snippets.

@eddroid
Last active January 19, 2016 21:33
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 eddroid/4c6a5add1c16006d3d69 to your computer and use it in GitHub Desktop.
Save eddroid/4c6a5add1c16006d3d69 to your computer and use it in GitHub Desktop.
The Same Thing Over and Over

Scope

Think of a telescope. As it extends right, it gets smaller.

__
|| __
|| || __
|| || || 
|| || __
|| __ 
__

Ruby Variable Scopes

As you go right, the scope of the variable gets smaller.

$global_var -> @@class_var -> @instance_var -> local_var

JavaScript Variable Scopes

window.globalVar; -> var functionVar;

Rails Model Scopes

As you go right, the scope of the Users returned gets smaller.

User.all -> User.all.where(active: true) -> User.all.where(active: true).where(cohort: 5) -> User.all.where(active: true).where(cohort: 5).limit(2)

Using named scopes

User.all -> User.all.active -> User.all.active.in_cohort(5) -> User.all.active.in_cohort(5).limit(2)

Nested URL Scopes

As the URL grows longer, it becomes more specific.

  • Show all users: http://localhost:3000/users
  • Show one user: http://localhost:3000/users/1
  • Show one user's articles: http://localhost:3000/users/1/articles

Wildcard (*)

The asterisk (*) always matches everything.

Bash

The command will effect every file in the current directory.

ls *
rm *
cat *

SQL

Select every column from the users table.

SELECT * FROM users;

Optimizing Keystrokes

The strategy of increasing productivity by optimizing keystrokes. This is usually creating convenient, short-named methods (or functions) for common operations, but it can be as simple as using nil over null.

Metalangauges

Langauges that requires fewer keystrokes to generate a language that requires more.

  • HAML, SLIM
  • CoffeeScript
  • SASS, SCSS

BASH Aliases

Shortcuts for longer BASH commands.

alias gd='git diff'
alias gc='git commit'
alias gco='git checkout'
alias gb='git branch'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment