Skip to content

Instantly share code, notes, and snippets.

@FremyCompany
FremyCompany / data.rs
Last active May 27, 2019 14:41
Large Trie rust compiler oom repro
use std::collections::hash_map::HashMap;
use std::hash::Hash;
pub struct Trie<K, V> where K: std::fmt::Debug+Eq+Hash+Clone, V: std::fmt::Debug+Clone {
value: Option<V>,
children: HashMap<K, Trie<K, V>>,
}
impl<K, V> Trie<K,V> where K: std::fmt::Debug+Eq+Hash+Clone, V: std::fmt::Debug+Clone {
pub fn new() -> Trie<K, V> {
@FremyCompany
FremyCompany / map-update.js
Last active February 5, 2019 13:37
Proof of concept of styleMap extension
// ================================================================
// enable to update a set of properties with a single call
// ================================================================
StylePropertyMapReadOnly.prototype.update = function(updaters) {
var oldValues = Object.create(null);
for(var key in updaters) { oldValues[key] = this.get(key); }
for(var key in updaters) { let newValue = updaters[key](oldValues); if (newValue) this.set(key, newValue); }
}
@FremyCompany
FremyCompany / compile.bat
Created February 4, 2019 19:57
Output all colors of an image in a file
# Open a command prompt and type the following lines:
cd C:\type\the\path\to\the\folder\containing\the\cs\file
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe extract-colors.cs /reference:System.Drawing.dll
extract-colors.exe > result.txt
@FremyCompany
FremyCompany / log-clicks.js
Created June 12, 2017 22:05
Debug WebDriver-generated mouse events
window.onclick = function(e) {
var d = document.createElement("div");
d.style = `position: fixed; top: ${e.clientY}px; left: ${e.clientX}px; outline: 3px solid ${e.ctrlKey ? 'green' : 'red'};`;
document.body.appendChild(d);
}
@FremyCompany
FremyCompany / typescript-jsx-mithril.tsx
Created February 22, 2017 23:45
Small helper to get autocompletion when authoring Mitrhil components in Typescript
function Component<T>(view: (attributes: T, children: Array<any>) => Mithril.VirtualElement): () => Mithril.Component<Mithril.ControllerWithAttributes<T>> & { attributes?: T} {
return () => ({ view(n) { return view(n.attributes, n.children); } } as any);
}
var Abc = Component<{ input:string, value:string }>(a =>
<div>{a.input}</div>
);
var t = <Abc input="true" value="true" />
@FremyCompany
FremyCompany / index.html
Last active January 27, 2017 04:20
Get the line of source code that generated an element for jsfiddle/etc purposes
<!doctype html><script onload="document.scripts[0].remove()">
var html =
`<html>
<head>
<title>Test page</title>
<style>
input:hover {
outline: 3px solid red;
}
</style>
@FremyCompany
FremyCompany / mapping-system.d.ts
Created June 8, 2016 22:51
Node Mapping System
declare var Map: { new(): Map<any,any> };
interface Map<IndexType, ValueType> {
get(index:IndexType): ValueType,
set(index:IndexType, value:ValueType)
}
declare var MappingSystem: MappingSystemConstructor;
interface MappingSystemConstructor {
new(): MappingSystem<any,any,any,any>
NodeMappingSystem: NodeMappingSystemConstructor
@FremyCompany
FremyCompany / height-distribution-ideas.md
Last active April 23, 2016 06:42
Table height distribution -- ideas

Computing the table height

The height of a table is the largest of:

  • The specified height of the table (percentages are resolved against ancestors as usual)
  • The height required for the rows and the vertical border-spacings. For each row, the largest of:
  • The row’s specified height if it is defined in non-percentages units (0 otherwise)
    • Also the eventual rowgroup specified size, using the usual splitting among tracks
  • The height deemed necessary to render all its cells when running the same algorithm that is being used to compute a column min-width, where the min-height of a cell is the largest of:
    • The cell’s specified height if it is defined in non-percentages units (0 otherwise)
    • The height of the cell border and padding plus the scrollHeight of its content layouted as if:
  • the cell height was set to 0px and overflow was set to hidden,
This file has been truncated, but you can view the full file.
//
// TEST EVERY TWO-CHAR TO-LOWER/TO-UPPER COMBINATION
//
var arr = []; for(var i = 0; i<=256; i++) { for(var j = 0; j<=256; j++) { var str = String.fromCharCode(i)+String.fromCharCode(j); arr.push(str+str.toLowerCase()+str.toUpperCase()) } };
var resultArr = [ "\u0000\u0000\u0000\u0000\u0000\u0000", "\u0000\u0001\u0000\u0001\u0000\u0001", "\u0000\u0002\u0000\u0002\u0000\u0002", "\u0000\u0003\u0000\u0003\u0000\u0003", "\u0000\u0004\u0000\u0004\u0000\u0004", "\u0000\u0005\u0000\u0005\u0000\u0005", "\u0000\u0006\u0000\u0006\u0000\u0006", "\u0000\u0007\u0000\u0007\u0000\u0007", "\u0000\b\u0000\b\u0000\b", "\u0000\t\u0000\t\u0000\t", "\u0000\n\u0000\n\u0000\n", "\u0000\u000b\u0000\u000b\u0000\u000b", "\u0000\f\u0000\f\u0000\f", "\u0000\r\u0000\r\u0000\r", "\u0000\u000e\u0000\u000e\u0000\u000e", "\u0000\u000f\u0000\u000f\u0000\u000f", "\u0000\u0010\u0000\u0010\u0000\u0010", "\u0000\u0011\u0000\u0011\u0000\u0011", "\u0000\u0012\u0000\u0012\u0000\u0012", "\u0000\u0013\u0000\u0013\u0000\u0013", "\u0000\u0014\u0000\
const element = dom.div.id("main-content").role("main")`
Hello, my name is ${html.a.href('//jakearchibald.com')`Jake Archibald`}.
I like:
${dom.ul`
${dom.li`The web`}
${dom.li`Food`}
${dom.li`…actually that's it`}
`}
`;