Skip to content

Instantly share code, notes, and snippets.

View norbornen's full-sized avatar
🐢

norbornen

🐢
  • Moscow, Russia
View GitHub Profile
@norbornen
norbornen / nodejs-postgresql-ssh-tunnel-proxy.js
Created October 14, 2020 12:31
Node.js postgresql connecting with ssh-tunnel proxy
const fs = require('fs');
const os = require('os');
const tunnelSsh = require('tunnel-ssh');
const { Pool } = require('pg');
(async () => {
/** @type {import('net').Server} */
let tunnel;
try {
@norbornen
norbornen / TT2PluralPlugin.pm
Last active January 31, 2020 15:14
Perl Template Toolkit multilang and pluralisation plugin
package Example::TT2::M;
use strict;
use warnings;
use base 'Template::Plugin';
use Locale::CLDR;
use Scalar::Util qw/looks_like_number/;
sub new {
@norbornen
norbornen / rssTitlesNodejsStreamParser.js
Last active November 7, 2019 15:05
load rss feed titles with node.js streams
#!/usr/bin/env node
// @ts-check
const https = require('https');
const { finished } = require('stream');
load_rss_feed_titles('https://news.google.com/rss?hl=en-US&gl=US&ceid=US:en')
.then(console.log).catch(console.error);
load_rss_feed_titles('https://news.google.com/rss?hl=ru&gl=RU&ceid=RU:ru')
.then(console.log).catch(console.error);
@norbornen
norbornen / jsreportClient.js
Last active November 7, 2019 15:57
nodejs jsreport client stream
// @ts-check
const fs = require('fs');
const client = require("jsreport-client")("http://localhost:5488");
const { finished } = require('stream');
(async () => {
try {
const data = {
"customer": "Тратата через атом!!",
function possibleSums(coins, quantity) {
let arr = new Set();
for (let i = 0, clen = coins.length; i < clen; i++) {
const coin = coins[i];
const qty = quantity[i];
const curr_sums = Array.from(arr);
const curr_coins = new Array(qty).fill().map((undefined, idx) => {
const n = coin * (idx + 1);
arr.add(n);
return n;
@norbornen
norbornen / passkit-webservice-swagger.json
Created October 8, 2019 09:04 — forked from ckrack/passkit-webservice-swagger.json
Passkit Webservice Swagger for Apple Wallet Webservice
{
"swagger": "2.0",
"info": {
"title": "Passkit Web Service",
"contact": {
"name": "Clemens Krack",
"email": "info@clemenskrack.com"
},
"version": "1.0.0"
},
const values = [1,2,null,3].map((x) => !!x || null);
const vlength = values.length;
let combinations = [];
for (let i = 0; i < vlength; i++) {
if (values[i]) {
let acc = [];
acc.push(new Array(vlength).fill(null).fill(true, i, i + 1));
for (let j = vlength - 1; j > i; j--) {
if (values[j]) {
acc = acc.concat(
@norbornen
norbornen / read-stream-async.js
Last active October 15, 2018 08:14
node.js stream with promisified reading (vanilla)
const fs = require('fs');
const path = require('path');
const testfile = path.join(path.resolve(), 'test.txt');
read(testfile);
async function read(filepath) {
const rstream = fs.createReadStream(filepath, {highWaterMark: 70, encoding: 'utf-8'});
let data;
@norbornen
norbornen / plain-list-to-tree.js
Created October 1, 2018 21:21
Превратить массив "плоских" объектов в массив объектов с вложенными детьми
#!/usr/bin/env node
const data = [
{ id: 3, parentId: 1 },
{ id: 2, parentId: 0 },
{ id: 6, parentId: 4 },
{ id: 4, parentId: 1 },
{ id: 7, parentId: 5 },
{ id: 5, parentId: 2 },
{ id: 1, parentId: 0 }
];
@norbornen
norbornen / move-first-string-to-eof.js
Last active January 21, 2023 05:25
move file first string to the end of file: node.js, stream
#!/usr/bin/env node
const fs = require('fs');
const {Buffer} = require('buffer');
const filepath = process.argv[2];
if (!filepath) {
console.log('\nДолжен быть указан путь к существующему файлу!\n');
process.exit(0);
}