Skip to content

Instantly share code, notes, and snippets.

View andreif's full-sized avatar
👾
invading spaces

Andrei Fokau andreif

👾
invading spaces
View GitHub Profile
# Tutorial: http://mysshlog.co.uk/tutorials/Python-Simple-Dns-Server
# Source: http://mysshlog.co.uk/download/Dns_Server_Python.py
## {{{ http://code.activestate.com/recipes/491264/ (r4)
#Edited By MySSHLog.co.uk
import socket
import optparse
import time
class DNSQuery:
def __init__(self, data):
@andreif
andreif / daemon.md
Last active May 8, 2024 00:17
A simple unix/linux daemon in Python

A simple unix/linux daemon in Python

Source: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

Access: http://web.archive.org/web/20131025230048/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

by Sander Marechal

I've written a simple Python class for creating daemons on unix/linux systems. It was pieced together for various other examples, mostly corrections to various Python Cookbook articles and a couple of examples posted to the Python mailing lists. It has support for a pidfile to keep track of the process. I hope it's useful to someone.

# coding=utf-8
"""
LICENSE http://www.apache.org/licenses/LICENSE-2.0
"""
import datetime
import sys
import time
import threading
import traceback
import SocketServer

Example of Go AWS Lambda using stdlib only

Source

Create a main.go file:

package main

import (
import { Construct } from 'constructs';
import { CfnOutput, Stack } from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
export function output(scope: Construct, name: string, value: string) {
return new CfnOutput(scope, name, {
value,
exportName: `${Stack.of(scope).stackName}:${name}`,
});
}
@andreif
andreif / Makefile
Created February 21, 2024 09:56
.npmrc
# $(call secret,region,account,secret_id)
define secret
$(shell aws secretsmanager get-secret-value \
--region $(1) --secret-id arn:aws:secretsmanager:$(1):$(2):secret:$(3) \
--output text --query SecretString)
endef
.npmrc: NPM_TOKEN ?= $(call secret,eu-west-1,1234567890,npm-readonly-token)
.npmrc:
@test -n "${NPM_TOKEN}" || (>&2 echo "Error: NPM_TOKEN is missing"; exit 1)
@andreif
andreif / sso-oidc.py
Last active February 19, 2024 09:29
AWS auth via SSO OIDC
import os
from time import sleep
import boto3
from utils import dump as _print, list_all
import cache
FORCE = False
ROLE_NAME = os.environ['ROLE_NAME']
@andreif
andreif / AWS-list-accounts.sh
Last active February 14, 2024 09:29
List AWS accounts and format in Markdown
aws organizations list-accounts --query Accounts \
| jq -r 'sort_by(.Name) | .[] | [.Id,.Name] | @csv' \
| sed 's/"//g' \
| sed -E 's/^([0-9]+),/- [ ] `\1` /g'
import http.server
class Handler(http.server.BaseHTTPRequestHandler):
def __getattr__(self, item):
if item.startswith('do_'):
return self.default
return getattr(super(), item)
def default(self):
@andreif
andreif / Cloud Build and Cloud Run example.md
Last active January 6, 2024 21:42
Cloud Build and Cloud Run example

Cloud Build and Cloud Run example

PROJECT=my-project-123456  make setup build-and-deploy