Skip to content

Instantly share code, notes, and snippets.

@MichaelCPell
MichaelCPell / link_to.rb
Created November 6, 2015 10:56
Differnet link to depending on class type.
@MichaelCPell
MichaelCPell / toc.js
Created November 6, 2015 10:49
Making a Table of Contents from H2's
// Step 1: Collect all of the H2's into a variable
$headings = $("h2")
// Step 2: Iterate through them and add some text
$.each($headings, function(index, value){
$("#toc-container").append("<li>" + $(value).html() +"</li>")
})
$("#timeofday").change(function(){
console.log($(this).text)
})
/*
*= require_self
*/
This expects an input like:
<select data-id=<%= ri.id %> ...other stuff...></select>
$(".some-input").change(function(){
var ri_id = $(this).data('id')
data = {
amount : $(this).val()
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
$.each($(".google-place"), function(index, value) {
var autocomplete = new google.maps.places.Autocomplete(value);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
window.foo = place
#sorting
def sort_by_length(array)
array.sort { |x, y| x.length <=> y.length }
end
def filter(array)
array.select { |v| v > 5 }
end
class UnitedStatesPresident
include Presidential
def self.citizenship
"The United States of America"
end
end
def hash_to_array(h ={})
a = []
h.each do |key, value|
a << key + value
end
a
end
class Calculator
def self.description
"Performs basic mathematical operations"
end
# def instance methods
# calc = Calculator.new(7,2)
# end
def initialize(x, y)