Skip to content

Instantly share code, notes, and snippets.

@tkhn
tkhn / perl-Sphinx-Search.spec
Created April 24, 2013 12:25
SPEC file for perl-Sphinx-Search.spec to build on Fedora 18
%define upstream_name Sphinx-Search
%define upstream_version 0.28
Name: perl-%{upstream_name}
Version: 0.28
Release: 2
Summary: Sphinx search engine API Perl client
License: GPL+ or Artistic
Group: Development/Perl
@tkhn
tkhn / zpasswd.py
Created September 10, 2013 17:56
Simple console htpasswd hash generator
#!/usr/bin/python
"""Replacement for htpasswd"""
# Original author: Eli Carter
# Inspired by https://gist.github.com/eculver/1420227
import crypt
import os
import sys
import random
from optparse import OptionParser
@tkhn
tkhn / sphinx_
Created September 13, 2013 11:12
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use File::Basename;
#---------------------------------------------------------------------
@tkhn
tkhn / sphinx_docs_num.sh
Last active December 22, 2015 23:49
Munin plugin to monitor docs number in bash
#!/bin/sh
case $1 in
config)
cat <<'EOM'
graph_title Sphinx index main stats
graph_vlabel docs count
graph_category sphinx
documents_count.label Documents count in index
graph_args --base 1000 -l 0"
@tkhn
tkhn / nginx-jira.conf
Last active December 23, 2015 06:19
nginx proxy for JIRA
# nginx
server {
listen 80;
listen 443;
ssl_certificate /etc/pki/tls/certs/example.crt;
ssl_certificate_key /etc/pki/tls/private/example.key;
server_name jira.example.com;
@tkhn
tkhn / nginx-pma.conf
Created September 27, 2013 13:41
nginx phpmyadmin conf
server {
listen 80;
server_name pma.example.com;
access_log /var/log/nginx/pma.example.com.access.log;
error_log /var/log/nginx/pma.example.com.error.log;
root /var/www/phpmyadmin/htdocs;
location / {
index index.php;
@tkhn
tkhn / apache-exclude-urls-basic-auth.conf
Created October 9, 2013 10:33
exclude one url from basic auth with apache
SetEnvIfNoCase Request_URI "^/status\.php" noauth
AuthType Basic
AuthName "Identify yourself"
AuthUserFile /path/to/.htpasswd
Require valid-user
Order Deny,Allow
Deny from all
Allow from env=noauth
@tkhn
tkhn / pop3-check.py
Created October 9, 2013 21:47
quick pop3 check
import poplib,getpass
M = poplib.POP3('localhost')
M.user('username')
M.pass_('password')
numMessages = len(M.list()[1])
for i in range(numMessages):
for j in M.retr(i+1)[1]:
@tkhn
tkhn / sort-dict-by-value.py
Created October 21, 2013 18:39
Python: sorting dict by value
>>> d = {'Canada': 513, 'Sao Tome and Principe': 3, 'Fiji': 1, 'Montenegro': 12, 'Lithuania': 47}
>>> sorted_list = sorted(d, key=d.get, reverse=True)
>>> for i in sorted_list:
... print i, d[i]
...
Canada 513
Lithuania 47
Montenegro 12
Sao Tome and Principe 3
Fiji 1
#!/usr/bin/perl -w
# Usage: check_sphinx_search.pl INDEX QUERY MIN-RESULTS
# Example: check_sphinx_search.pl products iphone 15000
use strict;
my $cmd = "search --limit 0 --index ${ARGV[0]} ${ARGV[1]}";
my $min = $ARGV[2];
my $output = `$cmd`;
if($?) {
bark("search command failed");
}