Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dead-claudia
dead-claudia / Gmail Filter by Search Query.md
Last active December 18, 2023 21:37
Gmail script filter based on search queries

Gmail Filter by Search Query

This program, in the form of a configuration script and a main script, allows for complicated Gmail search queries to be used as filters. It also lets you do more advanced stuff you can't do with ordinary filters, like label based on whether an email contains a specific kind of attachment.

Installing

  1. Go to script.google.com.
  2. Go to File > New > Script File, and type Main as the title for the new script. This will be for the main script.
  3. Delete any pre-filled text in the script file, and copy main.gs from this gist to that file.
  4. Go to File > New > Script File again, and type Config as the title for the new script. This will be for configuration.
@dead-claudia
dead-claudia / constraint-types.md
Last active October 3, 2022 19:31
TypeScript Constraint Types Proposal

(All feedback/discussion should take place in the relevant issue.)

TypeScript Constraint Types Proposal

There's multiple requests for the ability to control a type at a much more fine grained level:

  • #12424: Mapped conditional types
  • #12885: Typing function overloads
  • #12880: Bad inference for lambda closures
  • Promises wrongfully accept thenables as their generic parameter (thenables can never be the argument to a then callback).
@dead-claudia
dead-claudia / count-zero-bytes.c
Last active July 29, 2022 19:03
Utility to compare various ways of counting zero and (really) non-zero bytes, including exhaustive tests
// Note: there are some Clang-isms here. To compile with GCC, define `__builtin_readcyclecounter`
// to read from something like x86's `rdtsc` and return a 64-bit integer with the cycle count. It's
// always manipulated relative to a prior call, so it doesn't matter if it wraps around once in the
// process.
#define RUN_ONLY_TESTS 1
#define RUN_ONLY_BENCHMARK 2
// Set to RUN_ONLY_TESTS to run only tests, RUN_ONLY_BENCHMARK to run only the benchmark, or unset
// to run both.
@dead-claudia
dead-claudia / mithril-react.mjs
Last active September 27, 2021 12:21
Mithril to React adapters
import m from "mithril"
import React, {useLayoutEffect, Component} from "react"
import ReactDOM from "react-dom"
// Bottom-up to Mithril, top-down to React
export function useMithril(ref, view) {
useLayoutEffect(() => { m.render(ref.current, view()) })
useLayoutEffect(() => () => { m.render(ref.current, null) }, [])
}
@dead-claudia
dead-claudia / patch.js
Created May 6, 2021 15:50
patch userland implementation
export function patch(target, props) {
return m(Patch, {target, ...props})
}
const hasOwn = {}.hasOwnProperty
const isEventKey = /^on(?!init|create|(?:before)?(?:update|remove)$)/
function Patch({attrs}) {
function handler(event) {
const onevent = attrs[`on${event.type}`]
@dead-claudia
dead-claudia / promise-settle.js
Last active May 2, 2020 01:59
Promise synchronous settle
const call = Function.call.bind(Function.call)
// `onSettled` is just `onSettled(value, isSuccess)`.
Promise.hookIntoSettlement = (thenable, onSettled) => {
function settle(value) {
let settled = false
let then
function fail(e) {
if (!settled) {
settled = true
@dead-claudia
dead-claudia / mithril-fontawesome.js
Last active January 23, 2020 03:07
Mithril port of react-fontawesome
// This is a direct API port of https://github.com/FortAwesome/react-fontawesome
// to Mithril, with a few optimizations for faster vnode creation and more
// efficient normalization. It's also combined into a single UMD file and
// written to support a pure ES5 environment without transpiling. It's less than
// 200 lines of code excluding this long introductory comment, and is about
// 1.2KB min+gzip.
//
// Here's a few example vnodes:
//
// ```js
@dead-claudia
dead-claudia / foo.js
Last active December 14, 2019 01:33 — forked from sakenzhuma/foo.js
import {api} from '../../share/hlp'
import Header from './header'
import pgList from '../../cmp/pgList'
import editBox from '../../cmp/editBox'
import Modal from '../../cmp/modal'
export default function Storage(){
let modalstate = false
let folderView = 1
let folder = ""
let dataList = []
@dead-claudia
dead-claudia / mithril-optimization.md
Last active August 2, 2019 18:40
Mithril optimization ideas

Mithril Optimization Ideas

This is more of a list of ideas, so I can get some feedback on each one, but it's also in rough chronological order, since I have to wait for some things before I can do others. It deals a lot with optimization within the rendering, so be prepared to see some more arcane details about it and optimization in general.

I created this as a gist as to not litter the issue tracker with a long-term proposal likely to get lost in the flow of things.

  1. This monstrosity should be split up, so engines can actually optimize the thing better.

  2. This issue (#1653) should be fixed.

  • Compared to the rest, this is low hanging fruit.
@dead-claudia
dead-claudia / mini-css-in-js-framework-docs.md
Last active May 1, 2019 18:28
Mini CSS-in-JS framework in under 50 lines of ES6 code

A mini CSS-in-JS framework

It exports two functions:

  • renderToString(styles) - Render the CSS to a string. (This has no DOM dependency, and it omits the @charset - that's for you to set.)
  • renderToDOM(styles) - Render the CSS to the DOM.

Note that renderToString omits any charset - the user should specify that before emitting.

Styles are specified as follows: