Programmer's Little Helper

Sometimes we need to hit CTRL+R


Falling

Click arrow to expand description

Git

How to make changes in a Git repo

git status

Lists all new or modified files to be committed

git add [file]

Snapshots the file in preparation for versioning

git reset [file]

Unstages the file, but preserve its contents

git diff

Shows file differences not yet staged

git diff --staged

Shows file differences between staging and the last file version

git commit -m "[descriptive message]"

Records file snapshots permanently in version history


Ruby

# Comment text

Comments the text, Ruby will ignore everything that is marked with #.

variable = some_value

Declare a variable.

puts text

Prints the argument to the console with new line.

object.method(arguments)

Calling a method on object that accecpts an argument. It may also not require an argument.

def name(parameter)
method body
end

This defines a new method that accepts a parameter.

CONSTANT = some_value

Like a variable but has a known value that should never change and always refer to the same value.

"A string and and an #{expression}"

Combines a string with a variable or Ruby expression.

string[position]

Access the character the given position. Index is set at 0.

array[position]

Access the position in an array, Indexed at 0.

array << element

This pushes element into the bottom of the array.

array.each do |e| .. end

Iterates over the array. Each element is the assigned the element 'e'.

{key => value}

Key value pair in hashes. Easy memory trick. Think of a grocery list, the fish is the key and salmon is the hash (or value assigned).


JavaScript

// Comment text

Comments the text, JavaScript will ignore everything that is marked with //.

console.log(text)

Prints 'text' to the console.

for ([initialization]; [condition]; [final-expression])

The for loop syntax. Useful for iteration.

for (variable in object) { .. }

For..in statement iterates over the enumerable properties of an object.

var i = x

Declare a variable with the 'var' and set it equal x.

function greet(name) { .. }

Create a function. Functions are built for a singular piece of recurring logic. Accepts argument.

var obj ={}

JavaScript objects, similiar to Ruby Hashes..see above

if (condition == condition) { ..} else { .. };

If/else statement syntax. If conditions are met the code executes else moves on to next argument.

condition ? example1 : example2

Ternary operator. Operates the same as an if/else statement with boolean operator.

Math.random();

Generates a random number from 0 to 1. Math.floor will round integer down. Math.ceil will round up.