Skip to content

Instantly share code, notes, and snippets.

@jhinds
Last active February 10, 2021 02:23
Show Gist options
  • Save jhinds/56e6d33746fb471f14b1093a9b155f01 to your computer and use it in GitHub Desktop.
Save jhinds/56e6d33746fb471f14b1093a9b155f01 to your computer and use it in GitHub Desktop.

Do something when bash process finishes

(while kill -0 $pid; do sleep 1; done) && echo "finished"

pylons ipython

https://stackoverflow.com/questions/7389388/pylons-paster-shell-does-not-run-in-ipython

Check kublet logs

journalctl -u kubelet

Fetch a PR

git fetch opengov pull/[ID]/head:[NEW BRANCH NAME]

Fetch all PRs locally

git config --add remote.origin.fetch +refs/pull/*/merge:refs/remotes/origin/pr/*/merge
git fetch

See ciphers server accepts

sudo sshd -T | grep ciphers

Remove ^M line endings

OpenSSL seeing if cert is good

openssl s_client -showcerts -connect host:port

Setting k8s cluster & namespace

kubectl config set-context test.k8s.peeriq.com
kubectl config set-context $(kubectl config current-context) --namespace=metrics

Get list of ip addresses in a subnet

nmap -sL -n 192.168.1.0/30

Get GCE containers to talk to AWS via VPN

container_subnet=10.92.1.0/24
sudo iptables -t nat -A POSTROUTING ! -d ${container_subnet} -o eth0 -j MASQUERADE

See ssh attempts

tail -100 /var/log/auth.log | grep 'sshd'

Elasticsearch/Java tuning on host.

sudo sysctl -w vm.max_map_count=262144

Update time on ubuntu hosts.

ntpdate ntp.ubuntu.com

Mixpanel activity parshing in google sheets.

=SPLIT(SUBSTITUTE(SUBSTITUTE(D14,"u:",""),"c:",""), ",")

Django list of usernames.

str(','.join(db.userprofile_set.filter(user__is_active=True).values_list('user__username', flat=True))) ",".join(User.objects.values_list('username', flat=True))

AWS, lookup when an instance was stopped.

import boto.ec2
conn = boto.ec2.connect_to_region("eu-west-1")
reservations = conn.get_all_instances()
for r in reservations:
    for i in r.instances:
        if i.state == 'stopped':
            print(f"{i.id} [{i.state}] {i.reason}")

Jinja Templating

from jinja2 import Template
template = Template('Hi I am {{ name }}')
template.render(name='Jonathan')

To get Private Key from pk12 file generate by Barracuda when you download the SSL certificate:

openssl pkcs12 -in WildCard.p12 -nocerts -out WildCard_SSL.pem -nodes

And to get the Certificate:

openssl pkcs12 -in WildCard.p12 -clcerts -nokeys -out WildCard.crt

Import Django Models in Pycharm Console

import sys; 
print('Python %s on %s' % (sys.version, sys.platform))
import django;
print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): 
    django.setup()
import django_manage_shell; 
django_manage_shell.run(PROJECT_ROOT)

from django.apps import apps

for _class in apps.get_models():
    globals()[_class.__name__] = _class

Remove all .pyc files in subdirectories

find . -name "*.pyc" -exec rm -rf {} \;

Make a bookmarklet to change the host

  • Add javascript:window.location.host = "github1s.com"; to the url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment