Skip to content

Instantly share code, notes, and snippets.

@PeterMinin
PeterMinin / calc.py
Last active July 6, 2023 19:30
A command-line calculator with some handy and/or neat features.
#!/usr/bin/python
"""
A command line calculator with the following features:
1) Accepts numbers with any decimal and thousand separators.
2) Uses Decimal when possible, which favors "user-friendliness" of results
over speed of computation.
"""
from __future__ import division, print_function
@PeterMinin
PeterMinin / fps.py
Created May 15, 2016 18:15
Python utils
from time import time
class FpsCounter(object):
def __init__(self, period=1, period_in_seconds=True):
self.frame_counter = None
self.interval_start = None
self.period = period
self.period_in_seconds = period_in_seconds
self.total_seconds = 0
self.average = 0
# Set prefix to Ctrl+A
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Enable mouse interaction (for tmux version >= 2.1):
# select and resize panes, copy text and change window using the status line
set-option -g mouse on
# Scroll History
alias git-tree="git log --graph --full-history --all --color --pretty=format:\"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s\""
alias beep="echo -ne '\007'"
alias apt-install="sudo apt install $@"
@PeterMinin
PeterMinin / load-matlab-hdf5.py
Last active May 17, 2017 13:05
A function for reading .mat files from MATLAB v7.3+ in Python. Doesn't support all MATLAB types yet.
import h5py
import numpy as np
def convert_item(item, file):
cls = item.attrs['MATLAB_class'].decode('utf-8')
if cls == 'char':
return ''.join(map(chr, item))
elif cls == 'uint8':
return np.array(item, dtype=np.uint8)
@PeterMinin
PeterMinin / ipyparallel_push_functions.py
Last active June 14, 2017 11:28
For synchronizing ipyparallel engines with the controller client.
import ipyparallel as ipp
import types
ipp_client = ipp.Client()
ipp_direct = ipp_client[:]
def push_functions():
functions = {name: val
for name, val in globals().items()
if type(val) == types.FunctionType and val.__module__ == '__main__'}
; Ctrl+Win+Down - minimize active window
^#Down:: WinMinimize, A
; Ctrl+Win+Space - toggle Always On Top for the active window
^#Space:: Winset, Alwaysontop, , A
; Left "Shift" extender
SC056:: LShift
; Alt+Ctrl+M - Context Menu
#!/usr/bin/env python3
"""
This is an installation/uninstallation utility for integrating
unpackaged software, i.e. that distributed as an archive rather than
a deb-package or an installation script, into the user's ~/.local/
directory structure, provided that the application still follows
the standard directory structure (with "bin", "share", etc.).
Installation is performed in the form of symbolic links, i.e.
@PeterMinin
PeterMinin / phab_batch_assign_identities.py
Last active December 4, 2019 11:27
Batch-assigning repository identities in Phabricator
#! /usr/bin/env python3
"""
Motivation:
I made a mirror of a third-party repository in Phabricator to keep track
of changes in specific files using Owners. I'm still trying this workflow,
and I still have some issues with it that might need patching Phabricator
to solve, so I'm not sure I recommend doing this.
Anyway, importing the repository to Diffusion created a few hundred
@PeterMinin
PeterMinin / fix-eclipse-popup-size.py
Created January 28, 2020 18:00
A kludge for a bug in old Eclipse versions where the Parameter Hints popup keeps getting smaller and closes if you try to resize it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=466114
#! /usr/bin/env python3
import os
import re
workspace_path = os.environ['HOME'] + '/nsight-workspace'
plugin_name = 'org.eclipse.cdt.ui'
target_width = 800
target_height = 500