Skip to content

Instantly share code, notes, and snippets.

@donpark
donpark / PBKDF2Async.js
Created March 7, 2011 03:09
Asynch version of crypto-js 2.0.x PBKDF2
// original, synch version, is at:
// http://code.google.com/p/crypto-js/source/browse/branches/2.0.x/src/PBKDF2.js
(function(){
// Shortcuts
var C = Crypto,
util = C.util,
charenc = C.charenc,
UTF8 = charenc.UTF8,
Binary = charenc.Binary;
@donpark
donpark / DOM3D.js
Created March 27, 2024 10:41 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@donpark
donpark / claude-journalist.md
Created March 26, 2024 16:25
claude-journalist prompts

get search terms to query SERP with (haiku)

You are a world-class journalist. Generate a list of 5 search terms to search for to research and write an article about the topic.

Please provide a list of 5 search terms related to '{topic}' for researching and writing an article. Respond with the search terms in a Python-parseable list, separated by commas.

select relevant urls among SERP results (haiku)

@donpark
donpark / test-1.md
Created March 14, 2024 00:50
news-despin tests
$ llm chat -m gpt-4-turbo-preview
Chatting with gpt-4-turbo-preview
Type 'exit' or 'quit' to exit
Type '!multi' to enter multiple lines, then '!end' to finish
> !multi

You are seasoned news editor famous for identifying and removing political spin from news articles.

@donpark
donpark / gist:870585
Created March 15, 2011 10:53
node.js crypto notes

While this note is useful for achieving compatibility with non-node.js crypto code, it contains implementation details which maybe outdated in the near future. Beware.

key argument

key arguments are expected to be binary strings which is bytes packed as chararacter codes of a string.

What this means is that only lower byte of each character will be used.

crypto.createCipher and crypto.createDecipher

@donpark
donpark / perlincanvas.js
Created February 11, 2012 04:45
Rendering Perlin Noise Fast to HTML5 Canvas
/* Following canvas-based Perlin generation code originates from
* iron_wallaby's code at: http://www.ozoneasylum.com/30982
*/
function randomNoise(canvas, x, y, width, height, alpha) {
x = x || 0;
y = y || 0;
width = width || canvas.width;
height = height || canvas.height;
alpha = alpha || 255;
var g = canvas.getContext("2d"),
@donpark
donpark / NotificationEnum.swift
Created December 2, 2016 18:17
How to use enum of Notification.Name
import Foundation
// Extension allowing enum of Notification.Names.
#if swift(>=3.0)
extension Notification.Name: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(value)
}
@donpark
donpark / JSONFeed.ts
Last active March 16, 2021 10:23
Rough first cut of JSON Feed types and interfaces
/** JSON Feed TypeScript Declaration
* Spec Version: 1
*/
declare namespace JSONFeed {
const MIME_TYPE = 'application/json'
type DATEstring = RFC3339string
type IDstring = string
@donpark
donpark / FramePort.js
Last active June 29, 2020 08:05
Frame postMessage helper with request/response support
/**
* Create port to an iframe element:
*
* const iframePort = new FramePort(iframeEl);
*
* Create port to parent window:
*
* const parentPort = new FramePort(window.parent);
*
* Post a message:
@donpark
donpark / scriptBaseUrl.js
Last active June 23, 2020 22:50
scriptBaseUrl
// This needs to run when script loads.
const scriptUrl = new URL(document.currentScript.src, document.baseURI).toString();
const scriptBaseUrl = scriptUrl.substr(0, scriptUrl.lastIndexOf('/'));
// To build URL relative to script file.
const wasm = `${scriptBaseUrl}/wasm/my.wasm`