Skip to content

Instantly share code, notes, and snippets.

View gbrl's full-sized avatar

Gabriel Rambert gbrl

  • Earth
View GitHub Profile
@gbrl
gbrl / js
Created April 11, 2018 17:10
$(document).ready(function(){
console.log("Document is ready.");
$.ajax({
type:"GET",
url:"https://grantstraining.arts.on.ca/ex/ex_openreport.jsp?xml=1&export=1&key=&token=%40GwoGSx4eeFtZRRVfSRxSS1NUbVF8EnVo",
dataType:"xml",
success:function(xml)
{
console.log("Success");
$("#outputdiv").html(xml);
@gbrl
gbrl / Gemfile
Created October 15, 2016 05:07 — forked from slothelle/Gemfile
Deploying Rails 4 apps with Resque and Redis to Heroku using Unicorn with a Procfile.
# and whatever other gems you need
gem 'resque', '~> 1.24.1'
gem 'unicorn', '~> 4.6.2'
CREATE TABLE users (
phone char(13),
active boolean,
frequency integer,
news_weight integer,
entertainment_weight integer,
facts_weight integer,
romance_weight integer,
);
function arrayOfLight(num){
var arr = new Array(num+1).fill(0);
return Object.keys(arr);
}
console.log(arrayOfLight(8));
array = [6,5,3,1,8,7,2,4]
pairs = []
new_pairs = []
newer_pairs = []
# BUILD PAIRS
(0..array.length - 1).step(2).each do |index|
new_pairs << [array[index],array[index+1]]
end
SQL EXERCISES
1.
select isbn
from editions as e
join publishers as p
on (e.publisher_id = p.id)

"Ruby's self keyword"

Inside a class definition, if you define a method starting with "self." you're creating a method that can be called on the class itself, not on an instance of that class. Example:

class Contact
  def self.all
    # returns an array of all contacts
  end

end

Classical Inheritance in Ruby

For programmers who are new to Object Oriented Programming, the ideas behind classical inheritance can take some getting used to. This article walks you through the syntax of defining class inheritance in Ruby with explanations of each OOP feature along the way. You will have created many inheriting classes and used them in Ruby code by the end of this exercise.

Create a new Ruby code file and copy the code examples into it as you go. Run the file with the provided driver code and read the output. Try writing your own driver code to try things out new concepts as they're introduced.

require 'pp'
# Determine whether a string contains a SIN (Social Insurance Number).
# A SIN is 9 digits and we are assuming that they must have dashes in them
def has_sin?(string)
!!(string =~ /[ ]\d{3}-\d{3}-\d{3}$/)
end
puts "has_sin? returns true if it has what looks like a SIN"
puts has_sin?("please don't share this: 234-604-142") == true
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26