Skip to content

Instantly share code, notes, and snippets.

View davidlygagnon's full-sized avatar

David davidlygagnon

View GitHub Profile
@davidlygagnon
davidlygagnon / git_bash_prompt
Created July 9, 2019 14:09
Bash profile prompt showing git branch
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\] $ "
// 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 April 20, 2019 00:07
JavaScript shorthand property instantiation with super() call
// 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 April 20, 2019 00:06
Coffeescript shorthand property instantiation with super() call
// Coffeescript
class SportCar extends Car
constructor: (@model, @wheelsProperties) ->
super()
class Car
constructor: () ->
computeWheelMaintenance()
computeWheelMaintenance: ->
@davidlygagnon
davidlygagnon / gist:0e68b1981b06ecab30b769bef93cdd73
Last active April 19, 2019 23:43
CoffeeScript shorthand instance property initialization
// (1) Coffeescript
class Car
constructor: (@model) ->
// (2) JavaScript (ES6)
class Car {
constructor(model) => {
this.model = model
}
}
@davidlygagnon
davidlygagnon / gist:7c66914fcda083403a8bd1029d9c184c
Created April 18, 2019 23:36
Implicit coffeescript returns statements
componentDidMount() {
return this.fetchRecords();
}