Skip to content

Instantly share code, notes, and snippets.

View ptim's full-sized avatar

Tim Osborn ptim

View GitHub Profile
@kepano
kepano / obsidian-web-clipper.js
Last active April 16, 2024 18:44
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */
@wilsonpage
wilsonpage / swr.ts
Last active February 20, 2024 05:21
An implementation of stale-while-revalidate for Cloudflare Workers
export const CACHE_STALE_AT_HEADER = 'x-edge-cache-stale-at';
export const CACHE_STATUS_HEADER = 'x-edge-cache-status';
export const CACHE_CONTROL_HEADER = 'Cache-Control';
export const CLIENT_CACHE_CONTROL_HEADER = 'x-client-cache-control';
export const ORIGIN_CACHE_CONTROL_HEADER = 'x-edge-origin-cache-control';
enum CacheStatus {
HIT = 'HIT',
MISS = 'MISS',
REVALIDATING = 'REVALIDATING',
@jamalex
jamalex / notion_task_manager.py
Created January 17, 2019 07:14
Notion task manager toy example
import datetime
import random
import time
from multiprocessing import Lock
from notion.client import *
from notion.block import *
mutex = Lock()
@markerikson
markerikson / cheng-lou-spectrum-of-abstraction.md
Last active October 23, 2023 23:18
Cheng Lou - "On the Spectrum of Abstraction" summarized transcript (React Europe 2016)

Cheng Lou - On the Spectrum of Abstraction

Cheng Lou, a former member of the React team, gave an incredible talk at React Europe 2016 entitled "On the Spectrum of Abstraction". That talk is available for viewing here: https://www.youtube.com/watch?v=mVVNJKv9esE

It's only a half-hour, but it is mind-blowing. It's worth re-watching two or three times, to let the ideas sink in.

I just rewatched the talk for some research, and wrote down a summary that's semi-transcript-ish. I didn't see any other transcripts for this talk, other than the auto-generated closed captions, so I wanted to share for reference.

Summary

@benbacardi
benbacardi / templatetags.py
Last active October 11, 2023 11:03
Django query_transform templatetag
from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def query_transform(context, **kwargs):
'''
Returns the URL-encoded querystring for the current page,
updating the params with the key/value pairs passed to the tag.

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@lukasbesch
lukasbesch / disk-conversion-progress.sh
Last active March 31, 2022 15:52
View progress of long-running disk conversion tasks (en-/decryption) on macOS / OS X
function displaytime {
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf '%3s' $D && printf ' days '
(( $H > 0 )) && printf '%2s' $H && printf ' hours '
(( $M > 0 )) && printf '%2s' $M && printf ' minutes '
if [ $D -lt 1 -a $H -lt 1 ]
@mrparkers
mrparkers / async-component.spec.js
Created August 4, 2016 00:43
Unit testing an async React component using Mocha, Chai, and Enzyme
import AsyncComponent from './path/to/component';
import request from 'your-request-library';
import React from 'react';
import {shallow} from 'enzyme';
import Chance from 'chance';
import chai, {expect} from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
(function () {
function Router() {
EventTarget.call(this);
this.rules = [];
window.addEventListener('hashchange', this.hashChange.bind(this));
window.addEventListener('popstate', this.hashChange.bind(this));
}
Router.prototype = Object.create(EventTarget);
Router.prototype.constructor = Router;