Skip to content

Instantly share code, notes, and snippets.

@tspng
tspng / gitcheats.txt
Created February 4, 2016 14:24 — forked from chrismccoy/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# cherry pick range of commits, starting from the tip of 'master', into 'preview' branch
git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done
# create tracking branches for all remote branches
git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs;
# git reset newly added files

FWIW: I didn't produce the content present here. I've just copy-pasted it from somewhere over the Internet, but I cannot remember exactly the original source. I was also not able to find the author's name, so I cannot give him/her the proper credit.


Effective Engineer - Notes

What's an Effective Engineer?

Gigabyte GA-Z77-DS3H (rev1.0) Hackintosh

My Hackintosh setup for Gigabyte GA-Z77-DS3H rev1.0 motherboard using OS X 10.14 Mojave.

GA-Z77-DS3H onboard devices:

  • Qualcomm Atheros AR8151 Gigabit Ethernet controller
  • Realtek ALC887 audio chipset

Other components:

@tspng
tspng / conftest.py
Created December 17, 2019 14:21
Flask, Flask-Login, pytest example
import pytest
from backend import create_app
from backend.auth.models import User, Role
@pytest.fixture(scope="session")
def monkeypatch_session(request):
"""
Experimental session scoped monkeypatch fixture, see
@tspng
tspng / pre-commit
Last active September 13, 2020 15:59
git hooks & examples
#!/bin/sh
OC_CONFIG="EFI/OC/config.plist"
HIDDEN_VALUE="__GENERATE_YOUR_OWN__"
MODIFIED=0
hide_value() {
key=$1
found=`grep -A1 "<key>${key}</key>" ${OC_CONFIG} | grep ${HIDDEN_VALUE} | wc -l`
if [ $found -eq 0 ]; then
@tspng
tspng / models.py
Last active July 21, 2021 10:53
SQLAlchemy custom query property problem
class _ForUserQuery(BaseQuery):
def _get_client_user_query(self):
raise NotImplementedError
def _get_pk_field(self):
raise NotImplementedError
def for_user(self, user):
query = self._get_client_user_query()
if not user.is_admin:
@tspng
tspng / models.py
Last active July 26, 2021 14:10
SQLAlchemy Many-to-One relationship and cascade example
class Image(db.Model):
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(255))
class ThingWithImage(db.Model):
id = db.Column(db.Integer, primary_key=True)
image_id = db.Column(db.Integer, db.ForeignKey("image.id"))
image = db.relationship("Image", foreign_keys=[image_id])
@tspng
tspng / testcase.py
Created July 27, 2021 10:40
SQLAlchemy Many-to-One delete with backref testcase
import unittest
from sqlalchemy import Column, Integer, ForeignKey, create_engine, event
from sqlalchemy.orm import backref, relationship, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import IntegrityError
from sqlalchemy.engine import Engine
Base = declarative_base()
engine = create_engine('sqlite://')
@tspng
tspng / .gitconfig
Created March 3, 2022 16:03
My .gitconfig
# This is Git's per-user configuration file.
[push]
default = simple
[user]
name = tspng
email = tspng@socket.ch
[core]
excludesfile = /Users/tspng/.gitignore_global
[http]
# allow large deltas to be pushed
@tspng
tspng / iTermColorsToTerminalColors.swift
Created November 26, 2023 09:17
Convert iTerm2 color scheme to Terminal.app color scheme (Swift 5 Compatible)
#!/usr/bin/xcrun swift
//
// Copyright © 2016 Leon Breedt
// Ported to Swift 5 by Pablo Morelli 2019
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0