Skip to content

Instantly share code, notes, and snippets.

View zaiste's full-sized avatar
🌀
Loading...

Jakub Neander zaiste

🌀
Loading...
View GitHub Profile
@zaiste
zaiste / postgresql-copy-csv-import-export.md
Last active September 2, 2024 09:50
Using PostgreSQL's COPY to import & export CSV files

Using PostgreSQL's COPY to import & export CSV files

COPY can read/write data not only from/to CSV, but also from/to binary files. For the import, the table must exist along with its columns matching CSV columns.

Export table to CSV

COPY <table> TO 'file.csv' DELIMITER ',' CSV HEADER; 
@zaiste
zaiste / rst_to_md.sh
Created February 5, 2017 18:54
Convert RST to Markdown using Pandoc
FILES=*.rst
for f in $FILES
do
filename="${f%.*}"
echo "Converting $f to $filename.md"
`pandoc $f -f rst -t markdown -o $filename.md`
done
@zaiste
zaiste / swift.md
Created February 5, 2017 17:42
SWIFT/BIC for Polish banks
Bank Name SWIFT/BIC Code
ALIOR BANK ALBPPLPW
ALIOR Sync ALBPPLPW
ABN AMRO BANK ABNAPLPW
ALLIANZ BANK ALLBPLPW
CREDIT AGRICOLE AGRIPLPR
BANK POLSKIEJ SPÓŁDZIELCZOŚCI POLUPLPR
BPH BPHKPLPK
BGŻ (Bank Gospodarki Żywnościowej) GOPZPLPW
@zaiste
zaiste / nodejs-child-process-spawn-exec-fork-async-await.org
Last active February 27, 2023 15:04
Node.js: Child Processes using spawn, exec, fork & async/await [DRAFT]

Node.js Child Processes using spawn, exec, fork & async/await

Blog post: https://zaiste.net/nodejs-child-process-spawn-exec-fork-async-await/

Node.js runs in a single thread. You can, however take advantage of multiple processes.

child_process module allows to create child processes in Node.js. Those processes can easily communicate with each other using a built-in messaging system.

@zaiste
zaiste / install-tmux-without-root-access.sh
Created January 18, 2018 18:53
Install tmux without root access (tmux 2.6, libevent 2.1.8, ncurses 6.0)
#!/bin/bash
set -e
mkdir -p $HOME/bin $HOME/src
cd $HOME/src
wget https://github.com/tmux/tmux/releases/download/2.6/tmux-2.6.tar.gz
wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.0.tar.gz
@zaiste
zaiste / app.js
Created March 4, 2020 16:21
Fun with Pure Engine
const { compile } = require('pure-engine')
const escape = require('escape-html')
const fs = require('fs-extra');
async function example() {
const content = await fs.readFile('./index.html');
const { template } = await compile(content.toString())
console.log(template({ foo: 'bar' }, escape))
}
class String
def unindent
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
end
end
def display
text = <<-TEXT.unindent
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
@zaiste
zaiste / secure-rest-api-nodejs-without-jwt.md
Created May 7, 2019 12:23
Creating Secure REST APIs in Node.js without JWTs

Creating Secure REST APIs in Node.js without JWTs

Before we go on creating an actual RESTful API, let's address the elephant in the room: how to make an HTTP endpoint sufficiently secure in Node.js ?

I say sufficiently because, the topic of security is broad and constantly evolves. This article is a response to other Node.js articles I've seen that contain security mistakes. It may not be perfect, either, but is hopefully a good evolution on the topic.

Check the full article.

Version URL Req/s Avg Req/s Max Req/s Total Latency Avg Latency Max
Node.js Bare 11.14.0 2180 3410 54257 8.49 1.84 6.49
Fastify 2.3.0 2170 5240 54068 8.46 1.85 5.63
Szelmostwo (Huncwot's Core) 0.5.1 3440 5460 85482 8.80 1.17 3.55
Huncwot 0.40.0 https://huncwot.org/ 3430 6020 85167 8.77 1.17 3.48
uWebSockets 15.10.0 6840 7180 170266 19.97 0.58 1.53
Trek Router 0.0.1 1760 3120 43777 6.22 2.28 6.81
Kemal 3750 30940 93217 11.82 1.07 2.07
Turbo HTTP 0.3.2 3220 5700 80123 9.70 1.25 3.46
const Szelmostwo = require('./');
const { ok, json, created } = require('./response');
const { serve, security } = require('./middleware');
const app = new Szelmostwo();
app.get(
'/',
security(),