- Don't add code cruft. Avoid parentheses around conditions in if-statements or with the
returnkeyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line. - Don't use ALL_CAPS; use camelCase
- Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
- Don't use
varwhenletis appropriate, especially for properties. The compiler better optimizesletstatements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create." - Don't use classes when structs will do. Use class
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 googleapis = require('googleapis'), | |
| JWT = googleapis.auth.JWT, | |
| analytics = googleapis.analytics('v3'); | |
| var SERVICE_ACCOUNT_EMAIL = 'XXXXXXXXXX@developer.gserviceaccount.com'; | |
| var SERVICE_ACCOUNT_KEY_FILE = __dirname + '/key.pem'; | |
| var authClient = new JWT( | |
| SERVICE_ACCOUNT_EMAIL, |
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 MovingAverage { | |
| var samples: Array<Double> | |
| var sampleCount = 0 | |
| var period = 5 | |
| init(period: Int = 5) { | |
| self.period = period | |
| samples = Array<Double>() | |
| } | |
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
| export function ComponentWithMixins( ...mixins) { | |
| class MixedComponent extends React.Component { } | |
| for( let mixin of mixins) { | |
| // TODO: Would need to handle mixin collisions... | |
| for( let name of Object.keys( mixin)) { | |
| MixedComponent.prototype[ name]= mixin[ name] | |
| } | |
| } |
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
| 'use strict'; | |
| /** | |
| * Created by Alexander Litvinov | |
| * Email: alexander@codeordie.ru | |
| * May be freely distributed under the MIT license | |
| */ | |
| let singleton = Symbol(); | |
| let singletonEnforcer = Symbol(); |
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 pickFiles = require('broccoli-static-compiler'); | |
| var fastBrowserify = require('broccoli-fast-browserify'); | |
| var babelTranspiler = require('broccoli-babel-transpiler'); | |
| var mergeTrees = require('broccoli-merge-trees'); | |
| var libTree = pickFiles('lib', { | |
| files: ['**/*.js'], | |
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
| import {Component as _Component, Template as _Template} from 'angular2/src/core/annotations/annotations'; | |
| function makeDecorator(annotationClass) { | |
| return (options) => { | |
| return (klass) => { | |
| klass.annotations = klass.annotations || []; | |
| klass.annotations.push(new annotationClass(options)); | |
| return klass; | |
| }; | |
| }; |
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
| /* @flow */ | |
| var React = require("react") | |
| var Immutable = require("immutable") | |
| // In order to use any type as props, including Immutable objects, we | |
| // wrap our prop type as the sole "data" key passed as props. | |
| type Component<P> = ReactClass<{},{ data: P },{}> | |
| type Element = ReactElement<any, any, any> |
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
| <?php | |
| // This is sample code to draw some of the charts I blogged about here: | |
| // https://medium.com/ios-os-x-development/keeping-your-wits-as-an-indie-app-developer-3b5b14428e1f | |
| // | |
| // A few disclaimers: | |
| // 1. This assumes you have at least 30 days of sales data in order to draw the Trailing 7 Days Chart | |
| // 2. This assumes you have over 52 consecutive weeks of data in order to draw the Trailing Year Chart | |
| // 3. I don't really know PHP. Everything this does, I had to look it up while writing it. If you actually know PHP, sorry. There are surely better ways. | |
| // | |
| // the results of this PHP script is intended to be drawn using the Flot library. |
This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).
Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.
Switch to the master branch and make sure you are up to date: