Skip to content

Instantly share code, notes, and snippets.

View deanmarano's full-sized avatar
🦏

Dean Marano deanmarano

🦏
View GitHub Profile
@deanmarano
deanmarano / before.js
Last active August 29, 2015 14:15
Before Ember setter
handleLocationChange: function() {
this.removeOldMarkers(this.get(‘currentLocations’));
this.set(‘currentLocations’, this.get(‘locations’);
this.addMarkers(this.get(‘locations’));
}.observes(‘locations’),
removeOldMarkers: function(markers) {
markers.forEach(function(marker) {
// remove markers from Google map
});
@deanmarano
deanmarano / after.js
Created February 12, 2015 22:09
After Ember setter
locations: function(key, value, oldValue) {
if(value) {
this.removeOldMarkers(oldValue);
this.addMarkers(value);
}
return value;
}.property(),
removeOldMarkers: function(markers) {
markers.forEach(function(marker) {
@deanmarano
deanmarano / readme.md
Created October 2, 2015 01:25
Scopes vs. Closures

Scopes vs. Closures

Scopes and closures are often confused since they are so closely related. In your day to day life, it's somewhat rare that you'll need to know the difference. However, if you enjoy using the debugger, this may have bit you without you even knowing it.

Scope

https://developer.mozilla.org/en-US/docs/Glossary/Scope In Javascript, creating a new function creates a new scope. These are the variables that are defined in the current frame of the stack.

@deanmarano
deanmarano / readme.md
Created October 2, 2015 01:25
Scopes vs. Closures

Scopes vs. Closures

Scopes and closures are often confused since they are so closely related. In your day to day life, it's somewhat rare that you'll need to know the difference. However, if you enjoy using the debugger, this may have bit you without you even knowing it.

Scope

https://developer.mozilla.org/en-US/docs/Glossary/Scope In Javascript, creating a new function creates a new scope. These are the variables that are defined in the current frame of the stack.

@deanmarano
deanmarano / gist:a597eec343facb565bc4
Created December 17, 2015 22:20
Private Method Testing
https://lostechies.com/chadmyers/2008/11/21/do-not-test-private-methods/
http://peterprovost.org/blog/2012/05/31/my-take-on-unit-testing-private-methods/
https://dzone.com/articles/why-shouldnt-i-test-private
http://programmers.stackexchange.com/questions/135047/new-to-tdd-should-i-avoid-private-methods-now
class UserEnroller
attr_reader :user, :email
def initialize(user)
@user = user
if @user
# do some initialization, set some variables
end
end
@deanmarano
deanmarano / tips.md
Last active January 13, 2016 17:49
Development Tips

General

(bullets need expanding or categorization)

  • Class names should not be verbs, nor should they be verbs turned into nouns. (ex Enroller, UserAuthenticator)
  • Don't be clever. Clever is not obvious, and harder to read. Always code for the reader.
  • Reading code is hard. Writing code is easy. Get better at reading code.
  • Wrap third party calls (anything over the network) in their own wrapper. Don't make network calls outside of wrapper classes.
  • The rule of proximity - declare variables, methods, imports, etc. as close as possible to where they are used. (exception - standards of grouping imports near the top, etc.)
  • Push conditionals to the edges - out (to your public API) and in (towards the APIs you use), away from the middle.
  • If you’re writing a web service, play with the idea of making new endpoints instead of conditionals as query params

Veggies

  • 2 jalapeno peppers
  • 4 cloves garlic
  • 1 tablespoon ginger
  • 2 onions
  • 1 medium tomato
  • 1/2 pounds carrots, peeled and sliced

Fruits

  • 1/4 cup lime juice
@deanmarano
deanmarano / promises.coffee
Created February 22, 2016 21:12
Promise Support for Jasmine
itPromises = (testName, testFn) ->
it testName, (done) ->
promise = testFn()
if typeof promise.then == 'function'
promise.then(done, ->
fail("Promise was rejected - #{JSON.stringify(arguments)}")
)
else
fail('specs with itPromises needs to return a promise')
done()