Skip to content

Instantly share code, notes, and snippets.

Avatar

Vinay Sajip vsajip

View GitHub Profile
@vsajip
vsajip / pyvenvex.py
Last active Apr 13, 2021
A script which demonstrates how to extend Python 3.3's EnvBuilder, by installing setuptools and pip in created venvs. This functionality is not provided as an integral part of Python 3.3 because, while setuptools and pip are very popular, they are third-party packages.The script needs Python 3.3 or later; invoke it using"python pyvenvex.py -h"fo…
View pyvenvex.py
#
# Copyright (C) 2013-2020 Vinay Sajip. New BSD License.
#
import os
import os.path
from subprocess import Popen, PIPE
import sys
from threading import Thread
from urllib.parse import urlparse
from urllib.request import urlretrieve
View remove_silence.py
# From https://stackoverflow.com/questions/29547218/
# remove-silence-at-the-beginning-and-at-the-end-of-wave-files-with-pydub
from pydub import AudioSegment
def detect_leading_silence(sound, silence_threshold=-50.0, chunk_size=10):
'''
sound is a pydub.AudioSegment
silence_threshold in dB
chunk_size in ms
@vsajip
vsajip / ansistrm.py
Created Dec 29, 2010
Python logging: colourising terminal output
View ansistrm.py
#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
import ctypes
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
@vsajip
vsajip / migmail.py
Last active Nov 17, 2020
Python 3.6+ scripts for synchronizing IMAP mailboxes using mbsync and imapsync
View migmail.py
#
# Copyright (C) 2020 Red Dove Consultants Limited
#
# License: GPL v2
#
#
# This script uses imapsync to synchronize IMAP mailboxes. It uses as input a CSV file
# with columns oldhost,olduser,oldpwd,newhost,newuser,newpwd,migrate. The first line
# is expected to be those column names. oldXXX columns refer to the source mailbox
# information and newXXX columns refer to the target mailbox information. The migrate
@vsajip
vsajip / htpasswd.py
Created Oct 28, 2020 — forked from eculver/htpasswd.py
htpasswd script in python (no need to install apache utils)
View htpasswd.py
#!/usr/local/bin/python
"""Replacement for htpasswd"""
# Original author: Eli Carter
import os
import sys
import random
from optparse import OptionParser
# We need a crypt module, but Windows doesn't have one by default. Try to find
@vsajip
vsajip / home-server.md
Created Oct 26, 2020 — forked from nileshtrivedi/home-server.md
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel
View home-server.md

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

View keybase.md

Keybase proof

I hereby claim:

  • I am vsajip on github.
  • I am vsajip (https://keybase.io/vsajip) on keybase.
  • I have a public key ASBsA1X70Mmfu4TObh0UTxcGZhq_ITQjgw2j8m0A6-f1Ewo

To claim this, I am signing this object:

View qhtest.py
import logging
try:
import Queue as queue
except ImportError:
import queue
import threading
class QueueHandler(logging.Handler):
"""
This handler sends events to a queue. Typically, it would be used together
@vsajip
vsajip / InlineInlineMonacoEditor.stories.tsx
Created Aug 17, 2020 — forked from abersnaze/InlineInlineMonacoEditor.stories.tsx
React component, in typescript, wrapping Monaco editor to automatically grow & shrink with content to avoid scroll.
View InlineInlineMonacoEditor.stories.tsx
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import InlineMonacoEditor from './InlineMonacoEditor';
export const LINES = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Aenean aliquet, nulla eget auctor porttitor, lacus urna',
'posuere purus, at suscipit orci sapien quis est. Curabitur',
@vsajip
vsajip / mplog3.py
Created Apr 7, 2012
Example of logging and multiprocessing
View mplog3.py
import logging
import logging.config
import logging.handlers
from multiprocessing import Process, Queue, Event, current_process
import os
import random
import time
class MyHandler(object):
"""