Skip to content

Instantly share code, notes, and snippets.

View neumachen's full-sized avatar
🏠
Working from home

KH neumachen

🏠
Working from home
  • Bergen, Norway
View GitHub Profile
@neumachen
neumachen / flask-uWSGI-nginx.md
Created August 6, 2019 19:28 — forked from bluekvirus/flask-uWSGI-nginx.md
How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 14.04+

How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 14.04

@credit Yan Zhu (https://github.com/nina-zhu)

Introduction

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions, it can help you get your Python application or website off the ground. Flask includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server is required.

In this guide, we will demonstrate how to install and configure some components on Ubuntu 14.04 to support and serve Flask applications. We will configure the uWSGI application container server to interface with our applications. We will then set up Nginx to reverse proxy to uWSGI, giving us access to its security and performance features to serve our apps.

Prerequisites and Goals

@neumachen
neumachen / Dockerfile
Created August 8, 2019 18:58 — forked from knowsuchagency/Dockerfile
Makefile Docker Git GitHub multi-stage build ssh private key recipe
FROM python:3 as build-system
RUN pip install -U pip
COPY requirements.txt requirements.txt
### create temporary image used to download and vendor packages using private key ###
FROM build-system as intermediate
# add credentials on build
@neumachen
neumachen / gist:09d9389526811bef092cc22fccccb8a3
Created August 14, 2019 19:24 — forked from kirley/gist:3913166
Setting up PostGIS for Timezone Lookup
@neumachen
neumachen / logger.py
Created October 14, 2019 14:15 — forked from impredicative/logger.py
Python json logging using structlog and stdlib logging
"""
Usage example:
from logger import get_logger
log = get_logger()
log.info('my_event', my_key1='val 1', my_key2=5, my_key3=[1, 2, 3], my_key4={'a': 1, 'b': 2})
List of metadata keys in each log message:
event
_func
@neumachen
neumachen / tmux.md
Created October 19, 2019 20:06 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@neumachen
neumachen / main.go
Created March 11, 2020 11:44 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
package main
import (
"fmt"
"time"
"golang.org/x/sync/errgroup"
"context"
"os"
"syscall"
"os/signal"
@neumachen
neumachen / roman_numerals.rb
Created March 12, 2020 21:48 — forked from mecampbellsoup/roman_numerals.rb
Awesome roman numeral algorithm in Ruby :)
require 'pry'
# ```
# 1 => I
# 10 => X
# 7 => VII
# ```
# There is no need to be able to convert numbers larger than about 3000. (The Romans themselves didn't tend to go any higher)

Assuming this table definition:

CREATE TABLE segments (segments_id serial PRIMARY KEY, payload jsonb);
With JSON values like this:

INSERT INTO segments (payload)
VALUES ('{
     "a": [
        {

"kind": "person",

@neumachen
neumachen / sed cheatsheet
Created July 1, 2020 21:15 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@neumachen
neumachen / docker-image-size.sh
Created August 12, 2020 00:49 — forked from andyrbell/docker-image-size.sh
Sort docker images by size desc
#!/bin/sh
docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t