Skip to content

Instantly share code, notes, and snippets.

View jpedro's full-sized avatar
🐤

Pedro Barbosa jpedro

🐤
View GitHub Profile
@jpedro
jpedro / server.py
Created October 16, 2019 17:41 — forked from martijnvermaat/server.py
SimpleHTTPServer with history API fallback
#!/usr/bin/env python
"""
Modification of `python -m SimpleHTTPServer` with a fallback to /index.html
on requests for non-existing files.
This is useful when serving a static single page application using the HTML5
history API.
"""
@jpedro
jpedro / blog.md
Created March 5, 2020 18:44 — forked from mattstauffer/blog.md
Serving Statamic data from in-memory cache

Ed Finkler (Funkatron) asked me, in response to my recent article introducing Statamic, whether you could change Statamic's settings to serve from something other than the local disk.

I checked with Jason & Jack at Statamic, and they told me three things:

  1. Statamic already has the ability (if configured a certain way) to compile all the files down to HTML. It's possible (I don't know how yet, but I know it is) to configure Nginx to serve those files directly.
  2. Statamic v1 has a static site generator built-in, and v2 will get one soon.
  3. Since Statamic's .env file effects the behavior of its Laravel core, you can change the cache driver that your Statamic app is using just like you would in any Laravel app. Just add a CACHE_DRIVER key in .env file and set it to any of the options: 'file', the default; 'database'; 'memcached'; 'redis';
@jpedro
jpedro / SSL-certs-OSX.md
Created March 11, 2020 16:49 — forked from croxton/SSL-certs-OSX.md
Generate ssl certificates with Subject Alt Names

Generate ssl certificates with Subject Alt Names on OSX

Open ssl.conf in a text editor.

Edit the domain(s) listed under the [alt_names] section so that they match the local domain name you want to use for your project, e.g.

DNS.1   = my-project.dev

Additional FQDNs can be added if required:

@jpedro
jpedro / add_cert.sh
Created March 11, 2020 18:58 — forked from caleb531/add_cert.sh
Scripts for creating and managing simple SSL certificates on macOS (useful for local HTTPS)
#!/usr/bin/env bash
cert_file="$1"
key_file="$2"
CERT_CONF="$(dirname "${BASH_SOURCE[0]}")"/cert-conf.cfg
if [ ! -f "$cert_file" ]; then
cert_hostname="$3"
#!/usr/bin/env sh
VBOX_LATEST_VERSION=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso -O /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso
sudo mkdir -p /media/guestadditions ; sudo mount -o loop /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso /media/guestadditions
sudo /media/guestadditions/VBoxLinuxAdditions.run
sudo umount /media/guestadditions && sudo rm -rf /tmp/VBoxGuestAdditions_$VBOX_VERSION.iso /media/guestadditions
echo 'You may safely ignore the message that reads: "Could not find the X.Org or XFree86 Window System."'
@jpedro
jpedro / jq-insert-var.sh
Created March 25, 2020 07:49 — forked from joar/jq-insert-var.sh
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
@jpedro
jpedro / topwaits.py
Created July 8, 2020 19:53 — forked from midom/topwaits.py
stall detector!
#!/usr/bin/env bcc-py
#
# topwaits Show longest off-cpu waits per-stack
#
# Copyright 2019 Facebook, Inc.
# Copyright 2016 Netflix, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 13-Jan-2016 Brendan Gregg Wrote offcpu profiler
# 27-Nov-2019 Domas Mituzas Gutted most of profiling part and left stall detector
@jpedro
jpedro / latency.txt
Created August 14, 2020 01:09 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@jpedro
jpedro / airflow.cfg
Created September 8, 2020 04:43 — forked from kysnm/airflow.cfg
[core]
airflow_home = /etc/airflow
dags_folder = /home/airflow/gcs/dags
base_log_folder = /home/airflow/gcs/logs
plugins_folder = /home/airflow/gcs/plugins
remote_logging = True
remote_log_conn_id = google_cloud_default
remote_base_log_folder = gs://asia-northeast1-settings-te-xxxxxxxx-bucket/logs
executor = CeleryExecutor
dags_are_paused_at_creation = False
@jpedro
jpedro / cidrs.sh
Last active August 27, 2021 17:06
Generates all CIDR ranges from an initial CIDR split by subnet MASK
#!/usr/bin/env bash
### SYNOPSIS
### Generates all CIDR ranges from an initial CIDR split by subnet MASK
###
### USAGE
### cidrs <CIDR> <MASK>
###
### EXAMPLE
### cidrs 10.240.0.0/21 /25
###