Skip to content

Instantly share code, notes, and snippets.

View aulisius's full-sized avatar
🏠
Working from home

​Faizaan aulisius

🏠
Working from home
View GitHub Profile
@ebidel
ebidel / coverage.js
Last active April 27, 2024 04:13
CSS/JS code coverage during lifecycle of page load
Moved to https://github.com/ebidel/puppeteer-examples
const Compose = ({ children = () => null, ...chain }) => {
const composedFn = Object.entries(chain).reduce(
(acc, [renderProp, renderFn]) => props =>
renderFn(value => acc({ ...props, [renderProp]: value })),
children
);
return composedFn();
};
@nax3t
nax3t / ranking.js
Created March 1, 2017 00:14
Reddit Ranking Algorithm in JavaScript
function _confidence(ups, downs) {
var n = ups + downs;
if(n === 0) {
return 0;
}
var z = 1.281551565545;
var p = parseFloat(ups) / n;
var left = p + 1 / (2 * n) * z * z;

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

import java.util.*;
import java.util.stream.*;
class Trie {
public char nodeChar;
public boolean isLeaf;
public List<String> safeNames;
public HashMap<Character, Trie> subtrie;
Trie(char nodeChar, boolean isLeaf) {
@aalhour
aalhour / README.md
Last active March 9, 2018 09:19
BrainFuck Interpreter and REPL in Python 3

PBFI: Pythonic BrainFuck Interpreter

Yet another educational interpreter for the BrainFuck Programming Language, written in Python 3. This might not be the shortest BrainFuck interpreter that you had come acorss, however the style of programming is for educational purposes only.

USAGE:

Help:

@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@aulisius
aulisius / autocomplete.c
Created December 27, 2015 07:32
Basic autocomplete using trie in C
//Basic autocomplete using a Trie
//The trie is really not efficient
//The words should be supplied in a dict.txt file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct n {
struct n *subtrie[26];
@aulisius
aulisius / float2bin.js
Last active February 1, 2024 06:56
Converts decimal float to binary 32 format float
// @author - {N.Md Faizaan}
// @email - {aulisius7[at]gmail[dot]com}
// @title - Converts decimal float to binary 32 format float
// @ref - https://en.wikipedia.org/wiki/Single-precision_floating-point_format
// @license - MIT
/**
* float2bin - Convert decimal number to binary32 format
* @param {input} - The number to be converted either in Number or String type
* @return {bin32float} - The binary32 representation
@paulirish
paulirish / what-forces-layout.md
Last active June 9, 2024 13:52
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent