Skip to content

Instantly share code, notes, and snippets.

@avaly
avaly / sample.ts
Last active November 17, 2023 13:55
prettier-experimental-ternaries-samples.ts
// Having the condition start on a newline is not readable
const availabilityStartDate =
availability.startDate ? DateTime.fromJSDate(availability.startDate, { zone: 'utc' }) : DateTime.now().toUTC();
// Previously it was much more readable:
const availabilityStartDate = availability.startDate
? DateTime.fromJSDate(availability.startDate, { zone: "utc" })
: DateTime.now().toUTC();
/////////////////////////////////////////////////////////////
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
overrides: [
{
files: ['*.graphql'],
extends: ['plugin:@graphql-eslint/schema-recommended'],
@avaly
avaly / package.json
Last active January 7, 2020 14:37
typegoose-es-modules-bug
{
"type": "module",
"devDependencies": {
"@types/mongoose": "5.5.39",
"typescript": "3.7.4"
},
"dependencies": {
"@typegoose/typegoose": "6.2.0",
"mongoose": "5.8.3"
}
@avaly
avaly / type-assertion.js
Created February 27, 2019 03:30
typescript-checkJS
type Bar = { bar: number };
const test = { bar: 123 } as Bar;
test.bar;
@avaly
avaly / package.json
Created February 15, 2019 04:43
jest-nock-leak
{
"name": "jest-test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"jest": "24.1.0",
"nock": "10.0.6",
"weak": "1.0.1"
}
@avaly
avaly / rss.js
Created December 1, 2018 22:11
require-so-slow-mp-core
const requireSoSlow = require('require-so-slow');
process.env.PROVIDER_NAME = 'webshows';
require('./bin/serve');
process.on('SIGTERM', () => {
requireSoSlow.write('rss.trace');
});
@avaly
avaly / run-with-bug.js
Created November 15, 2018 20:22
winston-format-bug
const winston = require('winston');
const { combine, printf, splat } = winston.format;
const customFormat = combine(
splat(),
printf((info) => JSON.stringify(info))
);
const logger = winston.createLogger({
transports: [
@avaly
avaly / gist:f5760142157d618dfafcc2d27cce56ff
Created September 1, 2018 11:56
babel-inline-classnames-diff
diff --git a/package.json b/package.json
index 6a694e4..3dbaf84 100644
--- a/package.json
+++ b/package.json
@@ -42,9 +42,7 @@
"@babel/core": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
- "babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
@avaly
avaly / benchmark-propsOrId.js
Created August 23, 2018 12:25
benchmark-propsOrId.js
const _ = require('lodash');
const mongoose = require('mongoose');
const Benchmark = require('benchmark');
const { ObjectId } = mongoose.Types;
const isObjectId = (id) => id instanceof ObjectId;
function withCond(props, value) {
return _.cond([
@avaly
avaly / benchmark.js
Created August 2, 2018 16:39
sharp-blur-benchmark
const fs = require('fs');
const sharp = require('sharp');
const axios = require('axios');
const URL =
'http://static.megaphone.fm/podcasts/05f71746-a825-11e5-aeb5-a7a572df575e/image/uploads_2F1516902193862-jqkml22bswo-cee641b4533ddb31a5a7ab656fe45116_2FCURRENT_Reply+All+Logo.png';
function time(hrtime) {
const nanoseconds = hrtime[0] * 1e9 + hrtime[1];
const seconds = nanoseconds / 1e9;