Skip to content

Instantly share code, notes, and snippets.

View maxp's full-sized avatar

Maxim Penzin maxp

View GitHub Profile
@maxp
maxp / thread-loop.clj
Last active March 3, 2019 08:12
threaded init/step/cleanup lifecycle
;;
;; mlib: run proccessing loop in separate thread
;;
(ns mlib.thread
(:require
[clojure.core.async :refer [thread <!!]]))
;
(defn- thread-loop [state' init step cleanup]
@maxp
maxp / express-https.ts
Created November 22, 2018 04:35
https listener and key generation example
/**
openssl req -newkey rsa:2048 -nodes -batch -utf8 -keyout keytemp.pem -x509 -days 365 -out cert.pem \
-subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com"
openssl rsa -in keytemp.pem -out key.pem
*/
@maxp
maxp / random-hex
Created November 22, 2018 04:29
oneliner: generate random hex using nodejs
node -e "console.log(require('crypto').randomBytes(20).toString('hex'))"
@maxp
maxp / csr_key
Last active September 18, 2018 03:43
create key and certificate request
openssl req -utf8 -sha256 -out ${NAME}.csr -new -newkey rsa:2048 -nodes -keyout ${NAME}.key
https://www.openssl.org/docs/man1.0.2/apps/openssl-req.html
openssl req -nodes -newkey rsa:2048 -keyout example.key -out example.csr \
-subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" \
-batch -utf8
-config "file"
@maxp
maxp / nodejs-sigterm.js
Last active August 15, 2018 14:51
nodejs SIGTERM handling
//
// https://hackernoon.com/graceful-shutdown-in-nodejs-2f8f59d1c357
//
const express = require('express');
const mongoose = require('mongoose');
const app = express();
app.use(express.urlencoded({extended: true}));
app.use(express.json());
@maxp
maxp / bitbucket-socks
Last active August 2, 2018 03:00
How to route ssh over socks5 on ssh.
start-socks:
ssh -NCD 9999 -qf your.not-blocked.host
---
.ssh/config:
Host bitbucket.org
ProxyCommand=nc -X 5 -x localhost:9999 %h %p
@maxp
maxp / docker_aliases.sh
Created July 26, 2018 03:33
Handy Docker aliases
#!/bin/sh
# https://medium.com/@cjus/handy-docker-aliases-4bd85089a3b8
alias dm='docker-machine'
alias dmx='docker-machine ssh'
alias dk='docker'
alias dki='docker images'
alias dks='docker service'
alias dkrm='docker rm'
let addrs = new Set()
// avoid while(true) {} loops
for(let bi = getReasonalbeStartingBlockIndex(); bi > 0; bi--) {
let block = await web3.eth.getBlock(bi)
if(stopCondition(block)) {
// block.timestamp < START_TIME
break;
}
@maxp
maxp / .gitignore
Last active November 18, 2021 07:57
Generic .gitignore
#
# maxp.dev: generic .gitignore
#
## no hiddens in scm
.*
## editor backups
*~
*.bak
@maxp
maxp / parse_json_time.go
Created October 27, 2017 01:19
How to handle custom time formats in json
type MyTime struct {
time.Time
}
func (self *MyTime) UnmarshalJSON(b []byte) (err error) {
s := string(b)
// Get rid of the quotes "" around the value.
// A second option would be to include them
// in the date format string instead, like so below: