Skip to content

Instantly share code, notes, and snippets.

@mdavey
mdavey / count_svn_blame.php
Last active December 26, 2015 09:39
PHP code to count who was last to commit each line of code (uses svn blame)
<?php
function is_library($filename)
{
static $libraryNames = array(
'/Zend/',
'/html2ps',
'/simpletest/',
'/phpMailer/',
'/dompdf',
"""
Finds all Snom brand phones in a /24 and tells them to key in 6405 turn on the hands free speaker.
(6405 is an extension that plays the stock monkies sound from Asterisk)
"""
import urllib2
import socket
import sys
def enumerate_snom_ips(base):
@mdavey
mdavey / globalhotkeys.py
Created June 5, 2014 09:51
Global hot keys in Python for Win32
import ctypes
import ctypes.wintypes
import win32con
class GlobalHotKeys(object):
"""
Register a key using the register() method, or using the @register decorator
Use listen() to start the message pump
@mdavey
mdavey / clpak.py
Created June 18, 2014 02:03
Crimsonland (Steam) Pak Format
import os
import struct
"""
Crimsonland (Steam) pak file format
Header format:
50 40 4B 00 56 31 31 00 ("PAK" NUL "V11" NUL)
@mdavey
mdavey / extensions.conf
Last active December 9, 2020 20:20
Simple hangup detection (Asterisk)
; Detect which party hungup an Asterisk call
; If we (the caller) hangup after Dial() we jump directly to h
; Because of the 'g' option if the other party hangs up we continue on
exten => s,1,Set(whoHungUp=CALLER)
exten => s,n,Dial(IAX2/provider/${number},,g)
exten => s,n,Set(whoHungUp=OTHERPARTY)
exten => s,n,Hangup
exten => h,1,NoOp(whoHungUp ${whoHungUp})
@mdavey
mdavey / crimsonland_pak.lua
Created November 29, 2014 11:15
Crimsonland Pak Format
BinaryFile = {}
BinaryFile.new = function(file)
return setmetatable({file=file}, {__index=BinaryFile})
end
BinaryFile.readint32 = function(self)
local data = self.file:read(4)
return (data:byte(4) * (256^3)) +
(data:byte(3) * (256^2)) +
@mdavey
mdavey / dump-text.lua
Created April 28, 2015 06:52
Dump printable strings of a hex dump (in ASCII)
local function readsection(f)
local colon = f:read(1)
if colon == nil then return nil end
if colon ~= ':' then error('section did not start with colon') end
local data = ''
while true do
local char = f:read(1)
if(char:byte() == 13) then
f:read(1) -- eat cr
return data
local function setoptions(f)
local options = {}
local currentname = nil
local env = setmetatable({},
{
__index = function(self, method)
if method == 'set' then
return function(name)
if currentname ~= nil then
error('need to call "to" first')
@mdavey
mdavey / keyboard_svg_layout.lua
Created June 16, 2015 06:08
Code to generate SVG layout for a KBT Pure Pro Keyboard
--noescape--
local tag = doku.xml_tag
local unit = 19*2 -- Unit size, mapped straight to pixels
local space = 4 -- Spacing between keys (as pixels again)
local halfspace = space/2
local doublespace = space*2
@echo off
call :inputbox "Video ID" "Download Youtube video as MP3"
youtube-dl.exe -x --audio-format mp3 https://www.youtube.com/watch?v=%input%
exit /b
:InputBox
set input=
set heading=%~2
set message=%~1
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"