Skip to content

Instantly share code, notes, and snippets.

Avatar

Vinay Sajip vsajip

View GitHub Profile
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 / 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.

@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 / typescript-web-components.md
Created Apr 25, 2020 — forked from aelbore/typescript-web-components.md
Step by Step creating web components in typescript using rollup
View typescript-web-components.md

Getting Started

  • Install Dependencies
    npm init
    npm install --save-dev ts-node typescript tslib express @types/express
    

Create your web server

  • Create server.ts in root folder of your app.
@vsajip
vsajip / overlay_pdf.py
Created Apr 11, 2020 — forked from dwayneblew/overlay_pdf.py
Overlay text on a PDF template using fpdf and PyPDF2
View overlay_pdf.py
import fpdf
from PyPDF2 import PdfFileWriter, PdfFileReader
overlay_pdf_file_name = 'overlay_PDF.pdf'
pdf_template_file_name = 'base_PDF_template.pdf'
result_pdf_file_name = 'final_PDF.pdf'
# This section creates a PDF containing the information you want to enter in the fields
# on your base PDF.
@vsajip
vsajip / custom_directive.py
Created Nov 27, 2019 — forked from mastbaum/custom_directive.py
Example of a custom ReST directive in Python docutils
View custom_directive.py
'''Example of a custom ReST directive in Python docutils'''
import docutils.core
from docutils.nodes import TextElement, Inline
from docutils.parsers.rst import Directive, directives
from docutils.writers.html4css1 import Writer, HTMLTranslator
class foo(Inline, TextElement):
'''This node class is a no-op -- just a fun way to define some parameters.
There are lots of base classes to choose from in `docutils.nodes`.
View aiohttp_request_id_logging.py
# 05_aiohttp.py
from aiohttp import web
from aiohttp.web_log import AccessLogger
from asyncio import CancelledError
from contextvars import ContextVar
import asyncio
import logging
import secrets
@vsajip
vsajip / Args.ipynb
Created Feb 28, 2019 — forked from gbishop/Args.ipynb
Allow arguments to be passed to notebooks via URL or command line.
View Args.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vsajip
vsajip / playground_02.rs
Created Oct 18, 2018 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground_02.rs
use std::io::{BufRead};
struct Processor<B: BufRead> {
reader: B
}
// If you uncomment p in ValidatorA, compilation fails because the size of
// ValidatorA can't be determined at compile time. Fair enough.
struct ValidatorA {
// p : Processor<BufRead>