Skip to content

Instantly share code, notes, and snippets.

@Abdenasser
Forked from charliegerard/WDI_1st_day.md
Last active August 29, 2015 14:21
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 Abdenasser/c718f83445f916ff538c to your computer and use it in GitHub Desktop.
Save Abdenasser/c718f83445f916ff538c to your computer and use it in GitHub Desktop.

Day 1 of WDI

Introduction to markdown

[markdown cheat sheet] (https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)

Download tool called Alfred to find applications / Spotlight.

Download iTerm as terminal if we want more customisation.


Some commands:

  • "top" in terminal shows everything that is happening in the computer atm - list of processes.

  • "q" exit top

  • "whoami" gives the name of who is using the computer

  • "pwd" prints the working directory

  • "cd" means change directoy

  • "pwd" going back to home directory - tells you where you are

  • "~ $ cd -" going back to folder you were in before

  • "clear" or Ctrl-L clears your screen

  • "open ." opens the finder to find files

  • "ls" lists the folders on the computer.

  • "rm -rf "filename"" to remove a file in a directory - if you do that, it can be retrieved. Otherwise "rm Folder/file"

  • "subl filename" opens in Sublime text.

  • "ls -l" : gives long format of the file.

  • man 'command' --> gives you documentation for particular command.

  • "-a" stands for all files.

  • "-al" / "-la" long listing

  • touch --> can also update the time you modified the file without having to open it and preteng you make a change.

  • "-u" assumes we always do it (git push -u origin master) always pushes it to the same server on github so we can just use 'git push' after.

  • git pull - pulls updates

  • 'git log' tells us what happened so far.

  • 'git diff HEAD' gives the difference with the previous version of the file

  • 'git reset' resets the doc to how it used to be --> remove from depository

  • CTRL-d --> get out of previous command

  • .to_i converts to integer

  • .to_s converts to string

  • .class gives the type of the variable

  • 'cat' or 'more' shows the content of file

  • 'less "nameoffile"' shows less

  • 'command + b' in Sublime text shows the ouput at the bottom of the window

  • '.length' gives you the amount of items in your array

  • '<< + "item"' adds an item to an array (An array can stock any time of item)

  • '.pop' -> gets rid of one of the item in an array (the last one)

  • '.push("name")' : adds an item at the end of the array

  • .to_f : to floating point

  • .round : rounds a float number.

  • .sort : sorts things alphabetically

Most useful commands:

  • cd - change directory
  • pwd - prints working directory
  • ls - lists files in directory
  • mkdir - creates directory
  • rmdir - remove directory
  • rm - remove files
  • touch - creates file

This is location based.

Directories

. current folder (ex open .) .. previous folder (ex open .. opens previous folder, goes back a folder). ../.. opens the previous folder of the previous folder (ex: users/charlieg/Desktop) goes back to users

ps : process

PID: process ID


If our computer is running slow, check "top" to see which one of the programs running has high CPU.

To stop a process from running, type "kill 'Process ID (PID)'".

In the terminal, if you dont want to tap the full name of a directory or file, type their first letters and press 'tab'. It should display the full name if you don't have anything else with a similar name.

Tips & tricks for command line [tips and trick] (http://quickleft.com/blog/command-line-for-beginners-part-1)

Files starting with "." are considered as secret files so don't show up when you look for it with ls.

Merlyn's git talk http://vimeo.com/35778382


Introduction to Ruby

Compiled language = you have to compile it to be able to launch the program.

Perl gave Python and Ruby

Mike Taylor (look up on github)

integer (5) / floating point numbers (5.0)

If we enter whole numbers in the console, it will return whole numbers but as long as we enter one of the numbers as decimal, it will display the decimal result (ex. 1/3)

-Strings have to use double quotes or single quotes.

-Boolean values are either true or false

-Putting a '' before a character tells the console to ignore the character (for single and double quotes)

-Concatenation: adding two pieces together

-puts = put string.

Everything in Ruby returns something (ex: 23* 7 => 161 : it returns the value 161) if we use puts 23 * 7 it display the value an returns nil cause it doesnt return anything

Ex: answer = puts 23 * 7 returns nil

Variable interpolation : interpolate variables into string by using #{}.

example = "#{quantity} #{items} at $#{price}"

"2+2 = #{2+2}" = 4

Numbers in Ruby can be as long as you need them to be. ex: 5 ** 5000

  • '.pop' -> gets rid of one of the item in an array (the last one)

  • '.push("name")' : adds an item at the end of the array

brothers.each do |bros| puts "#{bros} Marx} end

Familiarity.rb (https://gist.github.com/wofockham/021d9f2662d4f141b81a)

  • .to_f : to floating point
  • .round : rounds a float number.
  • .unshift :
  • .sqrt : returns the non-negative square root of a number.
  • .delete_at : delete the item on position 5.
  • .sort : sorts things alphabetically

(http://rubymonk.com)


Homework day 1:

  • Watch / Read up on Git / Github
  • Practice push to portfolio
  • Ruby Monk
  • Questions from pre-work

Extra

A string using single quotes cannot support interpolation.

.include?() : search if a string includes a certain word.

.start_with?() : checks if an string/array starts with a certain item. .end_with?()

.index() : finds the index for a certain character

.upcase , .downcase : changes the case of a string

.swapcase : swaps the case of every letter in the statement

.split() : splits the statement

.concat() : concatenate 2 strings, numbers, ...

<< : Using this symbol does the same thing as .concat() and + except that it actually modifies the string it is applied to instead of creating another version. (Important for memory utilization)

.sub() replaces within the string only for the first occurence.

.gsub() same as .sub() but for all occurences

Regular Expressions (RegExp) are always put between 2 /

Ex: 'RubyMonk Is Pretty Brilliant'.gsub(/[A-Z]/, '0') --> Replaces all capital letters with 0.

Ternary operator : If-then-else construct

In Ruby '?' and ':' can be used to mean "then" and "else" respectively.

We can create an array by typing '[]' or Array.new

To find values in an array, we can do as follow [1,2,3,4,5][2] which will return 3, but we can also start from the end of the array by using negative values. Ex: [1,2,3,4,5][-1] will give 5.

Method .map is used to apply a modification to the whole array.

.delete_if

.keys returns all the keys of an array .values returns all the values of an array

When using "return" in a method, no code is executed after it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment