Skip to content

Instantly share code, notes, and snippets.

David davidlygagnon

  • San Francisco
View GitHub Profile
@davidlygagnon
davidlygagnon / git_bash_prompt
Created Jul 9, 2019
Bash profile prompt showing git branch
View git_bash_prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
View CoffeeScript existential operations
// CoffeeScript
getPartNumber = (car) ->
car?.getMake()?.model?.partNumber
return
// JavaScript
const getPartNumber = function(car) {
__guard__(__guard__(car != null ? car.getMake() : undefined, x1 => x1.model), x => x.partNumber);
};
function __guard__(value, transform) {
@davidlygagnon
davidlygagnon / example-constructor-instantiation-js
Created Apr 20, 2019
JavaScript shorthand property instantiation with super() call
View example-constructor-instantiation-js
// JavaScript
class SportCar extends Car {
constructor(model, wheelsProperties) => {
super();
this.model = model;
this.wheelsProperties = wheelsProperties;
}
}
class Car {
@davidlygagnon
davidlygagnon / example-constructor-instantiation-coffee
Last active Apr 20, 2019
Coffeescript shorthand property instantiation with super() call
View example-constructor-instantiation-coffee
// Coffeescript
class SportCar extends Car
constructor: (@model, @wheelsProperties) ->
super()
class Car
constructor: () ->
computeWheelMaintenance()
computeWheelMaintenance: ->
@davidlygagnon
davidlygagnon / gist:0e68b1981b06ecab30b769bef93cdd73
Last active Apr 19, 2019
CoffeeScript shorthand instance property initialization
View gist:0e68b1981b06ecab30b769bef93cdd73
// (1) Coffeescript
class Car
constructor: (@model) ->
// (2) JavaScript (ES6)
class Car {
constructor(model) => {
this.model = model
}
}
@davidlygagnon
davidlygagnon / gist:7c66914fcda083403a8bd1029d9c184c
Created Apr 18, 2019
Implicit coffeescript returns statements
View gist:7c66914fcda083403a8bd1029d9c184c
componentDidMount() {
return this.fetchRecords();
}
You can’t perform that action at this time.