Skip to content

Instantly share code, notes, and snippets.

RedSoxFan22

Block or report user

Report or block RedSoxFan22

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:72a572425f3bd0540027060ee9413cf2
Git/GitHub
Git is a version control system, a tool to manage all the different versions of your code. GitHub is an online hosting service for your git repositories.
When you start a project, you want to 1. create a file locally (in C9), 2. create a new repository in GitHub** 3. connect the two
That’s (mostly) it.
**Check out this 1-minute tutorial on how to create a new repo on GitHub: https://www.youtube.com/watch?v=LR5BYZjuXMU
View gist:f132c9e30480f517a775
Would you rather use RubyMine, vim, or Sublime Text? Why?
Of the three, I would rather use Sublime text because I am most familiar with it. However, I have used both Sublime and Atom, and of the two, I prefer Atom. However, I'm interested in trying RubyMine because of various features including Cucumber and Shoulda tests.
What is the difference between an INNER JOIN and a LEFT JOIN? INNER JOIN gets all records from one table that have some related entry in a second table
Which of these behaviors in a Rails app would require JavaScript? (you can pick more than one)
Scrolling down to a different part of the page (smoothly) when you click on a link in a menu.
Making the color of a background change over time.
View gist:2d1f5dcade2c33848d95
def all_permutations(array)
a = []
if array.length == 0
return [[]]
elsif array.length == 1
a << (array)
end
end
View Files
How to do Files on the web 10:25
We are working in the "public" folder
if we want to use something in the public folder, go to views/where you want it/html page you want it
<%= image_tag "name/png%>
all the files are accesible immediately on the root.
anything that's in public is available to anyone all the time
if there are images that should be seen only when logged in, you put them in the asset pipelime
public is where developers (not users) put images
files that users can upload:
View gist:90ba9e092b57e65f1e7b
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array as the first paramater and a number
# as the second parameter. Return true if two of the numbers in the array sum
# to the second parameter.
def complements(array, num)
if array.length < 2 || array.length == nil
false
View gist:c3d39d9cc2b4a2cc8c47
def primes(num)
array = []
1..num do |n|
array << n
end
array.reject {|x| if x.is_prime? = false }
end
def is_prime?(n)
if n % 2 == 0 && n % 3 == 0 & n % 5 == 0
View gist:fe6bc6f2480b3a3dbc97
function disableButton(){
var button = document.getElementById("submit");
setTimeout(function() [button.disabled = true;}, 1);
}
SQL
IN: let's you pass in multiple things. similar to Ruby include
removing N+1 queries is the best way to speed up runtimes
.joins:
AREL:
View gist:51aa674e2b10c48122e7
SQL the langauge we use to get information out of normalized date structures
Select clause tells you which
From clause tells you which
Where clause dictates which row you get back out
Answer.where(question_id=3).map &:response
Select * = select all is equivalent to .select(:response), but with the last one use and id otherwise you get back all the items, even if there are millions
View gist:ca35bb0a8341415cccfa
What command do you run if you want to discard all changes since your last commit? git checkout . There are three areas inside a repo: working directory(atom file), staging area, repository. Git checout takes what was in the repository and wipes it out. Git stash saves what you've done but removes them from the working directory.
Git stash pop: to get it out of the stack
Only use git stash if you want to get your code back.
Git reset --hard HEAD: HEAD is the last thing in the repository. Git reset hard is take the state of the repo and copy HEAD to staging area and working directory, and override the HEAD in those parts. -hard pulls it back 2 steaps. -mix and -soft as well
What command do you use if you run git add and then want to revert it? git reset --hard HEAD (HEAD is optional)
What command do you use if you run git commit and then want to revert it? git reset --hard HEAD ~1 (takes you back one step in time. any number will work. git revert won't work because it creates a new commit, but d
View June 17
What is a partial?
pieces of code in Views that are called upon in different places. its like a method for the views.
<%= render partial: "partial file name", locals:{parameters} %>
in JS, : goes inside of the "" like in "getShow('hoops');"
why code in the <script> tags on the html page?
control flow on a webpage.
when the application.js runs, there is nothing on the page. this isn't request/response like Ruby, it is event driven. the point in time in which events happen, matters. JS loads when the page loads
onclick is an html code.
You can’t perform that action at this time.