Skip to content

Instantly share code, notes, and snippets.

View cgthayer's full-sized avatar
💡
coding

Charles Thayer cgthayer

💡
coding
View GitHub Profile
@cgthayer
cgthayer / tmux.cheat
Last active October 20, 2015 16:04 — forked from afair/tmux.cheat
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &
@cgthayer
cgthayer / djikstra.py
Created March 15, 2017 06:06
Djikstra in python for source to all others and source to single destination
import copy
Infinity = 1e6
class GraphU:
"""Undirected graph, with edge cost and nodes have string names.
Okay to use int or float cost, but must be positive.
Assumes only one edge between any node n1 and n2.
"""
def __init__(self, edges=()):
@cgthayer
cgthayer / docker-n00b.md
Last active February 7, 2024 14:38
Docker Notes for n00bs

Basics

Images are read-only templates, but you can diff and push them to save many versions. Containers are instances of images, that are also directories and usually a single running process.

Images can be layered, you start from a base and make changes. Containers are versioned so that you can make changes and save the filesystem state as a new Image.

#!/usr/bin/env python
import hashlib
import sys
bsz = 8192
for f in sys.argv[1:]:
sha1sum = hashlib.sha1()
with open(f, 'rb') as source:
while True:
block = source.read(bsz)
@cgthayer
cgthayer / gist:25aa97bb4b74efb75e3467fb7bbdaacb
Last active May 27, 2019 18:04
Django: check what would be deleted when I delete an object, using a transaction
>>> from django.db import transaction
>>> transaction.set_autocommit(autocommit=False)
>>> o = Organization_v2.objects.get(name='pdemo')
>>> del_info = o.delete()
>>> del_info
(1404, {'data.Property': 408, [..more stuff..], 'data.Organization_v2': 1})
>>> Property.objects.filter(scope__organization_id=o).count()
0
>>> transaction.rollback()
>>> o = Organization_v2.objects.get(name='pdemo')

Django DRF Cheat Sheet

Django Rest Framework

Overview:

    http request --> url_route --> view --> serializer --> data-dict response
s = """Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
@cgthayer
cgthayer / gist:a43786a447527e0c8b9afb5cd69c91d2
Last active February 24, 2020 02:04
deploy-django-code-1
$ pip install django
$ django-admin startproject myproj
$ cd myproj
$ django-admin startapp myapp
$ export DJANGO_SETTINGS_MODULE=myproj.settings
$ django-admin runserver
Performing system checks…
System check identified no issues (0 silenced).
February 11, 2020–05:12:45
Django version 1.11.9, using settings 'myproj.settings'
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
@cgthayer
cgthayer / latency.txt
Created April 25, 2020 01:33 — 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