Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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> {