Skip to content

Instantly share code, notes, and snippets.

@postmalloc
postmalloc / hn_sidebar.js
Last active August 30, 2023 08:10
Hacker News comments sidebar bookmarklet
// A handy bookmarklet to display comments from the top-rated Hacker News thread related to the current page
// Written with the help of GPT-4
javascript:(function() {
const createCommentElement = (comment, depth) => {
const commentWrapper = document.createElement('div');
commentWrapper.style.paddingLeft = (depth * 20) + 'px';
commentWrapper.style.marginBottom = '10px';
commentWrapper.style.marginLeft = '10px';
commentWrapper.style.color = '#333';
@zadeviggers
zadeviggers / emmet-in-jinja-vscode.json
Created June 8, 2022 05:50
Add this to your vscode json configuration file when using the better jinja extention (samuelcolvin.jinjahtml) to get emmet snippet support.
{
"emmet.includeLanguages": {
"jinja-html": "html"
}
}
@zadeviggers
zadeviggers / easeInOutQuad.py
Created March 19, 2022 08:49
Ease in-out one-liner function in python
def easeInOutQuad(x: int | float) -> int | float:
return 2 * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 2) / 2
@zadeviggers
zadeviggers / generate-json-file.ts
Last active February 22, 2022 03:21
The code for my search bar (https://publictransportforum.nz/articles). Made in SolidJS (with FuseJS for fuzzy matching) to be used in an Astro site. Note that this code is ripped straight from my source so it might need a bit of tweaking to make it work for you.
// Here are some snippets from the file that loads all my article's markdown files and does processing on them
// including generating the json file for search
import * as fs from "fs";
import path from "path";
const publicDirectory = path.join(process.cwd(), "public");
// At the bottom of the function that populates the cache of articles...
const searchFile = JSON.stringify(
articles.map((article) => ({
@senderle
senderle / hand-modify-pdf.md
Created September 23, 2020 15:03
So you want to modify the text of a PDF by hand

So you want to modify the text of a PDF by hand...

If you, like me, resent every dollar spent on commercial PDF tools, you might want to know how to change the text content of a PDF without having to pay for Adobe Acrobat or another PDF tool. I didn't see an obvious open-source tool that lets you dig into PDF internals, but I did discover a few useful facts about how PDFs are structured that I think may prove useful to others (or myself) in the future. They are recorded here. They are surely not universally applicable --
the PDF standard is truly Byzantine -- but they worked for my case.

@phacks
phacks / shadows.js
Created September 5, 2019 12:02
Material UI override shadows with color
/**
* This module is used at providing an easy way to override material-ui
* `shadows` properties.
* material-ui expects the shadows to be following a certain pattern.
* (source: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/styles/shadows.js)
* This file is a slight adaptation (for colours) of the above material-ui source file.
*
* This module exports a `createShadows(hexColor: string): Array<string>` method
* that takes a hex color (presumably from the configuration) and returns an array
* of the 25 possible shadows matching the 25 elevations in material-ui.
@JMPerez
JMPerez / service-worker.js
Created October 27, 2018 20:21
An example of a service worker for serving network first, cache second
// the cache version gets updated every time there is a new deployment
const CACHE_VERSION = 10;
const CURRENT_CACHE = `main-${CACHE_VERSION}`;
// these are the routes we are going to cache for offline support
const cacheFiles = ['/', '/about-me/', '/projects/', '/offline/'];
// on activation we clean up the previously registered service workers
self.addEventListener('activate', evt =>
evt.waitUntil(
https://youtu.be/-C-JoyNuQJs?t=39m45s
When I put the reference implementation onto the website I needed to
put a software license on it.
And I looked at all the licenses that were available, and there were a lot
of them. And I decided that the one I liked the best was the MIT License,
which was a notice that you would put on your source and it would say,
"you're allowed to use this for any purpose you want, just leave the
notice in the source and don't sue me."