Skip to content

Instantly share code, notes, and snippets.

import ipaddress
from typing import Union, List
class Network:
def __init__(self, network_ips: List[str]):
self.nets = [ipaddress.ip_network(nip) for nip in network_ips]
http --headers \ # Print out the response headers (they would otherwise be supressed for piped ouput)
--download \ # Enable download mode
--output=./body \ # Save response body to this file
httpbin.org/get 2>&1 \ # Merge STDERR into STDOUT (with --download, console output otherwise goes to STDERR)
| grep HTTP/ \ # Find the Status-Line
| cut -d ' ' -f 2 # Get the status code
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
@jkbrzt
jkbrzt / ansible-verify-github-ssh-login.yml
Created January 2, 2015 11:43
Ansible task to verify that it's possible to login to github.com via SSH using forward agent
- name: Verify GitHub SSH login
tags:
- debug
- deploy
shell: |
ssh_output=$(ssh -T [email protected] &>/dev/stdout)
echo
echo Should not be empty:
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
@jkbrzt
jkbrzt / django-email-as-username.py
Last active April 4, 2016 18:41
Sane email-as-username Django setup
# models.py
from django.core.exceptions import ValidationError
from django.core.validators import EmailValidator
from django.db.models.signals import pre_save
from django.contrib.auth.models import User
def _user_clean(user):
"""
Require the value of `username` to be an email. The `email` field
@jkbrzt
jkbrzt / install-python.sh
Last active August 26, 2016 14:43
Download, compile, and install Python on RHEL or CentOS. Tested with CentOS 6 + Python 2.7.3 and CentOS 7 + Python 3.4.1
VERSION="3.4.1"
yum -y install gcc openssl-devel
rm -rf Python-${VERSION}*
wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz
tar -xvzf Python-${VERSION}.tgz
cd Python-${VERSION}
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
echo "/usr/local/lib" > /etc/ld.so.conf.d/custom-python.conf
make && make altinstall
$ pip install httpie
$ echo 'fake partial download' > /tmp/test
$ http --verbose --download --continue --output=/tmp/test https://dl.dropboxusercontent.com/s/prxxcgndysv13t1/httpie.png
GET /s/prxxcgndysv13t1/httpie.png HTTP/1.1
Accept: */*
Host: dl.dropboxusercontent.com
Range: bytes=22-
User-Agent: HTTPie/0.8.0
@jkbrzt
jkbrzt / pyc
Last active June 6, 2023 14:59
Delete Python's compiled *.pyc files like a pro
#!/bin/sh
#
# Delete Python's compiled *.pyc and __pycache__ files like a pro
# https://gist.github.com/jakubroztocil/7892597
#
# Usage:
# Delele *.pyc and __pycache__ files recursively in the current directory:
# $ pyc
#
# The same, but under /path:
@jkbrzt
jkbrzt / opbeat-cli.sh
Last active December 20, 2015 04:29
Opbeat CLI syntax survey
#
# Opbeat is looking for the best CLI syntax for the `opbeat'
# command that sends deployment info to the Opbeat API.
#
# Users should be able to specify repositories that the app being deployed
# consists of and their attributes.
#
# The attributes are "name", "version", "vcs", "rev", "branch", "remote_url".
#
# We are considering these syntaxes:
#!/usr/bin/osascript
# vim: set syntax=applescript
(*
Launch multiple commands in iTerm2 split views
inspired by github.com/xgdlm/iterm2-cssh.
Usage: