Skip to content

Instantly share code, notes, and snippets.

View dan-lee's full-sized avatar
‌‌

Dan dan-lee

‌‌
  • Germany
  • 23:30 (UTC +02:00)
  • X @drlehr
View GitHub Profile
--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
RETVAL_FALSE;
} else {
if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ ret = xmlOutputBufferGetSize(buf);
+#else
ret = buf->buffer->use;

Keybase proof

I hereby claim:

  • I am dan-lee on github.
  • I am danlee (https://keybase.io/danlee) on keybase.
  • I have a public key ASB-wIoYlALYLZ_eR0FSy77P3T4XfYIR5tfjmu6cRJ1KTAo

To claim this, I am signing this object:

@dan-lee
dan-lee / spiegel-plus-deobfuscator.js
Last active January 27, 2018 16:33
Deobfuscate and hide paywall for SPIEGEL PLUS
let getReplacement = char =>
/[\s\n]/.test(char) ? char : String.fromCharCode(char.charCodeAt(0) - 1);
let deobfuscate = text =>
text
.trim()
.split('')
.reduce((prev, curr) => prev + getReplacement(curr), '');
@dan-lee
dan-lee / getAbsoluteHeight.js
Created June 19, 2018 13:02
Get absolute height of a DOM element
const getAbsoluteHeight = el => {
const computedStyle = window.getComputedStyle(el)
return Math.ceil(
el.offsetHeight +
parseInt(computedStyle.getPropertyValue('margin-top'), 10) +
parseInt(computedStyle.getPropertyValue('margin-bottom'), 10)
)
}
@dan-lee
dan-lee / custom-test-env.mjs
Last active December 4, 2021 19:01
miniflare: The requested module 'ws' does not provide an export named 'WebSocketServer'
import NodeEnvironment from 'jest-environment-node'
export default class CustomTestEnvironment extends NodeEnvironment {
async setup() {
await super.setup()
;['atob', 'btoa', 'AbortSignal'].forEach((fn) => {
if (typeof this.global[fn] === 'undefined') {
this.global[fn] = global[fn]
}
})
@dan-lee
dan-lee / array-windows.ts
Created August 28, 2022 21:39
Rust-like `windows` for arrays
const windows = <T>(array: T[], slice = 2): T[][] =>
Array.from({ length: array.length - slice }).reduce<T[][]>((result, _, i) => {
return [...result, array.slice(i, slice + i)]
}, [])
@dan-lee
dan-lee / zip.ts
Created September 12, 2022 21:29
const zip = <A, B>(a: A[], b: B[]): Array<[A, B]> => a.map((k, i) => [k, b[i]]);
@dan-lee
dan-lee / ThrowingDate.ts
Created May 20, 2023 20:39
Throwing date
export class ThrowingDate extends Date {
constructor(...args: ConstructorParameters<typeof Date>) {
super(...args)
const date = new Date(...args)
if (isNaN(+date)) {
throw new Error('Invalid date')
}
return date