Skip to content

Instantly share code, notes, and snippets.

View dkorolev's full-sized avatar
💭
Live long and prosper.

Dima dkorolev

💭
Live long and prosper.
View GitHub Profile
@dkorolev
dkorolev / echo.c
Created August 12, 2024 09:21
The `echo.c` using the `connection_context` ref. https://github.com/Theldus/wsServer/pull/93
/*
* Copyright (C) 2016-2023 Davidson Francis <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
function memoizer(fn) {
if (typeof fn !== 'function') {
console.error('Need a function.');
return () => {};
} else {
return (() => {
const cache = {};
eval(`
function memoized(...args) {
const impl = ${fn.toString().replace('{', `{ const ${fn.name} = memoized; `)}
// To run: `g++ -O3 calc.cc && ./a.out`.
// Example values to run on are commented out in lines 8..10.
#include <cmath>
#include <iostream>
#include <iomanip>
long double const range = std::pow(2.0, 64); // std::pow(1.0, 32); // 1e6;
long double const desired_p_of_collision = 0.01; // 1e-5; 1e-2; // 0.5;
long double const desired_log_p = logl(1.0 - desired_p_of_collision);
@dkorolev
dkorolev / sum.rego.ir.js
Created June 12, 2022 18:03
Example Rego => JavaScript transpiled code for `dkorolev/jsopa` README.
let function_bodies = {};
let plans = {};
const opa_builtins = {
plus: (args) => { return { t: 'number', v: args[0].v + args[1].v }; },
minus: (args) => { return { t: 'number', v: args[0].v - args[1].v }; },
mul: (args) => { return { t: 'number', v: args[0].v * args[1].v }; },
numbers: {
range: (args) => {
let v = [];
for (let i = args[0].v; i <= args[1].v; ++i) {
@dkorolev
dkorolev / sum.rego.ir.json
Created June 12, 2022 18:03
Example Rego IR JSON for `dkorolev/jsopa` README.
{
"static": {
"strings": [
{
"value": "result"
},
{
"value": "a"
},
{
al = 0
si = 0x500
ram[si] = al
++si;
++al;
ram[si] = al
cx = ram[0]
cx -= 2;
while (cx) {
al = ram[si - 1]
N = 8;
ram = [];
for (let i = 0; i < N; ++i) {
ram[0x500 + i] = 0;
}
ram[0] = N;
al = 0
si = 0x500
ram[si] = al
digraph test_setup {
rankdir = LR;
node [ shape = cylinder; label = "DB" ];
db_indexer;
db_forwarder;
node [ shape = box3d ];
{ rank = same; indexer; db_indexer; }
{ rank = same; forwarder; db_forwarder; }
generator [ label = "Generator"; ];
indexer [ label = "Indexer"; ];
digraph test_setup {
rankdir = LR;
node [ shape = cylinder; label = "DB" ];
db_indexer;
db1; db11; db12; db2; db21; db22; db3; db4; db5;
node [ shape = box3d ];
{ rank = same; indexer; db_indexer; }
source1 [ label = "Generator A"; ];
source2 [ label = "Generator B"; ];
source3 [ label = "RSocket Wrapper"; ];
@dkorolev
dkorolev / report_for_vle.txt
Created May 21, 2018 08:26
fgets() vs. gets() timing.
dima@dima-x1:~/github/dkorolev/current/examples/datafest_talk/tier2_rides_by_months@unstable $ cat step5_rides_by_months_unoptimized.c
// To run: gcc -O3 step5_rides_by_months_unoptimized.c && time ./a.out | tee >(md5sum)
//
// Count rides by month, print the counters in the lexicographically sorted order of keys.
// The "canonical C" implementation, with no extra checks, unsafe in a few ways, but still only 2x slower than `wc -l`.
#include <stdio.h>
int MM[12];