This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# customizing as_json with standalone JBuilder DSL | |
def as_json(options={}) | |
Jbuilder.encode do |json| | |
graffito = self | |
json.(graffito, :incident_address, :borough, :latitude, :longitude) | |
json.upvotes(graffito.upvotes.count) | |
json.upvoted_by(graffito.upvotes.pluck(:user_id)) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File activesupport/lib/active_support/json/encoders/hash.rb, line 33 | |
def to_json(options = nil) #:nodoc: | |
hash = as_json(options) | |
result = '{' | |
result << hash.map do |key, value| | |
"#{ActiveSupport::JSON.encode(key.to_s)}:#{ActiveSupport::JSON.encode(value, options)}" | |
end * ',' | |
result << '}' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#initialize a deck of cards and print out | |
#shuffle deck | |
class Deck | |
attr_reader :suits, :cards, :length | |
def initialize | |
@suits = ['Clubs', 'Diamonds', 'Hearts', 'Spades'] | |
@cards = build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
var counter = 0; // count number of posts received | |
var jsonURL = 'https://credentials-api.generalassemb.ly/explorer/posts'; | |
$('#load-more').click(function() { | |
var $loadButton = $(this); | |
$loadButton.prop('disabled', true); | |
$loadButton.html('Exploring the archive...'); | |
var $spinner = $('<i>', { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require node-flavored modules in the manifest | |
//= require jquery | |
//= require tether | |
//= require bootstrap-sprockets | |
//= require bootstrap-slider | |
//= require jquery_ujs | |
//= require turbolinks | |
//= require_tree . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "something", | |
"dependencies" : { | |
"browserify": "~10.2.4", | |
"browserify-incremental": "^3.0.1" | |
}, | |
"license": "MIT", | |
"engines": { | |
"node": ">= 0.10" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cell { | |
constructor(alive, x, y) { | |
this.alive = alive; | |
this.x = x; | |
this.y = y; | |
} | |
die () { this.alive = false; } | |
revive () { this.alive = true; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
# Configure Browserify to use babelify to compile ES6 | |
config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 ] ]" | |
# Run on all javascript files | |
config.browserify_rails.force = true | |
# Alternatively, only run on .es6 files | |
# config.browserify_rails.force = ->(file) { File.extname(file) == ".es6" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import Cell class | |
import Cell from './Cell.es6'; | |
class World { | |
constructor (cols, rows) { | |
this.cols = cols; | |
this.rows = rows; | |
this.cellGrid = []; | |
this.makeGrid(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "browserify-rails" | |
group :development, :test do | |
# Your choice of test library. | |
# Also available, teaspoon-mocha / teaspoon-qunit | |
gem "teaspoon-jasmine" | |
# Teaspoon's front-end is written in CoffeeScript but it's not a dependency | |
gem "coffee-script" | |
end |