Skip to content

Instantly share code, notes, and snippets.

@102
102 / naive.js
Last active November 4, 2020 04:46
let countBits = (x) => x.toString(2).replace(/0/g, "").length;
let sortBits = (x) => [...x].sort((a, b) => countBits(a) - countBits(b));
module.exports.sortBits = sortBits;
@102
102 / index.js
Last active October 20, 2020 07:03
pseudo-HTML Lexer and Parser (without attributes support)
/**
* @typedef LexemType
* @type {'data' | 'startTagStart' | 'endTagStart' | 'selfClosedTagEnd' | 'tagEnd' | 'tagName'}
*/
/** @type {{ [lexem: string]: LexemType }} */
const Lexem = {
startTagStart: "startTagStart", // `<` in `<div>`
endTagStart: "endTagStart", // `</` in `</div>
selfClosedTagEnd: "selfClosedTagEnd", // `/>` in `<br />`
@102
102 / index.js
Created October 12, 2020 09:19
babyLisp
const Token = {
operator: "operator",
parensOpen: "parensOpen",
parensClose: "parensClose",
number: "number"
};
const Operator = {
add: "add",
subtract: "subtract",
@102
102 / hey
Last active July 9, 2020 18:28
👁👄👁
@102
102 / error
Created September 21, 2018 11:14
This file has been truncated, but you can view the full file.
{"arguments":[{"MessageId":0,"SendlerId":"40032bde-37aa-47c9-9000-7c479f2bb725","RecipientId":"ad43e0ed-5bd6-494d-87ad-f2115ca14a20","MessageText":"asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf a
@102
102 / redux-saga_v0.15.x.js
Created November 17, 2017 10:54 — forked from TomiS/redux-saga_v0.15.x.js
Redux-saga flow types for version 0.15.x
/**
* Shared interfaces between the modules 'redux-saga' and
* 'redux-saga/effects'
*/
declare interface $npm$ReduxSaga$Channel {
take: (cb: (msg: mixed) => void) => void,
put: (msg: mixed) => void,
close: Function,
}
@102
102 / 8893
Created September 1, 2017 08:07
8893
8893
@102
102 / gitstats.sh
Created March 15, 2017 08:12
Git additions/deletions stats by user
git log --pretty=format: --shortstat --no-merges --author=$1 \
| sed '/^$/d'\
| awk -F' ' '{s1+=$4;s2+=$6}END{printf "additions: %s; deletions: %s\n",s1,s2}'
@102
102 / gitcommitsbydate.sh
Last active July 11, 2023 00:22
get commits by author between two dates
# to get commit messages of user 'rgusev' betwen 2017-01-01 and 2017-31-12
# sh gitcommitsbydate.sh rgusev 2017-01-01 2017-31-12
git log --author=$1 --pretty=format:"%s" --no-merges --after="$2" --before="$3"
@102
102 / flatten.js
Last active July 20, 2016 07:08
js array flatten
const assert = require('assert');
function flatten(array) {
// Return argument if it isn't an array
if (!Array.isArray(array)) {
return array;
}
const result = [];