Skip to content

Instantly share code, notes, and snippets.

View lpinca's full-sized avatar

Luigi Pinca lpinca

  • Foligno (PG), Italy
View GitHub Profile
@lpinca
lpinca / prng.js
Last active January 23, 2023 22:19
Pseudorandom number generator based on crypto.randomBytes
var crypto = require('crypto')
, rrange = 4294967296;
/**
* Return an integer, pseudo-random number in the range [0, 2^32).
*/
var nextInt = function() {
return crypto.randomBytes(4).readUInt32BE(0);
};
@lpinca
lpinca / prng.js
Last active December 16, 2015 06:19
SRANDMEMBER lacks randomness
/**
* Module dependencies.
*/
var crypto = require('crypto')
, rrange = 4294967296;
/**
* Return an integer, pseudo-random number in the range [0, 2^32).
*/
@lpinca
lpinca / client.js
Created December 20, 2013 09:32
Primus WebSocket not opened issue
'use strict';
var Ws = require('ws')
, ws = new Ws('ws://localhost:3000/primus');
ws.on('open', function() {
var buf = new Buffer([
0x88, // state.lastFragment = true && opcode = 8
0x02, // state.masked = false && length = 2
0x03, // this byte and the next => code = 1000
@lpinca
lpinca / heartbeat.js
Created January 29, 2014 19:21
Spark heartbeat timeout test when streaming a huge file from server to client
'use strict';
var fs = require('fs')
, server
, Primus = require('primus')
, server = require('http').createServer()
, primus = new Primus(server);
primus.on('connection', function(spark) {
console.log(spark.id + ' connected');
@lpinca
lpinca / destruction.js
Last active August 29, 2015 13:56
Chaos and destruction
var chars = '̴̴̛̮̫̞͚͉̮̙͕̳̲͉̤̗̹̮̦̪̖̱͍͙̖̟͕̹͕̙̦̣̲̠̪̯̳͖̝̩̝̦͇̥̠̟͚̳̤̹̗̻̭͍͖͕͓̻̥̹̮̙͔̗͍͚͓̗̦̹͈͙͕̘̮͖̝̗̲̤̗̮͈̙͈̹̼̣̹̖̱̤̼̺̤̻͙̗̥̠̱͇̱̝̟̺͍̺̼̜̖͈͇͎͙̲̙̗͇̫̘̖̹͖͓͔̺̱̹͓̮͇̯̜̤̗͍̯̰̫̫̖̰͚̪͚̭͚̥̰̤̟͎̝̲̯̭̹̭̙̼̤͖̞̙̹͈͚̥̦͚͉͖̼̬͓͚̳͉͙͎͚̱̮̗͍̩̻̰̣̫͉͈̞̲͉̫̞͔͆̅̓̓̇ͬ͌ͬͫͩͦ̃͌̿̐ͪͩ̌̇͂̆̑͐ͣ҉̶̲͉͔͎̤̼̘͇̮̥̻̜̹̥͚̲̻̖̗̻̫̼̠̳̗̺̤̗̳͈̪̮̗̝͇͈̙͇͕̺̱̼̤̗̰̬̣͌ͬͧ͊́ͧͩ͌͌̐̓̃ͥ̄ͤ͑̈ͬ͆ͬ͂̇̿̅҉̨̙̼̳̭̙͍̻̱̠͈̮̺̣̝̱̙̺͉̳͎̻͔̯̪̝͕͚̣̜̼̞͇̠̘̠̪̫͙͙̬̰̰̫͚̗͕̝̤̗͕̲̮̝̼̺͙͚̟͓̣̥͍͙̘̩̖͇͎̬̠̝͈̺̙̮̬̗̪̤͕͇͕̰̮͖͉̬̙̪̤̝̹͖͖̻̬̹͙̞̗͓̞̭̜̠̟̐͋͊͑̌̾̉͆̆̍̿̾ͤ̔̉̈̂̾̈ͭ'
, len = chars.length
, str = 'foo and bar'
, result = '';
str.split('').forEach(function char(chr) {
for (var i = 0; i < 20; i++) {
var r = Math.floor(Math.random() * len);
chr += chars.charAt(r);
}
@lpinca
lpinca / cert.pem
Last active August 29, 2015 13:56
Primus secure WebSocket
-----BEGIN CERTIFICATE-----
MIICATCCAWoCCQDuPBBeAphl0zANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
cyBQdHkgTHRkMB4XDTE0MDIyNjE5MTg0OVoXDTE0MDMyODE5MTg0OVowRTELMAkG
A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0
IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA68hH
8JNVn7mGxtSRl+GI+jw12t5kX7+ML42pHteynBki1FmNnYAgUekQ8EnGCwXyUOaD
YxglhAv6Yu0tggE1hcJNbDh4a6N2B02fUcIwEHPGWJNVEB8L92mfDc0tS00a5Drp
yv3T965R0HF7GNlF1MU3Y3V6rk0WNWv1sECVCQkCAwEAATANBgkqhkiG9w0BAQUF
AAOBgQDOUWndwR84vPQKgyYEjK/wspVQ7Rp7qV6VYezTLGJJYhdOgH6xqoGzcj/5
@lpinca
lpinca / client.js
Created March 25, 2014 11:47
Test case for SockJS retransmission timeout issue
var sock = new SockJS('/test', null, {
protocols_whitelist: ['jsonp-polling']
});
sock.onopen = function () {
console.log('open');
};
sock.onerror = function (err) {
console.log(err);
};
sock.onmessage = function (e) {
@lpinca
lpinca / time.diff
Created March 26, 2014 08:57
Required time for a connection to be established (IE8 + SockJS + jsonp-polling)
--- sockjs-0.3.4.js 2014-03-26 09:49:46.000000000 +0100
+++ sockjs-0.3.4-m.js 2014-03-26 09:55:07.000000000 +0100
@@ -933,6 +933,8 @@
* ***** END LICENSE BLOCK *****
*/
+var timestamp;
+
var SockJS = function(url, dep_protocols_whitelist, options) {
if (this === _window) {
@lpinca
lpinca / client.js
Last active January 16, 2016 21:36
Engine.IO client `xhr.status = 0` issue
(function () {
var socket = new eio.Socket({
rememberUpgrade: false,
transports: ['polling']
});
socket.on('open', function () {
console.log('open');
socket.on('message', function (data) {
console.log(data);
@lpinca
lpinca / Procfile
Created April 13, 2014 10:49
Heroku Primus wss test
web: node server.js