Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
egrueter-dev / date_cheatsheet.rb
Last active August 29, 2015 14:19
Ruby Date Cheatsheet
Date.parse(purchase.charge.charge_date).strftime("%B")
Date (Year, Month, Day):
%Y - Year with century (can be negative, 4 digits at least)
-0001, 0000, 1995, 2009, 14292, etc.
%C - year / 100 (rounded down such as 20 in 2009)
%y - year % 100 (00..99)
%m - Month of the year, zero-padded (01..12)
@egrueter-dev
egrueter-dev / n_plus_one.rb
Created April 22, 2015 22:14
Eliminating N+1 Queries
@purchases = current_user.purchases.includes(:charges)
#loads the charges for a particular user's purchases into memory, when you
#call the below code, the application does not need to go back to memory...
current_user.purchases.charges
@egrueter-dev
egrueter-dev / emberajax.js
Created June 13, 2015 18:34
Making an Ajax request from an ember component. Had to set async to false in order to store the data in a persistent manner. Good to know.
export default Ember.Component.extend({
//....//
newClass: function() {
var result;
Ember.$.ajax({
url: '/api/surveygizmodata/1',
import Ember from 'ember';
export default Ember.Route.extend({
model: function (params) {
return Ember.RSVP.hash({
school: this.store.find('school', params.school_id),
// data: Ember.$.getJSON('api/surveygizmodata', { school_id: params.school_id }
@egrueter-dev
egrueter-dev / example.js
Created May 27, 2016 01:18
Execution Stack Example
var a = “first variable”;
function myfunction () {
var b = “ second variable”;
console.log(b);
}
console.log(a)
myfunction();
@egrueter-dev
egrueter-dev / example2.js
Created May 27, 2016 01:24
Execution Stack Example with Notes
var a = “first variable”
function myfunction () {
///// myfunction execution context
var b = “ second variable”;
return console.log(b);
/////
}
console.log(a) //=> ‘first variable’
var a = “first variable”;
function myfunction () {
var b = “ second variable”;
console.log(b);
}
console.log(a) // => ‘first variable’
myfunction(); //=> ‘second variable’
function b() {
console.log(myvar);
}
function a( ) {
var myvar = 2
b( );
}
var myvar = 1;
function a( ) {
var myvar = 2
function b() {
console.log(myvar);
}
b( );
}
var myVar = 1;
function b() {
console.log(myvar);
}
function a( ) {
var myvar = 2
b( );
}
var myvar = 1;