Skip to content

Instantly share code, notes, and snippets.

@FremyCompany
FremyCompany / 1-readme.md
Last active August 29, 2015 14:23
onecharaway-tree.js

This algorithm collects the words of a dictionary identical to a given words, one letter excepted.

To achieve a faster speed, the dictionnary is transformed into a tree of nodes containing the words letter by letter, as such:

{
  "a": {
    "b": {
      "c": {
 "d": {
@FremyCompany
FremyCompany / readme.md
Last active June 15, 2022 06:26 — forked from DigiTec/readme.md

Spoiler pages for the FindNearbyWords challenge

The goal of the exercise is to find an efficient way to take an existing word and lookup all words in a dictionary that differ from the original by only a single character. This is the kernel function for larger algorithmic problems like the Word Ladder, where you try to find the shortest route between two words, by changing one character at a time, and where each intermediate step must be in an intial dictionary of words.

Bruce Force

The simplest algorithm possible will take the input word and then compare it against every word in the dictionary, character by character, and count the differences. If the character differences between the word are just 1, then we add it to our list, otherwise we reject it. JavaScript has the Array.filter method which does precisely what we want and we just supply a function which returns true or false depending on if our criterion are met.

It is possible to optimize differsByOne further to get more benefits, but given t

//
// HELPER
//
var MetadataHolder = function() {
var map = new WeakMap();
var get = function(obj) {
return map.get(obj)
}
get.init = function(obj, val) {
map.set(obj, val);
@FremyCompany
FremyCompany / AA5-INTRO.MD
Last active August 29, 2015 14:17
"Hooking into InputDevice's Raw Input" (proposal)

At the time of writing, the input devices landscape is fragmented, very fragmented. Beside a few common concepts inherited from the very first input devices (mouses and keyboards), it's impossible to get out of input devices the raw input they collect and make something useful out of it.

Inspirations

The aim of this proposal is to philosophically draw from the Pointer Events specification and unify a large range of input devices by providing a new set of fundamental concepts

@FremyCompany
FremyCompany / index.html
Created February 23, 2015 23:15
Proof position:relative is necessary to create layout islands
<main>
some main content here
<section style="position: not-relative; width: 100px; height: 100px; background: blue; color: white; overflow: hidden;">
some section content here
<aside style="position: absolute; top: 5px; left: 50px; background: red; -ms-wrap-flow: both">
some aside content here
</aside>
</section>
</main>
@FremyCompany
FremyCompany / a.js
Last active November 19, 2021 16:03
Namespaces events without jQuery
// once in the headers
defineMetaEvent('Namespace','Click');
// then when you need it
document.body.onNamespaceClick.add(function(e) { /*...*/ });
document.body.onNamespaceClick.clear();