Skip to content

Instantly share code, notes, and snippets.

View eduardopoleo's full-sized avatar

Eduardo Poleo eduardopoleo

View GitHub Profile

Create Topic, Reply Topic, Comment on Reply, Mention someone

  {
    "type": "cause",
    "attributes": {
      "userName": "Hello greg",
      "actionText": "posted a topic",
      "timeStamp": "2016-05-05T13:39:17Z"
    }
```ruby
def all_uniq2?
length = self.size - 1
# what's the efficiency of this
for i in 0..length
break if i == length
for k in i+1..length
return false if self[i] == self[k]
end
end
@eduardopoleo
eduardopoleo / npm_versioning.md
Last active May 30, 2016 18:19
npm versioning

Commit changes and then:

git push 
npm version patch
npm publish --access public
git push —tags

current version is on package version When having problems when the versioning

class DummyClass
attr_reader :text
def initialize(some_text)
@text = some_text
end
def present
puts text
end
<thead>
<tr>
<td><a href="LinkToFirstPage">First Page</a> </td>
<td>
<a href="LinkToPage1">1</a>
<a href="LinkToPage2">2</a>
<a href="LinkToPage3">3</a>
<a href="LinkToPage4">4</a>
</td>
<td><a href="LinkToLastPAge">Last Page</a> </td>
#lib/tasks/scrape.rake
#Mechanize setup
require 'mechanize'
agent = Mechanize.new
#The starting point which corresponds to page 1
page = agent.get('http://www.fin.gov.on.ca/en/publications/salarydisclosure/pssd/orgs-tbs.php?year=2014&organization=universities&page=1')
#Extracts all the pagination links over which we are going to iterate
page_links = page.search("//thead/tr/td[2]/a")
#lib/tasks/scrape.rake
def salary_averages(staff, use_case)
universities = staff.map{|p| p.university}.uniq
data = []
universities.each do |university|
university_staff = staff.select{|s| s.university == university}
average_salary = (university_staff.map{|p| p.salary}.reduce(:+)/university_staff.count).round(2)
Average.create(
#averages_controller.rb
class AveragesController < ApplicationController
#Uses the use_case flag to query for the correct type of averages
def all_salaries
@data = Average.where(use_case: "overall_salaries")
respond_to_block
end
def professors_only
@data = Average.where(use_case: "professors_only")
#routes.rb
root 'staff#vertical'
#Main route where we are going to bootstrap our application
get 'vertical' => 'staff#vertical'
#Routes where we are dumping the JSON data.
get 'all_salaries' => 'averages#all_salaries', defaults: { format: 'json' }
get 'professors_only' => 'averages#professors_only', defaults: { format: 'json' }
get 'administrative_staff' => 'averages#administrative_staff', defaults: { format: 'json' }
<!-- views/staff/vertical.html.erb -->
<%= form_tag() do %>
<%= radio_button_tag(:average, "all_salaries", true, class: 'choice') %>
<%= label_tag(:average_all_salaries, "All Salaries") %>
<%= radio_button_tag(:average, "professors_only", false, class: 'choice') %>
<%= label_tag(:average_professors_only, "Professors Only") %>
<%= radio_button_tag(:average, "administrative_staff", false, class: 'choice') %>
<%= label_tag(:average_administrative_staff, "Administrative Staff") %>
<% end %>