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
@trueadm
trueadm / adopt-syntax.js
Last active November 27, 2021 03:32
Adding a the "adopt" keyword to the JSX syntax
// I'm suggesting we add a new "adopt X from <Y />" syntax to the JSX language
// it would de-sugar to render prop children, but look and read better than
// what we currently have. For example:
// 1.
// this sugar
function MyComponent(props) {
adopt foo from <Bar />;
return <div>{foo}</div>;
}
@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 April 14, 2025 22:47
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