Skip to content

Instantly share code, notes, and snippets.

View vsajip's full-sized avatar

Vinay Sajip vsajip

View GitHub Profile
@vsajip
vsajip / pr.md
Created December 24, 2021 13:59 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

/* Generated by: JavaCC 21 Parser Generator. JSONParser.java */
package org.parsers.json;
import org.parsers.json.ast.*;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.logging.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
/* Generated by: JavaCC 21 Parser Generator. Do not edit. JSONConstants.java */
package org.parsers.json;
/**
* Token literal values and constants.
*/
public interface JSONConstants {
public enum TokenType {
EOF, WHITESPACE, COLON, COMMA, OPEN_BRACKET, CLOSE_BRACKET, OPEN_BRACE, CLOSE_BRACE, TRUE, FALSE, NULL, STRING_LITERAL, NUMBER, INVALID
}
@vsajip
vsajip / gist:b5d678fe128c566d4827ed04632eceb3
Last active December 1, 2021 19:08 — forked from dusual/gist:9838932
Heroku Bottle app
mkdir heroku
cd heroku/
virtualenv --no-site-packages env
source env/bin/activate
pip install bottle gevent
pip freeze > requirements.txt
cat >app.py <<EOF
try:
import gevent.monkey
@vsajip
vsajip / README.md
Last active February 20, 2025 12:53
Run a logging socket receiver in a production setting with logging from an example webapp

This set of files is to help you set up a socket listener for Python logging in a production environment.

The other files are:

Filename Purpose
prepare.sh A Bash script to prepare the environment for testing.
supervisor.conf The Supervisor configuration file, which has entries for the listener and a multi-process web application.
ensure_app.sh A Bash script to ensure that Supervisor is running with the above configuration.
log_listener.py The socket listener program which receives log events and records them to a file.
@vsajip
vsajip / handles.py
Created September 25, 2021 15:33
Duplicate stdio handles on Windows using ctypes
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Red Dove Consultants Limited. BSD-3-Clause licensed.
#
from ctypes import *
from ctypes.wintypes import BYTE,WORD,DWORD,LPWSTR,LPCWSTR,HANDLE,LPVOID,BOOL
import os
import sys
@vsajip
vsajip / fix_shebang.py
Created August 14, 2021 12:51
A Python script to fix up shebangs in text files and zip archives with/without Windows launchers
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Red Dove Consultants Limited
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
@vsajip
vsajip / test.ftl
Last active June 25, 2021 22:39
Python code generation template and result - how to pass indentation across multiple levels of nested directives?
[#macro BuildCodeSequence expansion indent]
[#var is = ""?right_pad(indent)]
${is}# DBG > BuildCodeSequence ${indent}
[#list expansion.units as subexp]
[@BuildCode subexp indent /]
[/#list]
${is}# DBG < BuildCodeSequence ${indent}
[/#macro]
[#macro BuildExpansionCode expansion indent]
[#var is=""?right_pad(indent)]
@vsajip
vsajip / remove_silence.py
Created April 9, 2021 17:18 — forked from fred9/remove_silence.py
Remove silences
# 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 October 28, 2020 12:42 — forked from eculver/htpasswd.py
htpasswd script in python (no need to install apache utils)
#!/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