View gulpfile.js
This file contains 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 gulp from 'gulp'; | |
import { Transform } from 'node:stream'; | |
gulp.task('build', () => { | |
return gulp | |
.src('src/**/*.js') | |
.pipe( | |
new Transform({ | |
objectMode: true, | |
transform(file, encoding, callback) { |
View mapped-type-conversion.ts
This file contains 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
type Input<Output> = { | |
[K in keyof Output]: { foo: () => Output[K] }; | |
}; | |
function convert<Output>(input: Input<Output>): Output { | |
const keys = Object.keys(input) as (keyof Input<Output>)[]; | |
return keys.reduce( | |
(output, key) => ({ ...output, [key]: input[key].foo() }), | |
{} as Output |
View gulpfile.js
This file contains 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 gulp from 'gulp'; | |
import Vinyl from 'vinyl'; | |
import vinylAdapter from './vinyl-adapter'; | |
gulp.task('build', () => { | |
const file = new Vinyl({ | |
path: 'hello.js', | |
contents: Buffer.from(`console.log('👋');`) | |
}); |
View ban-generators-and-async.json
This file contains 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
{ | |
"rules": { | |
"no-restricted-syntax": [ | |
"error", | |
"[generator=true]", | |
"[async=true]", | |
"AwaitExpression" | |
] | |
} | |
} |
View get-color-in-range.js
This file contains 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 { scaleLinear } from "d3-scale"; | |
const getColor = scaleLinear().domain([0, 100]).range(["#ccc", "#419fcf"]); | |
getColor(0); // 0% = #ccc | |
getColor(80); // 80% = #5da8ce | |
getColor(100); // 100% = #419fcf |
View express-curl-middleware.js
This file contains 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
// After body-parsing middleware... | |
app.use(function(req, res, next) { | |
console.log( | |
"curl '%s://%s%s' -X %s -H 'Content-Type: %s' -d '%s'", | |
req.protocol, | |
req.get("host"), | |
req.originalUrl, | |
req.method, | |
req.get("Content-Type"), | |
JSON.stringify(req.body) |
View es6-map-to-object-literal.js
This file contains 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
let map = new Map(); | |
map.set("a", 1); | |
map.set("b", 2); | |
map.set("c", 3); | |
let obj = Array.from(map).reduce((obj, [key, value]) => ( | |
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't. | |
), {}); | |
console.log(obj); // => { a: 1, b: 2, c: 3 } |
View interceptors.coffee
This file contains 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
.config ($httpProvider) -> | |
$httpProvider.interceptors.push ($q, $rootScope, apiUrl, authToken) -> | |
request: (config) -> | |
# Intercept API requests and inject the auth token. | |
config.headers["X-Auth-Token"] = authToken if config.url.indexOf(apiUrl) is 0 and authToken? | |
config or $q.when config | |
responseError: (response) -> | |
# Intercept unauthorised API responses and fire an event. |
View routes.html.erb
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Routes</title> | |
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> |
View excel-grid-plugin.js
This file contains 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 newGridCellValue = '', | |
deleteGridCellValue = false; | |
Ext.define('ExcelCellEditing', { | |
extend: 'Ext.grid.plugin.CellEditing', | |
alias: 'plugin.excelcellediting', | |
initEditTriggers: function () { | |
var me = this; |
NewerOlder