Skip to content

Instantly share code, notes, and snippets.

import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class extends Component {
@service counter;
get count() {
return this.counter.count;
}
@tansongyang
tansongyang / simple-money.ts
Created September 17, 2019 21:18
An attempt at a super simple money type that only supports addition
function toCents(value: number) {
return Math.round(value * 100);
}
function fromCents(value: number) {
return +(value / 100).toFixed(2);
}
class Money {
private cents: number;

Keybase proof

I hereby claim:

  • I am tansongyang on github.
  • I am tansongyang (https://keybase.io/tansongyang) on keybase.
  • I have a public key ASD27yKRSxfJSerZr5ww8DNMMW-TsZdGJR3zCfjrayjFqwo

To claim this, I am signing this object:

@tansongyang
tansongyang / vimovetobrackets.py
Last active June 12, 2018 22:09
A BracketHighlighter plugin that implements Vintage's vi_move_to_brackets.
import BracketHighlighter.bh_plugin as bh_plugin
import sublime
class ViMoveToBrackets(bh_plugin.BracketPluginCommand):
"""
Move to Bracket plugin for Vintage.
Based on [Select Bracket plugin](https://github.com/facelessuser/BracketHighlighter/blob/st3-2.23.3/bh_modules/bracketselect.py).
"""
@tansongyang
tansongyang / ramda-evolve-in-lodash-fp.js
Last active July 10, 2018 07:53
An implementation of Ramda's `evolve` function in lodash.
// http://stackoverflow.com/questions/38090023/whats-the-lodash-fp-equivalent-of-ramdas-evolve-function/38425764#38425764
const mapValuesWithKey = _.mapValues.convert({cap: false});
function evolve(transformations) {
return item =>
mapValuesWithKey((value, key) => {
const transformation = _.getOr(_.identity)(key)(transformations);
const type = typeof transformation;
return type === 'function' ?
@tansongyang
tansongyang / cartesian-product-lodash-fp.js
Last active October 8, 2023 23:45
An implementation of Cartesian product using lodash/fp
// Based on this gist: https://gist.github.com/ChrisJefferson/cb8db2a4c67a9506c56c
// JS Bin: https://jsbin.com/cefopi/edit?js,console
const cartesianProduct = (...rest) =>
_.reduce((a, b) =>
_.flatMap(x =>
_.map(y =>
x.concat([y])
)(b)
)(a)
)([[]])(rest);