Skip to content

Instantly share code, notes, and snippets.

View niklaswall's full-sized avatar

Niklas Wall niklaswall

View GitHub Profile
@niklaswall
niklaswall / request-logger.js
Created September 8, 2022 16:39
Supersimple NodeJS express-ish request logger
module.exports = {
requestLogger: (req, res, next) => {
function newWriteHead(prevWriteHead) {
return function writeHead(statusCode) {
let log = {
ts: new Date().toISOString(),
statusCode,
method: req.method,
originalUrl: req.originalUrl,
@niklaswall
niklaswall / hosts.py
Created June 25, 2020 08:00
Ansible DNS hosts repository
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import json
import socket
import subprocess
@niklaswall
niklaswall / export_elastiscsearch_source_documents.py
Created June 3, 2020 16:15
Python script that exports source documents from a exlasticsearch index
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
# Update constants below for connection and index information.
# Run with: export_elastiscsearch_source_documents.py | gzip > export.json.gz
from __future__ import print_function
from elasticsearch import Elasticsearch, helpers, exceptions
import json
import sys
// Quick hack to iterate over domain names with numbers and resolve their IPv4 addresses
// Example: prefix1.domain.com ... prefix100.domain.com
const dns = require("dns");
const prefixes = ["se", "de", "ie", "uk", "us"];
const suffixes = [".domain.com", ".another.com"];
const min = 1;
const max = 10;
function check(hostname) {
// Though the call to dns.lookup() will be asynchronous from JavaScript's
### Keybase proof
I hereby claim:
* I am niklaswall on github.
* I am secnic (https://keybase.io/secnic) on keybase.
* I have a public key ASAM4lKjCMC11ThJHgIPWK3VKyTIMmWHJ6ZYClRubT-g9Qo
To claim this, I am signing this object: