Skip to content

Instantly share code, notes, and snippets.

@dmy3k
dmy3k / imsim.py
Last active February 1, 2017 10:11
Image similarity detection
'''
Bunch of functions to do basic image similarity detection
See:
http://www.gossamer-threads.com/lists/python/python/901273
http://sourceforge.net/projects/imsim/?source=dlp
'''
from PIL import Image
from PIL import ImageStat
@dmy3k
dmy3k / word_click.js
Last active December 24, 2015 07:09
Get word on click.
// see See http://stackoverflow.com/questions/7563169/detect-which-word-has-been-clicked-on-within-a-text
$(".clickable").click(function(e) {
s = window.getSelection();
var range = s.getRangeAt(0);
var node = s.anchorNode;
while (range.toString().indexOf(' ') != 0) {
range.setStart(node, (range.startOffset - 1));
}
range.setStart(node, range.startOffset + 1);
do {
@dmy3k
dmy3k / opt.skype.skype
Created January 20, 2014 14:15
AppArmour Skype profile [openSuse 13.1, dynamic skype at /opt]
# vim:syntax=apparmor
#
# Copyright (C) 2012 Lekensteyn <lekensteyn@gmail.com>
#include <tunables/global>
/opt/skype/skype {
#include <abstractions/kde>
#include <abstractions/nameservice>
#include <abstractions/video>
#include <abstractions/audio>
@dmy3k
dmy3k / django_logging.py
Created January 23, 2014 10:37
Part of django settings.py as a sample logging setup
import os.path
p = lambda *x: os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', *x))
# Main configuration goes here
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
"""
Execute function in process/thread pool with possibility to get return values
credits to http://stackoverflow.com/a/8533626
"""
from multiprocessing.pool import ThreadPool as Pool
# for process-based pool use
# from multiprocessing import Pool
import time
#!/bin/bash
FILES=$(find $1 -maxdepth 1 -name '*.eps')
for file in $FILES
do
extension="${file##*.}"
filename="${file%.*}"
#echo $file
#echo $filename
@dmy3k
dmy3k / loader.css
Last active August 29, 2015 14:23
Zero element CSS loader
.loading {
position: relative;
}
.loading:before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
function getSelectionCoords(win) {
win = win || window;
var doc = win.document;
var sel = doc.selection, range, rects, rect;
var x = 0, y = 0;
if (sel) {
if (sel.type != "Control") {
range = sel.createRange();
range.collapse(true);
x = range.boundingLeft;
@dmy3k
dmy3k / Howto convert a PFX to a seperate .key & .crt file
Created January 15, 2016 14:50 — forked from TemporaryJam/Howto convert a PFX to a seperate .key & .crt file
How to convert a .pfx SSL certificate to .crt/key (pem) formats. Useful for NGINX
source: http://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/
`openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]`
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.
Now let’s extract the certificate:
`openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]`