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
var o = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: { | |
a: 5, | |
b: 6 | |
} | |
}; |
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
#!/usr/bin/env ruby | |
# More often than not at @RTR_tech, our ruby layer is a pass-through from our | |
# services to our client application. In those cases, it doesn't make much | |
# sense to parse the JSON string. | |
# | |
# Other times, however, we want to work with the objects that come back, so | |
# like good ruby developers, we create classes which reflect the data we | |
# expect, but as an intermittant step, we convert the JSON to a Hash, which | |
# we convert to an object. |
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, |
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
# 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
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
// 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
# 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 |
OlderNewer