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
// Log DB Queries | |
// *** Warning, this does not capture calls to the Meteor-defined | |
// /<Collection>/<action> methods, which don't seem to be heavily utilized in | |
// this project. | |
import { Mongo } from "meteor/mongo"; | |
// import { MongoInternals } from "meteor/mongo"; | |
import { Logger } from "/server/api"; | |
export const Colors = { |
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
// It happens all the time: you have some data, you want to update | |
// a key without modifying the original object. You typically end | |
// cloning the original with Object.assign({}, originalObject), | |
// then adding your new data. This is probably pretty fast, even | |
// for objects with many keys, but doesn't it seem unnecessary? | |
function applyNewData(sourceData = { abc: 123, def: 456 }) { | |
const newData = { abc: 789 }; | |
// Previously, we'd write: |
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
# simple class to contain the id and value of a transaction | |
class Transaction: | |
def __init__(self, id, value): | |
self.id = id | |
self.value = value | |
def __add__(self, other): | |
return self.value + other.value | |
# readable output |
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
// to increase readability and to allow for more sane and detailed | |
// commenting, I prefer to break up complex conditional statements | |
// into separate statements in a separate function, using `return` | |
// to short-circuit when a condition has failed | |
///////////////////////////////////////////////////////////////// | |
// as an alternative to combining the condition and the behavior: | |
// ❌❌❌ | |
function render() { | |
if ( |
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 App < Sinatra::Base | |
get '/users' do | |
User.all.to_json | |
end | |
post '/users' do | |
User.create!(params) | |
204 | |
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
# Original Code | |
class App < Sinatra::Base | |
get '/users' do | |
User.all.to_json | |
end | |
post '/users' do | |
User.create!(params) | |
204 | |
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
# Original Code | |
class App < Sinatra::Base | |
get '/users' do | |
User.all.to_json | |
end | |
post '/users' do | |
User.create!(params) | |
204 | |
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
# Original Code | |
class App < Sinatra::Base | |
get '/users' do | |
User.all.to_json | |
end | |
post '/users' do | |
User.create!(params) | |
204 | |
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
// convert numbers to ordinal versions of themselves | |
// {{ 1 | ordinal }} : "1st" | |
// {{ 2 | ordinal }} : "2nd" | |
// {{ 3 | ordinal }} : "3rd" | |
// etc. | |
angular | |
.module("app", []) | |
.filter("ordinal", function () { | |
var suffix = ["th", "st", "nd", "rd"]; |
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
/* | |
let's say you are trying to inflate a Backbone Collection | |
using some endpoint which returns data in non-array form. | |
maybe, | |
*/ | |
{ | |
meta: { | |
total: 25, | |
pageSize: 3, |