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 / index.html
Created February 7, 2019 11:49
JS Bin example1 // source https://jsbin.com/kuhukal
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="example1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<h3>Check your console to see the output, press F12 and go to the console tab.</h3>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@alessioalex
alessioalex / swarmchat.html
Created September 18, 2018 21:08
swarmchat.html
<html>
<head>
<style>
.lines { height: 20em; }
input[type="text"] {
width: 500px;
padding: 5px;
}
</style>
@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 / such-wow.js
Created February 3, 2016 12:45
ES6 Proxy magic for arrays
// https://curiosity-driven.org/array-slices#mimicking-array
function emulateArray(obj) {
var length = obj.length || 0;
return new Proxy(obj, {
get: function(target, property) {
if (property === 'length') {
return length;
}
if (property in target) {
@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?
var fs = require('fs');
var CHUNK_SIZE = 4 * 1024;
var buffer = new Buffer(CHUNK_SIZE);
var filePath = __dirname + '/public/index.html';
// fs.open(filePath, 'r', function(err, fd) {
// if (err) throw err;
//
// fs.read(fd, buffer, 0, CHUNK_SIZE, null, function(err, nread) {
// if (err) throw err;