Skip to content

Instantly share code, notes, and snippets.

View alessioalex's full-sized avatar

Alexandru Vlăduţu alessioalex

View GitHub Profile
@alessioalex
alessioalex / domtokenlist.js
Created October 22, 2021 19:17 — forked from ShirtlessKirk/domtokenlist.js
DOMTokenList polyfill for IE < 9; implements element.classList
/**
* Polyfill of DOMTokenList for IE < 9
* Monkey patch of .add, .remove for IE 10 / 11, Firefox < 26 to support multiple arguments
* Monkey patch of .toggle for IE 10 / 11, Firefox < 24 to support second argument
*/
/*global define: false, module: false */
/*jslint nomen: true */
(function domTokenListModule(global, definition) { // non-exporting module magic dance
'use strict';
@alessioalex
alessioalex / htmldiff.js
Created January 31, 2021 16:11 — forked from bcks/htmldiff.js
htmldiff
(function() {
var Match, calculate_operations, consecutive_where, create_index, diff, find_match, find_matching_blocks, html_to_tokens, is_end_of_tag, is_start_of_tag, is_tag, is_whitespace, isnt_tag, op_map, recursively_find_matching_blocks, render_operations, wrap;
is_end_of_tag = function(char) {
return char === '>';
};
is_start_of_tag = function(char) {
return char === '<';
};
@alessioalex
alessioalex / sjcl-example.js
Created July 11, 2018 12:52 — forked from yetanotherchris/sjcl-example.js
Stanford Javascript Crypto Library basic AES example
// Basic AES example using the defaults.
// https://github.com/bitwiseshiftleft/sjcl
var password = "password";
var text = "my secret text";
var parameters = { "iter" : 1000 };
var rp = {};
var cipherTextJson = {};
sjcl.misc.cachedPbkdf2(password, parameters);
@alessioalex
alessioalex / sendfile.js
Created March 13, 2012 17:49 — forked from pgriess/sendfile.js
Using sendfile(2) with NodeJS
var assert = require('assert');
var net = require('net');
var open = process.binding('fs').open;
var sendfile = process.binding('fs').sendfile;
if (process.argv.length < 4) {
console.error('usage: sendfile <port> <path>');
process.exit(1);
}
@alessioalex
alessioalex / server.js
Last active May 27, 2016 07:06 — forked from koistya/server.js
Async node-postgres sample code
/*
import express from 'express';
import db from './core/db';
const app = express();
const port = process.env.PORT || 3000;
app.get('/visits', (req, res, next) => {
db.connect(async ({ query } => {
await query('INSERT INTO visit (date) VALUES ($1)', new Date());
@alessioalex
alessioalex / System Design.md
Created April 18, 2016 07:12 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
/**
* POST to create a new user.
*/
exports.create = function *(){
var body = yield parse(this);
// password
var pass = body.password;
assert(pass, 400, 'password is required');

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

{
"name": "my-app",
"version": "0.0.0",
"dependencies": {
"browserify": "~2.36.1",
"less": "~1.5.1"
},
"devDependencies": {
"watchify": "~0.4.1",
"catw": "~0.2.0"

node-websocketd

A lightweight node port of websocketd, originally written in go.

Usage

node-websocketd --port=8080 ./count.sh