Skip to content

Instantly share code, notes, and snippets.

@zahna
zahna / gist:59fb516285d9295025463d4c96720950
Last active February 9, 2023 22:57
WSL2 distro stuff
Related Links:
https://docs.microsoft.com/en-us/windows/wsl/use-custom-distro
http://cloud-images.ubuntu.com/wsl/
https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/
https://cloudlinuxtech.com/install-linux-on-windows-10-wsl/
https://docs.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions
To install WSL2:
https://docs.microsoft.com/en-us/windows/wsl/install-win10
cd $HOME
git clone git@github.com:pyenv/pyenv.git .pyenv
In your .profile, add:
# Initialize pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
Then:
. .profile
https://github.com/Neilpang/acme.sh.git
cd /var/www/acme.sh
./acme.sh --issue --standalone --home /var/www/ssl --cert-home /var/www/ssl --httpport 8080 -d www.zahna.com -d zahna.com
./acme.sh --renew --standalone --home /var/www/ssl --cert-home /var/www/ssl --httpport 8080 -d www.zahna.com -d zahna.com
@zahna
zahna / gist:649b634048d758f513a6cd9925c5c61b
Last active February 11, 2020 21:45
nginx proxy to different local backend sites, depending on a variable
map $http_x_forwarded_for $backend_site {
~^[6] www1.zahna.com;
default www2.zahna.com;
}
server {
listen 80;
listen 443 ssl;
server_name dfas78dsf9sa.cloudfront.net;
access_log /dev/null;
location / {
@zahna
zahna / gist:d0a4b74ba332109c1dbd1ac4dd6c0215
Created October 16, 2019 18:38
Lambda@Edge to rewrite Host: header in Cloudfront based on client IP address
// https://gist.github.com/prenagha/886c44526c7e9b1bc9e904900687f6b0
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-permissions.html
'use strict';
exports.handler = (event, context, callback) => {
let request = event.Records[0].cf.request;
if (request['clientIp'].match(/^[456]/)) {
request.headers['x-client-ip-match'] = [{'key': 'X-Client-IP-Match', 'value': 'true'}];
@zahna
zahna / gist:f3252db9eaf11eb6ac1dac0dedc202ac
Last active July 26, 2019 15:07
Python module quick steps
put module code in a git repo, push to github
pip install -e /path/to/module/code
pip install -e git+https://github.com/<project.git>#egg=master <-- installs to $HOME/src/master for further developing
pip install git+https://github.com/<project.git>#egg=master <-- pip installs from a git repo, rather than pypi
register a username at both http://test.pypi.org and http://pypi.org.
Setup ~/.pypirc file:
```[distutils]
@zahna
zahna / waf.lua
Last active June 24, 2018 18:01
-- https://github.com/openresty/lua-nginx-module#nginx-api-for-lua
-- https://www.nginx.com/resources/wiki/modules/lua/
-- http://www.staticshin.com/programming/definitely-an-open-resty-guide/
-- access_by_lua_file /path/to/waf.lua;
-- examine request
ngx.req.read_body()
local request_method = ngx.req.get_method()
local get_args = ngx.req.get_uri_args()
local post_args, err = ngx.req.get_post_args()
@zahna
zahna / gist:9712d69257ef388bee28f45319c1a44e
Last active October 31, 2017 19:54
creating a git branch to github upstream project
https://help.github.com/articles/syncing-a-fork/
http://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository
git remote add upstream https://github.com/whoever/whatever.git
git fetch upstream
git checkout master
git rebase upstream/master -or- git merge upstream/master
<resolve conflicts>
git add <files>
git rebase --continue
@zahna
zahna / gist:ee9c7d85400800b4873289213086813f
Created October 2, 2017 20:38
optimized natural sorting key function
def alphanum_key(s):
'''http://nedbatchelder.com/blog/200712/human_sorting.html'''
tryint = lambda s: int(s) if s.isdigit() else s
return [ tryint(c) for c in re.split('(\d+)', s) ]
alist.sort(key=alphanum_key)
@zahna
zahna / gist:63783dba265269ea09a6c75e4d7bad62
Last active August 8, 2017 13:08
initializing my ansible dynamic inventory data structure
# Initialize the inventory
inventory = {}
inventory['all'] = {'hosts': [], 'vars': {}}
inventory['_meta'] = {'hostvars': {}}
# Add localhost to inventory
inventory['all']['hosts'].append('localhost')
inventory['_meta']['hostvars']['localhost'] = {}
inventory['_meta']['hostvars']['localhost']['ansible_host'] = 'localhost'
inventory['_meta']['hostvars']['localhost']['ec2_public_dns_name'] = 'localhost'
inventory['_meta']['hostvars']['localhost']['ec2_public_ip_address'] = '127.0.0.1'