Skip to content

Instantly share code, notes, and snippets.

View lhw's full-sized avatar

Lennart Weller lhw

View GitHub Profile
@lhw
lhw / check_password.sql
Last active August 29, 2015 13:56
Convert plain password to prosody scram-sha-1
DELIMITER $$
DROP FUNCTION IF EXISTS check_password;
CREATE FUNCTION check_password(U VARCHAR(255), P VARCHAR(255)) RETURNS BOOLEAN
BEGIN
DECLARE auth SMALLINT DEFAULT 0;
DECLARE return_value SMALLINT;
SELECT COUNT(*) INTO auth FROM users WHERE username = U and password = ENCRYPT(P, password) LIMIT 1;
IF auth > 0 THEN
SELECT SCRAM("HOSTNAME", U, P) INTO return_value;
END IF;
@lhw
lhw / pm.py
Last active August 29, 2015 13:56
logind power management via dbus
#!/usr/bin/python
import dbus
import sys
import gtk
from optparse import OptionParser
LD_PATH="org.freedesktop.login1"
LD_OBJ="/org/freedesktop/login1"
LD_IFACE="org.freedesktop.login1.Manager"
@lhw
lhw / fcgiwrap.diff
Last active September 21, 2015 14:06
Patch for fcgiwrap in debian to allow file owner based execution
commit 58513c0528a991c0ba0be17adb0fb26407a66742
Author: Lennart Weller <lhw@ring0.de>
Date: Thu May 21 13:27:54 2015 +0000
userswitch
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -61,6 +61,9 @@
static const char **allowed_programs;
@echo off
cls
set x86="%SYSTEMROOT%\System32\OneDriveSetup.exe"
set x64="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"
echo Closing OneDrive process.
echo.
taskkill /f /im OneDrive.exe > NUL 2>&1
ping 127.0.0.1 -n 5 > NUL 2>&1
@lhw
lhw / dicecoefficient.go
Last active October 5, 2015 10:48
Dice coefficient for string similarity on natural text
/*
Dice coefficient for string similarity on natural text
Playground: http://play.golang.org/p/JFUjcpBb66
*/
package dicecoefficient
import "strings"
import "unicode"
@lhw
lhw / scummvm_extract.sh
Created June 21, 2012 01:05
GoG.com ScummVM Windows to Linux (debian)
#!/bin/sh
#
## This script extracts the game data and builds a debian archive which can be easily installed
## The following debian/ubuntu packages are required fakeroot, dpkg, imagemagick, innoextract
#
FILE=`zenity --file-selection --file-filter='*.exe'`
INFO=`zenity --forms --text "the scummvm short (e.g. sky) can be found here\n http://www.scummvm.org/compatibility/" --add-entry=scummvm-short`
GAME=`basename $FILE .exe | sed "s;setup_;;g"`
@lhw
lhw / scummvm_extract.sh
Created June 22, 2012 00:30
GoG.com ScummVM Windows to Linux (self-extract)
#!/bin/sh
#
## Extracts inno setup and creates self extracting tar archive
## requires innoextract
#
FILE=`zenity --file-selection --file-filter='*.exe'`
GAME=`basename $FILE .exe | sed "s;setup_;;g" | sed "s;_;-;g"`
WORKSPACE=/tmp/$GAME
@lhw
lhw / WhatsAppDecrypter.java
Created April 27, 2013 19:56
WhatsApp msgstore decrypter
public class Main {
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException {
final SecretKeySpec keySpec = new SecretKeySpec("4j#e*F9+Ms%|g1~5.3rH!we,".getBytes(), "AES");
final Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, keySpec);
FileUtils.writeByteArrayToFile(new File("msgstore.db"), cipher.doFinal(FileUtils.readFileToByteArray(new File("msgstore.db.crypt"))));
}
}
class String
def similarity(other)
b = [self, other].map{|s| 0.upto(s.length-2).map{|i| s[i,2].downcase unless s[i,2].include? " "}.compact}
(2.0 * ((1.0/(b.first.size + b.last.size)) * b.first.inject(0){|r,p1|
b.last.each{|p2| b.last.delete(p2) and r = r+1 and break if p1 == p2}
r
})).round(2)
end
end
@lhw
lhw / Dockerfile
Last active June 24, 2016 12:09
Sinusbot Docker Container. Needs the mentioned files in the COPY instructions. Those files may not be redistributed.
FROM debian:jessie
MAINTAINER Lennart Weller <lhw@ring0.de>
ENV TS3_VERSION 3.0.19.1
ENV SINUS_VERSION 0.9.8
RUN apt-get update && \
apt-get install -y xinit xvfb libxcursor1 ca-certificates bzip2 curl libglib2.0-0 python libav-tools && \
rm -r /var/lib/apt/lists/*