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 / 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 / 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:
function isObject(obj) {
return obj !== null && typeof obj === 'object';
}
const isArray = Array.isArray;
function isPlainObject(obj) {
return isObject(obj) && (
obj.constructor === Object // obj = {}
|| obj.constructor === undefined // obj = Object.create(null)

Keybase proof

I hereby claim:

  • I am maxp on github.
  • I am mpenzin (https://keybase.io/mpenzin) on keybase.
  • I have a public key whose fingerprint is C086 D0BB A73A 97D5 B486 C516 F5F1 67A9 3283 443B

To claim this, I am signing this object: