Skip to content

Instantly share code, notes, and snippets.

View Bobsans's full-sized avatar
👽
Write code

Bobsans Bobsans

👽
Write code
  • Dim-Tim, Inc.
  • Belarus
View GitHub Profile
@Bobsans
Bobsans / change-commit-author-in-git-history.sh
Created February 7, 2022 13:34
Change commit author in git history
git filter-branch -f --env-filter '
if test \"$GIT_AUTHOR_NAME\" = \"User\"; then export GIT_AUTHOR_NAME=\"New User\" GIT_AUTHOR_EMAIL=\"user@mail.com\"; fi
' -- --all
git push --force
@Bobsans
Bobsans / python_code_tests.py
Last active March 29, 2022 13:35
Testing different python code performance
# Windows 10, x64
# Python 3.8.5
def sep(a=None, b=None):
return {**({'a': a} if a else {}), **({'b': b} if b else {})}
def comp(a=None, b=None):
return {k: v for k, v in {'a': a, 'b': b}.items() if v}
def simp(a=None, b=None):
@Bobsans
Bobsans / coordintas-encode.js
Created July 23, 2020 21:55
Maps polygon coordinates encoder/decoder
export default class CoordinatesEncoder {
static SCALE = 1000000;
static encode(polygons) {
const result = [];
const intToCodes = (number) => {
const result = [];
for (let i = 0; i < 4; i++) {
result[i] = 255 & (number >> 8 * i); // eslint-disable-line no-bitwise
@Bobsans
Bobsans / postgresql-upgrade.md
Last active April 29, 2020 09:20
Migration to new version of PostgreSQL on Windows

Run it in new postgres bin folder

pg_upgrade.exe 
  -b D:\database\PostgreSQL-9.5-x64\bin     -- old postgres bin folder without end slash
  -B D:\database\PostgreSQL-10.7-x64\bin    -- new postgres bin folder without end slash
  -d D:\cluster\PostgreSQL-9.5-x64          -- old postgres cluster data folder without end slash
  -D D:\cluster\PostgreSQL-10.7-x64         -- new postgres cluster data folder without end slash
  -U postgres
@Bobsans
Bobsans / sgv_path_translate.py
Created April 1, 2018 14:02
Translate svg path
def translate(path, mx, my):
out = []
parts = path.split(' ')
for part in parts:
if ',' in part:
nums = part.split(',')
prex = nums[0][0] if nums[0][0] in ('M', 'C', 'L') else ''
numx = float(nums[0][1:]) if nums[0][0] in ('M', 'C', 'L') else float(nums[0])
prey = nums[1][0] if nums[1][0] in ('M', 'C', 'L') else ''
numy = float(nums[1][1:]) if nums[1][0] in ('M', 'C', 'L') else float(nums[1])
@Bobsans
Bobsans / create-self-signed-wildcard-certificate.md
Last active September 9, 2020 16:59 — forked from bitoiu/self-signed-wildcard-cert-for-ghes.md
Self-Signed Wildcard certificate with SAN using openssl

Copy the default template of openssl.cnf to a writable location.

cp /etc/ssl/openssl.cnf src

Uncomment the req_extensions = v3_req

req_extensions = v3_req # The extensions to add to a certificate request

Add subjectAltName to v3_req section

@Bobsans
Bobsans / app_links.py
Created October 24, 2017 09:13
Get dict of links from django urls.
@Bobsans
Bobsans / models.py
Created January 24, 2017 10:23
Django ImagedModel. Delete all linked images after model instance delete.
class ImagedModel(models.Model):
class Meta:
abstract = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
pre_delete.connect(self.pre_delete, self.__class__, dispatch_uid='%s_pre_delete' % str(self.__class__).lower())
def save(self, *args, **kwargs):
try: