Skip to content

Instantly share code, notes, and snippets.

@tommyip
tommyip / venv.fish
Last active February 23, 2024 20:00
venv.fish - Automatically activate/deactivate virtualenv in fish shell
# Based on https://gist.github.com/bastibe/c0950e463ffdfdfada7adf149ae77c6f
# Changes:
# * Instead of overriding cd, we detect directory change. This allows the script to work
# for other means of cd, such as z.
# * Update syntax to work with new versions of fish.
# * Handle virtualenvs that are not located in the root of a git directory.
function __auto_source_venv --on-variable PWD --description "Activate/Deactivate virtualenv on directory change"
status --is-command-substitution; and return
@britishtea
britishtea / fish_right_prompt.fish
Last active February 17, 2024 22:20
My right prompt for the fish shell.
function fish_right_prompt -d "Write out the right prompt"
set -l exit_code $status
set -l is_git_repository (git rev-parse --is-inside-work-tree 2> /dev/null)
set -l max_shlvl 1; and test "$TERM" = "screen"; and set -l max_shlvl 2
# Print a fork symbol when in a subshell
if test $SHLVL -gt $max_shlvl
set_color yellow
echo -n "⑂ "
set_color normal
@elgalu
elgalu / keybindings.pl
Created January 19, 2014 22:27
Export Ubuntu shortcuts: keybindings.pl -e keys.csv ;; Import (DANGER) Ubuntu shortcuts: keybindings.pl -i keys.csv
#!/usr/bin/perl
use strict;
my $action = '';
my $filename = '-';
for my $arg (@ARGV){
if ($arg eq "-e" or $arg eq "--export"){
$action = 'export';
@koenrh
koenrh / gcp-gpu-vm-hashcat.md
Last active February 4, 2024 18:37
Running Hashcat on Google Cloud's new GPU-based VMs

Running Hashcat on Google Cloud's GPU-based VMs

In February 2017, Google announced the availability GPU-based VMs. I spun up a few of these instances, and ran some benchmarks. Along the way, I wrote down the steps taken to provision these VM instances, and install relevant drivers.

Update April 2019: Updated instructions to use instances with the Tesla T4 GPUs.

@NotTheDr01ds
NotTheDr01ds / fish_load_sudo_alias.fish
Created December 27, 2021 02:46
Fish `sudo` replacement function
function fish_load_sudo_alias
function sudo
if functions -q -- "$argv[1]"
# Create a string which quotes each of the original arguments
# so that they can be safely passed into the new fish
# instance that is called by sudo.
set cmdline (
for arg in $argv
printf "\"%s\" " $arg
end
@shreyansb
shreyansb / flask_profiler.py
Last active January 11, 2024 12:08
A profiler for Flask apps
"""
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the profile or cProfile
module to do the profiling and writes the stats to the stream provided
To use, run `flask_profiler.py` instead of `app.py`
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling
"""
from __future__ import division
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
os.chdir('C:/Users/gennady.nikitin/Dropbox/Coding/OpenCV')
# define variable for resize tratio
ratio = 1
@oisinmulvihill
oisinmulvihill / assert_not_raises.py
Created August 4, 2019 12:58
How to test a python exception is not raised with pytests
# Updated for python3
#
# https://stackoverflow.com/questions/20274987/how-to-use-pytest-to-check-that-error-is-not-raised/35458249#35458249
#
from contextlib import contextmanager
@contextmanager
def not_raises(ExpectedException):
try:
@TySkby
TySkby / timeout.py
Last active March 9, 2023 04:24
Timeout decorator/context manager using signals (for Python 3)
#!/usr/bin/env python3
"""Easily put time restrictions on things
Note: Requires Python 3.x
Usage as a context manager:
```
with timeout(10):
something_that_should_not_exceed_ten_seconds()
```
@EEVblog
EEVblog / Arduino-IR-TX-NEC
Last active January 25, 2023 20:59
A simple Arduino driver for the NEC (Japanese) Infrared IR protocol. Drive an IR LED direct with your own code. This is a direct pin bit-bang approach, so beware about interrupts and timing difference between hardware. Feel free to use hardware PWM to generate the carrier frequency if you want better accuracy.
//*****************************************
// NEC (Japanese) Infrared code sending library for the Arduino
// Send a standard NEC 4 byte protocol direct to an IR LED on the define pin
// Assumes an IR LED connected on I/O pin to ground, or equivalent driver.
// Tested on a Freetronics Eleven Uno compatible
// Written by David L. Jones www.eevblog.com
// Youtube video explaining this code: http://www.youtube.com/watch?v=BUvFGTxZBG8
// License: Creative Commons CC BY
//*****************************************