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
@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'}];
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: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: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 / gist:3450f3de83454fd266082bc009e87574
Last active August 8, 2017 13:05
tengine (nginx) backend process healthcheck in lua
location /health.pgrep {
default_type text/plain;
access_log off;
content_by_lua '
local io = require "io"
if (ngx.var.arg_q ~= nil and ngx.var.arg_q ~= "") then
-- Note: Testing this over 127.0.0.1 will always succeed.
local arg_q = ngx.var.arg_q:gsub("[;&|/\\\\ ]", "")
local c = assert(io.popen("/usr/bin/pgrep -f "..arg_q))
@zahna
zahna / gist:b302ee6d150405e5430855e53d5771ee
Last active August 8, 2017 13:05
render any number of recaptchas that are on a single page
In the page somewhere:
<script type="text/javascript" defer>
var gcRender = function() {
var sitekey, gcs, i, rcks, len;
sitekey = '';
// Render all .g-recaptcha's on the page
gcs = document.getElementsByClassName('g-recaptcha');
len = gcs.length;
for (i = 0; i < len; i++) {
@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