Skip to content

Instantly share code, notes, and snippets.

View davidgilbertson's full-sized avatar

David Gilbertson davidgilbertson

  • Sydney, Australia
View GitHub Profile
@davidgilbertson
davidgilbertson / http2.js
Last active October 9, 2023 06:09
HTTP2 server with compression and caching
View http2.js
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const brotli = require('brotli'); // npm package
const PORT = 3032;
const BROTLI_QUALITY = 11; // slow, but we're caching so who cares
const STATIC_DIRECTORY = path.resolve(__dirname, '../dist/');
const cache = {};
@davidgilbertson
davidgilbertson / Python-List.py.groovy
Last active August 23, 2023 20:37
Custom extractor for PyCharm - copy tables to a list of dicts
View Python-List.py.groovy
import static com.intellij.openapi.util.text.StringUtil.escapeStringCharacters as escapeStr
SEPARATOR = ", "
QUOTE = "\""
NEWLINE = System.getProperty("line.separator")
def record(columns, dataRow) {
OUT.append(" {").append(NEWLINE)
columns.eachWithIndex { column, idx ->
View color-log.js
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
View KeyframeLR.py
import timeit
import math
from typing import Sequence, Mapping, Literal, Callable
from torch.optim import Optimizer
from torch.optim.lr_scheduler import LRScheduler
class KeyframeLR(LRScheduler):
def __init__(
View webpack.config.js
module.exports = {
entry: {
main: path.resolve(__dirname, 'src/index.js'),
ProductList: path.resolve(__dirname, 'src/ProductList/ProductList.js'),
ProductPage: path.resolve(__dirname, 'src/ProductPage/ProductPage.js'),
Icon: path.resolve(__dirname, 'src/Icon/Icon.js'),
},
output: {
path: path.resolve(__dirname, 'dist'),
View deconstructions.csv
Word Deconstruction
it's it ~is
years year ~s
going go ~ing
that's that ~is
i'm i ~am
things thing ~s
states state ~s
including include ~ing
called call ~ed
View css-breakpoint-mixins.scss
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-landscape-up {
@media (min-width: 900px) { @content; }
}
@mixin for-desktop-up {
View webpack.config.js
const path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
},
optimization: {
splitChunks: {
View webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: path.resolve(__dirname, 'src/index.js'),
plugins: [
new webpack.HashedModuleIdsPlugin(), // so that file hashes don't change unexpectedly
],
output: {
path: path.resolve(__dirname, 'dist'),
@davidgilbertson
davidgilbertson / Icon.jsx
Last active August 10, 2022 03:00
Production version
View Icon.jsx
import React from 'react';
const {PropTypes} = React;
const Icon = props => {
const styles = {
svg: {
display: 'inline-block',
verticalAlign: 'middle',
},
path: {