Skip to content

Instantly share code, notes, and snippets.

@Tatsh
Tatsh / python-type-stuff.md
Last active July 13, 2020 18:05
Basic typing in Python. Some of this is Mypy-specific.

Mypy

Assertions

Optional values often have to tell the type checker that they are no longer optional. To do this, use assert:

assert x is not None, "x should exist"
@Tatsh
Tatsh / mutable_list_plugin.py
Last active February 3, 2020 05:48
Start of a Pylint plugin to check for lists that have never been mutated, and could therefore be a tuple or other immutable type.
from typing import Dict, List, Optional, Union
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from pylint.lint import PyLinter
import astroid
from astroid.scoped_nodes import FunctionDef
@Tatsh
Tatsh / README.md
Last active January 23, 2020 03:49
Automate transferring of repositories from one user to another.

How to use

  1. Change OLD_USER to the current owner of the repositories to transfer.
  2. Change NEW_USER to the new owner.
  3. Change REPOS to be an iterable of repository names (str) to transfer.
  4. Transfer one repository normally through the web browser, because you need to type your password once (this only lasts for a few hours).
  5. Extract cookies from the browser after signing into GitHub. Save in Netscape format in cookies.txt in the same location as the script. On every line in cookies.txt that starts with 'github.com' change it to '.github.com'.
  6. python gh-transfer.py because the API does not have this feature!

You can extract cookies from Chrome in Netscape format with EditThisCookie.

@Tatsh
Tatsh / fibseq.spl
Created December 7, 2019 10:17
Maybe working fibonacci algorithm in Shakespeare language.
Fibonacci Sequence.
Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
Ghost, another character.
Ophelia, flatterer.
Act I: The one.
Scene I: Zero.
#!/usr/bin/env bash
set -e
SIGNING_IDENTITY='iPhone Distribution: Andrew Udvare (EU5R2QY9HJ)'
mkdir -p ~/dev/retroarch
cd ~/dev/retroarch
if ! [ -d retroarch ]; then
git clone https://github.com/libretro/RetroArch.git retroarch
fi
@Tatsh
Tatsh / ldmacclientuninstall.sh
Created March 29, 2019 20:24 — forked from ferment/ldmacclientuninstall.sh
Remove LANDESK from OSX / macOS
#!/bin/sh
#
function killAllProcs( )
{
sudo /usr/bin/killall $1
/bin/ps ax | /usr/bin/grep $1|/usr/bin/awk '{print $1}'|/usr/bin/xargs sudo kill -9
}
echo "removing LANDesk Client"
@Tatsh
Tatsh / github-no-discover.user.js
Last active March 28, 2019 05:40
Hide the Discover section in >= 1012px view
// ==UserScript==
// @name No Discover
// @homepage https://gist.github.com/Tatsh/d1b5a039d6f511c95a08daade8b07a81
// @namespace https://tat.sh
// @version 0.0.5
// @description Hide the Discover section in >= 1012px view.
// @author Tatsh
// @match https://github.com
// @grant none
// @run-at document-end
@Tatsh
Tatsh / qsort.js
Last active July 14, 2020 17:20
Single-expression qsort() implementations
const sorted = (xs) =>
xs.length < 2
? xs
: sorted(xs.slice(1).filter((x) => x < xs[0])).concat(
[xs[0]],
sorted(xs.slice(1).filter((x) => x > xs[0]))
);
@Tatsh
Tatsh / smallest-in-array-positive.js
Last active July 28, 2018 13:43
Demo test question on Codility.
const sorted = (a) => Array.prototype.sort.call(a, (a, b) => a - b);
const tail = (n, a) => Array.prototype.slice.call(a, n);
const abs = Math.abs;
const solution = (a) => {
const sa = sorted(a);
let last = abs(a[0]);
for (const x of tail(1, sa)) {
const negative = x < 0;
@Tatsh
Tatsh / quassel-format.py
Created June 25, 2018 01:10
Use new Python template syntax to format text in Quassel.
#!/usr/bin/env python
from argparse import Namespace
from string import Template
import sys
Codes = Namespace(
Bold=chr(2),
Color=chr(3),
Normal=chr(15),
Underline=chr(31),