Skip to content

Instantly share code, notes, and snippets.

View numtel's full-sized avatar
🦓
Natural Ungulates Make Teeming Elephants Laugh

Ben Green numtel

🦓
Natural Ungulates Make Teeming Elephants Laugh
View GitHub Profile
@numtel
numtel / rummikub.js
Last active May 29, 2023 17:29
Rummikub
const crypto = require('crypto');
const http = require('http');
const url = require('url');
const ws = require('ws');
// Generate a new tileset with all tiles upside down in a random pile
const newRummikubGame = () => [1,2,3,4,5,6,7,8,9,10,11,12,13]
// Each ordinal in the various color sets, classname first, tile text second
.map(i => [['green', i], ['red', i], ['orange', i], ['blue', i]])
// Don't forget the wilds, ...except the mirror wild!
@numtel
numtel / breaking-the-rules.js
Created September 23, 2019 04:28
Node.js server example for chunked server events response handling
const http = require('http');
const url = require('url');
const querystring = require('querystring');
http.createServer((req, res) => {
const parsedUrl = url.parse(req.url);
switch(parsedUrl.pathname) {
case '/task':
// Browser RPC method
const PROGRESS_COUNT = 10, PROGRESS_INTERVAL = 300;
const globalHandlerKey = querystring.parse(parsedUrl.query).x;
@numtel
numtel / index.js
Last active February 20, 2018 23:08
node-raiblocks-pow threaded implementation starting
// Change index.js to this contents
var cp = require('child_process');
var os = require('os');
var addon = require('bindings')('functions.node');
function zeroPad(num, size) {
// Max 32 digits
var s = "00000000000000000000000000000000" + num;
return s.substr(s.length-size);
};
function genPow(hash, timeout) {
timeout = timeout || 15000000;
const start = Date.now();
const hashBytes = hex_uint8(hash);
let i=0;
while(Date.now() - start < timeout) {
const workBytes = nacl.randomBytes(8);
for(let j=0;j<256;j++) {
workBytes[7] = j;
@numtel
numtel / ec2-rai-node.md
Last active May 12, 2019 22:18
Install rai_node on EC2 Ubuntu instance

Follow these instructions to start an EC2 instance running Ubuntu that will run rai_node on startup

  1. Select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type. A t2.small or larger instance type is recommended.

  2. Configure the security group to match the screenshot.

  3. Download install_rai_node.sh below, update the URLs with their latest versions.

    Get latest rai_node archive URL from https://github.com/clemahieu/raiblocks/releases.

    Get latest gdrive-linux-x64 version URL from https://github.com/prasmussen/gdrive#downloads

@numtel
numtel / AWSPingTest.js
Created May 14, 2017 07:59
Find your closest AWS region
'use strict';
(function() {
// inspired by cloudping.info
var regions = {
'us-east-1': 'US-East (Virginia)',
'us-east-2': 'US East (Ohio)',
'us-west-1': 'US-West (California)',
'us-west-2': 'US-West (Oregon)',
'ca-central-1': 'Canada (Central)',
'eu-west-1': 'Europe (Ireland)',
@numtel
numtel / aws-lambda-fetch-npm.js
Created September 2, 2016 04:08
AWS Lambda example to fetch an NPM package inline, works only if the package has no dependencies
'use strict';
const asyncProgressPromise = fetchNPM('progress-promise', '0.0.5');
exports.handler = (event, context, callback) => {
asyncProgressPromise
.then(ProgressPromise => {
console.log(ProgressPromise);
callback();
})
@numtel
numtel / example.js
Last active August 4, 2023 09:07
Restart ZongJi gracefully on error
var ZongJi = require('zongji');
var RETRY_TIMEOUT = 4000;
function zongjiManager(dsn, options, onBinlog) {
var newInst = new ZongJi(dsn, options);
newInst.on('error', function(reason) {
newInst.removeListener('binlog', onBinlog);
setTimeout(function() {
// If multiple errors happened, a new instance may have already been created

From what I can tell, accomplishing a more automatic lazy-loading system would require the current file bundling scheme to be amended to support applications written with explicit source file dependency trees.

With the dependency tree, an intelligent lazy-loader could decide which files are necessary for which routes/templates.

In order to not break compatibility with existing applications, the directories used must become configurable.

The default configuration could be described in a file such as .meteor/dirmap.json:

{
@numtel
numtel / gist:c8f9b883b4bbbfab6abd
Created April 26, 2015 09:05
Javascript Async style memory usage

Async/await style (i.e. how most of this package's code is written)

module.exports = async function() {
  await delay(1)
}

function delay(duration) {
  return new Promise(resolve => setTimeout(resolve, duration))
}