DSA key

  • Today I was given a DSA private key by a job application, and a git ssh address that looked like:  git@github.com:username/reponame.git
    • the top of the DSA file looked like:  -----BEGIN DSA PRIVATE KEY-----
  • What I did:
    • navigated to my ~/.shh  directory
    • made a id_dsa extension-less file, and pasted in the body of the DSA private key
    • changed permissions to -rw-r--r-- via: sudo chmod u+w id_dsa and sudo chmod ugo+r id_dsa
    • ssh-keygen -y -f id_dsa >> id_dsa.pub
    • and suddenly, I had access to the git repository
      • git remote add origin git@github.com:username/reponame.git
    • Then, as instructed later, I sent a post request, netcat, ruby RestClient, and telnet didn’t work as expected, so I did it with straight JS
Advertisements

Week05 Day06&07

  • The node package for sublime
    • Installed the Nodejs package with the sublime text 2 package manager
    • Edited my: ~/Library/Application Support/Sublime Text 2/Packages/Nodejs/Nodejs.sublime-build to include the line:
      • "path" : "/usr/local/bin",
      • (gotten from running which node in the terminal)
    • Also edited my: ~/Library/Application Support/Sublime Text 2/Packages/Nodejs/Nodejs.sublime-settings from
      • "node_command": false,
      • TO
      • "node_command": "/usr/local/bin/node",
      • UPDATE: a week later, these 2 settings got cleared. Popup window for code execution would not work without the additional line: "node_path": "/usr/local/bin/", being added to: ~/Library/Application Support/Sublime Text 2/Packages/Nodejs/Nodejs.sublime-settings
    • Then, was able to press ^R to see the results of my code (traditional cmd+B does not return errors anymore, but also does not print the results of the code)
    • I also installed sublime linter and jslint to get some really nice syntax highlighting (jshint does the same thing, and has more useful error messages)
      • Screen Shot 2013-07-20 at 2.53.19 PM
    • More stuff

Course Week02 Day04&05

  • array.concat(array) is the same thing as adding two arrays together
  • moves to test jumping over in checkers
    • 23&32&56&45&25&34&45&23&12&34&65&56&32&41…
  • Rake
    • RSpec::Core::RakeTask.new(:spec) do |t|
      • symbol will be the name of the task, RSpec provides a configuration object t
      • can then specify pattern of files it should run (i.e. location of the files)
      • and you will also be able to specify the default task when you call rake without any args
  • RSpec
    • mock - double("obj_name") – blank state, a stub with an expectation that the method gets called
      • should_receive(:meth_to_be_run).with(specific_parameter)
        • can also add a and_return() 
        • should_receive(:bleh).exactly(3).times
    • stubcanned answers made during a test, and can record information about calls, returns a specified result. should be within a spec or a let statement
      • dog.stub(:meth_name).and_return(true)
      • if  is a stub, and you call x.as_null_object on it, from there on, no matter what method(s) are called on x, it will return self (Mock object)
        • use this feature in cases where object interaction is incidental
    • unit tests – mocks (behavior verification), specific and narrow
    • integration tests – real objects, large scope
    • let does not persist between different specs
    • stubbing:
      • name = stub(:name_given_to_stub, one: 1, two: 2)
        • will allow name.one to return 1 and so on
        • naming the sub is optional
      • let(:name) { double(“for_self_reference”) }
      • cat.encounter_dog(obj)
    • DRY tips
      • before's brother: after(:each)
      • shared examples:
        • can go at the top of the spec file: shared_examples_for 'ex_name' { code here }, call it later with:  describe Thingy { it_behaves_like 'something' }
        • or can go into the spec/support/ directory and create a shared_examples_for 'something' { code here on subject }
          • alternatively, the shared example can take an argument, which you can pipe as the subject in the spec/support/ and then call with an extra argument in the spec
      • can add tags to contexts, and specify tags when running the specs
        • can add a slow: true tag, and filter those out when running most of the time:
          • rspec --tag ~slow spec/lib/zombie_spec.rb
          • or change the spec/spec_helper.rb config file
      • have a context for each function inside of a class
  • Ruby Tests shortcuts again:
    • Command-Shift-R: run a single test
      • on either an it block or a describe block
    • Command-Shift-E: run the last test(s)
    • Command-Shift-T: run all the tests in current file
  • Postgres

SQL

  • foreign keys
    • storing links between elements when they are not attributes of a single thing (relating posts to the users that created them)
    • the foreign key in one table will reference the primary key in another table
    • usually name the column of the foreign key after the name of the other table plus an _id suffix
  • anatomomy of query execution:
    • database connection » query optimizer (chooses efficient execution plan) » result set (temporary table)
      • db connection is held until request app releases it, or server shuts down
  • SELECT DISTINCT this_column, 'new_value' nonreal_column FROM this_table
    • asking for a nonexistent column will show a nameless one filled with the nonexistent name you specified, alternatively you can precede it will a value to fill that column name
    • if you are not retrieving any data from tables, and are just executing built in functions, you don’t even need a FROM
    • DISTINCT removes duplicates (ALL is the automatic default), can be very slow for large datasets since data needs to be sorted
    • The tables that SELECT come in different flavors (permanent, temporary, virtual – from CREATE VIEW view_name AS)
      • FROM doesn’t have to take a permanent table
      • could take a table returned from a subquery
        • put the subquery in parentheses, and follow it with an alias after the parentheses
          • this could be a single letter e, that the main query then references like: e.column_name
      • could take a view/virtual table
        • a query stored in the data dictionary, which acts like a table but holds no data itself, just references
        • can be used to hide columns
    • can also handle multiple tables, in which case the link/joining technique needs to be specified
    • WHERE is for filtering rows in raw data, use AND OR NOT and parentheses
      • takes basic operators plus: <>, LIKE
        • column_name IN ('desired_row_value_1', 'desired_row_value_2')
          • also works with NOT
        • column_name IN ( subquery )
        • BETWEEN lower_inclusive AND upper_inclusive
        • LEFT(column_name, 1) = 'T' to find all the rows starting with the letter T
        • LIKE with wildcards: for one character, for zero or more characters
        • use for regex matching
        • IS NULL for nonexistent or empty values
    • GROUP BY will group data by column values, and in that case use HAVING to sort the data
    • ORDER BY can take the
      • DESC parameter (ASC is the default)
      • LIMIT with a number of rows
      • RIGHT(column_name, 3) to extract the last three characters of some column
      • can reference the columns already specified in the SELECT query: ORDER BY 2,  5 to sort by the 2nd and 5th columns specified earlier
  • Joining
    • select * from table_one o INNER JOIN table_two t USING (column_in_common)
      • same as: select * from table_one o INNER JOIN table_two t ON o.column_in_common = t.column_in_common
    • useful to join a table to itself when there is a self referenciung foreign key (it includes a column that points to the primary key within it)

Course Week02 Day02

We were warned that this was the calm before the storm, that taking a couple not too tense days to build a functional Human vs Human chess game would be the last project focussed on developing out object oriented skills. So, I’m excited to start learning about RSpec, SQL, Javascript, and many other technologies soon, but I am also enjoying the design of our chess game. We’re starting to see all the benefits of atomizing methods, having clear classes, and putting in play all the Ruby tricks we’ve learned. I also feel like I’ve finally started to get the hang of recursion, writing recursive methods in a way that makes use of their returns rather than them passing around arguments.

Course Week02 Day01

Today, we continued to work on our atomization of methods and DRYing out by making an interactive minesweeper game. Approach was pretty similar to the hangman game, and it didn’t come too hard thanks to past experience. Something to check out in the future is using UTF-8 characters for prettier displays of arrays and game boards. We also went over some etiquette for git commits, which should be in present tense. We were introduced to JSON and YAML formats, and the YAML came in handy for saving ruby objects for access later. Also did the first code review today. Seems like other pairs have very similar approaches, and differences are largely in the little things, like favorite go-to methods for common tasks or naming patterns.

Tidbits

  • can do puts or var assignment before a ternary operator
  • arrays of arrays: Array.new(3){["a"]*3}

Course Week01 Day05

Made it throught the week!

  • Custom indexes when iterating through an array:
    • [:foo, :bar, :baz].to_enum.with_index(1).each do |elem, i|
  • Depth vs breadth first searching
    • if you have a tree-like structure, and are filling an array with the children of nodes…
      • you may use that array as last in, first out (stack), maybe with pop , to do a depth first search
      • or, you may use that array as first in, first out (queue), maybe with shift, to do a breadth first search
  • counterpart of the any? enumerator is none? , good for when you need to make sure say, that no items in an array are divisible by 5
  • When you have a method that may take a block, its very slick to use a default block with the ||= notation instead of using if block_given?

Git Weekend

  • Orienting yourself
    • git diff will show specific information about differences between committed and unstaged changes (git diff --staged to get difference between commited and staged)
    • can compare anything: git diff HEAD^^ or git diff HEAD~5 or git diff HEAD^^^..HEAD^ or name the SHAs, or name the branches (no dots required in this case), or time ranges with –since
    • git blame filename
  • Unstaging
    • since HEAD refers to last commit on current branch/timeline
      • git reset HEAD filename to unstage
    • restore a file to its previous state
      • git checkout -- filename
        • the -- is needed to ensure so that you don’t checkout a branch accidentally
  • shortcuts
    • git commit -a -m "comment" will add and commit tracked files
    • git checkout -b branch-name
    • might want to make an alias: git config --global alias.alias_name \ "git command" or short two letter-like ones like: git config --global alias.st status
  • Regret a commit? (Don’t do this if you’ve pushed already)
    • reset, move to commit before HEAD (note the caret), want to move further back? Add more consecutive carets
      • git reset --soft HEAD^ rewinds
      • git reset --hard HEAD deletes
    • amend, with an optional message to override the last
      • git commit --amend -m "new comment"
  • Branches/Merging
    • after merging a branch to the master, it’s possible to delete the old one
      • git branch -d branch-name
      • won’t work if there are unmerged commits there, need -D instead of -d
    • if it isn’t a fast forward merge
      • recursive merge
        • happens when there have been changes on the master branch after an aux branch was made, before it was merged
        • git makes a merge commit automatically when merging (visible in log, but doesn’t list any files)
    • two people have worked at the same time from a remote repo, person1 has already pushed, person2 wants to push too, but will be rejected with the simple git push. Solutions:
      • git pull && git push
        • will make a merge commit in log (happens often, can get messy, avoid with rebase)
      • OR: checkout to the aux branch, then:
        • git rebase master to add master branch commits onto that aux branch
        • then checkout to master, and do a fastforward merge
    • two people have worked on the same file at the same time, person1 has already pushed
      • person2 will fail to git pull, and will see the merge conflict in git status
      • manually edit the file (your own edits will be under HEAD), git commit -a (merge commit in log), then git push
      • OR, rebase style:
        • git fetch and then…
        • git rebase
          1. moves changes to master which are not in origin/master to a temporary area
          2. runs all the origin/master commits, one at a time
          3. runs all commits in the temporary area. Conflicts will result here
        • when running into conflicts, can manually fix those, and add them, then run git rebase --continue , you’ll notice at this point (git status) that you’re not on any particular branch
    • git branch -r will list all the remote branches (that you got with git pull)
      • you can checkout to these branches
      • can get more information on branches with git remote show origin
    • if someone has deleted a remote branch that you have been working on,  and you try to push
      • you will see “Everything up to date”
      • git remote show origin will show its “stale”
      • git remote prune origin removes stale references
  • Sharing remotely
    • git remote add origin http:
      • bookmarking, giving the name origin to a remote branch (but could technically give any name)
      • can add multiple remotes
      • git remote -v will show remote repositories (-v for verbose)
    • Deleting
      • to remove remote repo: git remote rm name_of_remote
      • git push origin :name_of_remote_branch to delete remote branch
    • git pull
      1. Fetches/syncs local repo with remote one (same as git fetch). This doesn’t update any local code
      2. merges origin/master (i.e. remote) with master (i.e. local), (same as git merge origin/master), code modification happens here
    • git push -u remote_repo_name local_branch_name
      • the -u flag saves the remote repo and local branch for the next time you push
      • git push itself updates the origin/master branch
      • can push any branch this way
    • Cloning
      • can pass in a name when you clone, otherwise takes the name it had in the repo
      • automatically adds the origin remote with the url you cloned from
      • automatically checks out the initial branch
    • Excluding files
      • add it as a line in .git/info/exclude
      • can use patterns: *.mp4
      • use a .gitignore file, which contains lines like: logs/*.log
      • Untrack
        • git rm --filename (doesn’t affect working directory)
  • Tagging
    • work as references to commits
    • git tag to show all
    • git tag -a tag-name -m "tag description"
    • git push --tags must be used to push tags
    • can git checkout tag-name to checkout to a commit with a certain tag
  • Heroku
    • heroku create gives ssh address, and adds a remote repo (called heroku)
    • only deploys branch named master. git push heroku-staging local_branch:remote_branch (remote_branch should be master)

Course Week01 Day04

Today was all about writing well organized code. Atomizing methods, and making sure classes don’t have method envy with each other, and making sure changes in one class doesn’t change the functionality of another, even if one’s dependent on the other.

Tidbits:

  • having a method that takes a &block as an argument and the does: block.call(stuff) in its body is doing the same thing as a method that yield(stuff)
  • $PROGRAM == __FILE__  is the same as $0 == __FILE__
  • when writing a class and needing to pass around data
    • use an instance variable if that data never changes during the object’s lifetime
    • pass it as an argument if it changes
    • alternatively – make factory methods that act as instance creators
      • have class methods that create instances of a class that store information
  • using a regex to match a string is powerful because it can match on length and content:
    • /^.{7}$/ would match strings that are 7 characters long and don’t contain say dashes ( – ) or apostrophes ( ‘ )