Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
A ghost

Nathan myobie

👻
A ghost
View GitHub Profile
@myobie
myobie / estrella-utils.cjs
Created Jan 4, 2021
Build a project with estrella by convention using the settings in package.json
View estrella-utils.cjs
/* eslint-disable @typescript-eslint/no-var-requires */
const { join } = require('path')
const { build, file, cliopts } = require('estrella')
module.exports = {
buildPackage,
buildBrowserAndNodeModule,
buildBrowserModule,
buildNodeModule
@myobie
myobie / tsc-build.cjs
Created Jan 4, 2021
Alternative to estrella's tslint; instead use tsc --build so we can choose to produce declaration files (.d.ts)
View tsc-build.cjs
/* eslint-disable @typescript-eslint/no-var-requires */
const perf = require('perf_hooks')
const { spawn } = require('child_process')
const { cliopts, fmtDuration, findInPATH, log, stdoutStyle } = require('estrella')
module.exports = {
clock,
tscBuild
}
@myobie
myobie / clone.sh
Created Nov 23, 2020
Keep things organized with a clone bash function which always puts repos into the correct place
View clone.sh
clone() {
org=$(echo $1 | awk -F/ '{ print $1 }')
mkdir -p ~/src/github.com/$org
path=~/src/github.com/$1
git clone $@ $path
cd $path
}
# Examples:
# $ clone myobie/dot-files
@myobie
myobie / application.ex
Last active Nov 19, 2020
Gentle request task in elixir
View application.ex
defmodule Gentle.Application do
use Application
def start(_type, _args) do
children = [
{Task.Supervisor, name: Gentle.TaskSupervisor}
]
opts = [strategy: :one_for_one, name: Gentle.Supervisor]
Supervisor.start_link(children, opts)
@myobie
myobie / ci.yml
Last active Aug 26, 2020
Don't run GitHub Actions for pull requests that are drafts
View ci.yml
on:
push:
branches:
- master
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
@myobie
myobie / .eslintrc.js
Last active Aug 10, 2020
How to setup a hugo repo (or any static website) with eslint and the standard config
View .eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
mocha: true
},
globals: {
expect: true
},
plugins: [],
@myobie
myobie / .eslintrc.js
Created Jul 17, 2020
My eslint config for typescript projects
View .eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
mocha: true
},
globals: {
expect: true
},
parser: '@typescript-eslint/parser',
@myobie
myobie / service-worker.ts
Last active Jul 3, 2020
A small example of a service worker in typescript along with the tsconfig.json that allows tsserver and IDEs to understand what's going on
View service-worker.ts
// NOTE: We must export or import at least one thing so we are not in
// the "global" scope, but in a module scope which is re-declarable.
//
// The error from tsserver is: 2451: Cannot redeclare block-scoped
// variable 'self'.
//
// Even tho this is not really a module and cannot be: ServiceWorkers
// cannot be modules.
export type Version = number
@myobie
myobie / socket.ts
Created Jul 2, 2020
An example of how I seem to always end up wrapping the phoenix socket client
View socket.ts
import { Socket, Channel } from 'phoenix'
import { encode, decode } from './serializer'
import createState, { UpdateCallback } from './create-state'
import { enableMapSet } from 'immer'
enableMapSet()
type MessageCallback = (payload?: unknown) => void
type ChannelState = {
@myobie
myobie / create-state.ts
Last active Jul 2, 2020
Make a little state object which can be updated through Immer's produce
View create-state.ts
import produce, { Draft, Immutable } from 'immer'
type Updater<S> = (state: Draft<S>) => void | S
type UpdateCallback<S> = (state: Immutable<S>) => void
type State<T> = {
current: Immutable<T>;
update: (updater: Updater<T>) => void;
onUpdate: (cb: UpdateCallback<T>) => void;
}