Skip to content

Instantly share code, notes, and snippets.

View courtneyphillips's full-sized avatar

Courtney Phillips courtneyphillips

  • Datadog
  • Portland, Oregon
View GitHub Profile
@courtneyphillips
courtneyphillips / controller.rb
Last active March 15, 2016 17:19
Example controller, view, schema and routes for including upvote/downvote functionality in Ruby on Rails.
def upvote
@item = Item.find(params[:id])
@item.upvotes += 1
@item.save
redirect_to items_path
end
@courtneyphillips
courtneyphillips / controller.rb
Last active March 15, 2016 17:17
Live-sorting via link in Rails.
def index
@reviews = Review.order(params[:sort])
end
@courtneyphillips
courtneyphillips / Gemfile
Last active March 15, 2016 17:21
Bootstrap popovers in Rails
gem 'bootstrap-tooltip-rails'
//ADDITIONAL OPTIONS & DOCUMENTATION
http://getbootstrap.com/javascript/#popovers
@courtneyphillips
courtneyphillips / Code Review
Last active February 18, 2016 16:20
Sample code provided for Epicodus Level 2 JavaScript Modern JS Apps Code Review
// index.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="js/git-interface.js"></script>
<title>Githupdates</title>
</head>
<body>
</body>
@courtneyphillips
courtneyphillips / component.js
Last active March 15, 2016 17:20
Example Google Maps component in Ember.js with multiple markers with corresponding unique info windows.
showMap(foodcarts) {
this.set('mapShowing', true)
var coordArray = [];
var contentArray = [];
var markerarray = [];
foodcarts.forEach(function(foodcart) {
coordArray.push([foodcart.get('latitude'), foodcart.get('longitude')]),
contentArray.push([foodcart.get('name'), foodcart.get('website')])
});
@courtneyphillips
courtneyphillips / Terminal
Last active March 15, 2016 17:18
Installing Ember on Epicodus Machines
From Home Directory, in the following order:
$ brew update
$ brew upgrade node
$ npm uninstall -g ember-cli
$ npm cache clean
$ bower cache clean
$ npm install -g [email protected]
@courtneyphillips
courtneyphillips / some-component.js
Last active February 25, 2016 22:44
Ember computed properties in components
//in component
import Ember from 'ember';
export default Ember.Component.extend({
sortProperties: ['date:desc'],
sortedAnswers: Ember.computed.sort('comments', 'sortProperties'),
actions: {
...
}
@courtneyphillips
courtneyphillips / model.js
Created March 11, 2016 17:55
Ember.js computed property averaging value on `hasMany` Firebase relationship in model.
//this is the model for an object that has many reviews. reviews each contain a score. the averageScore property below gathers
// all reviews, sums all scores from all reviews, and divides by the number of reviews to calculate an average score.
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
reviews: DS.hasMany('review', {async: true}),
...
@courtneyphillips
courtneyphillips / sample-component.js
Last active March 11, 2016 17:59
Using .intersect functionality of Ember Computed Properties in component
import Ember from 'ember';
export default Ember.Component.extend({
selectedSkills: Ember.inject.service(), // <-- service containing an array of objects.
selected: Ember.computed.alias('selectedSkills.skills'), // <-- giving 'selected' nickname to this array of objects within service.
skillsInCommon: Ember.computed.intersect('selected', 'project.skills'), // <-- returning only the objects present in both the service's array and in 'project.skills' (current model where this component is being called?)
});
@courtneyphillips
courtneyphillips / somefile.js
Created March 15, 2016 17:15
Async API Calls in Node Modules
// Because the ajax request is asynchronous, cannot assign data from api response to a variable in the success
// callback and return it, because the return statement will execute before the success function is completed.
// Instead, logic must happen inside of the success callback function.
// This can either mean using jQuery to directly display the response:
exports.getHumidity = function(city) {
$.get(url).then(function(response) {
$('.showWeather').text("The humidity in " + city + " is " + response.main.humidity + "%");
}).fail(function(error) {