Skip to content

Instantly share code, notes, and snippets.

View artyom's full-sized avatar

Artyom Pervukhin artyom

View GitHub Profile
@artyom
artyom / print_feed_ulrs.sh
Created April 3, 2011 11:37
Print RSS feed urls from Mac OS X Mail.app
#!/bin/sh
find ~/Library/Mail/RSS/ -name "Info.plist" -print0 | xargs -0 -I{} sh -c 'F="{}" ; defaults read "${F%.plist}" RSSFeedURLString'
@artyom
artyom / Makefile
Created January 14, 2012 12:32
make site from markdown files (using "Discount" markdown implementation)
MAKEFLAGS := -j
MDFILES := $(shell find . -name '*.md' -type f)
HTMLS := $(patsubst %.md,%.html,$(MDFILES))
TEMPLATE := template.tpl
.PHONY: all clean
all: $(HTMLS)
%.html: %.md $(TEMPLATE)
theme -E -t $(TEMPLATE) -o $@ $<
@artyom
artyom / gist:1717729
Created February 1, 2012 16:05
subsequent rows values difference
sqlite> select * from t1;
i n
a 1
b 2
c 3
d 4
e 5
foo 15
bar 37
baz 115
@artyom
artyom / deployer
Created February 14, 2012 18:52
deployer prototype (tired of cfengine :))
#!/usr/bin/make -rf
SELF := $(shell hostname -s)
.NOTPARALLEL:
.ONESHELL:
SHELL := /bin/sh
.SHELLFLAGS := -e
.PHONY: UPDATE_SOURCES ALL $(PACKAGES)
MAKEFLAGS = -j -s
HOSTGROUP1 = host1 host2 host3 host4
HOSTGROUP2 = host10 host11 host12
default:
echo available targets: all, hostgroup1, hostgroup2
all: $(HOSTGROUP1) $(HOSTGROUP2)
@artyom
artyom / strip-ips.sh
Created June 1, 2012 12:36
filter out ipv4 ips from stdin/file(s)
#!/bin/sh -e
cat $@ | tr -cs '0-9\.' '\n' | awk -F'.' 'NF==4 && $1 > 0 && $1<=255 && $2<=255 && $3<=255 && $4<=255 && !/\.\./'
@artyom
artyom / gist:3368367
Created August 16, 2012 08:24
Persistent SSH_AUTH_SOCK for using with screen/tmux
# put this to your $HOME/.bashrc
# so you can safely use screen or tmux while preserving ssh-agent forwarding features
# of your ssh sessions
test "${SSH_AUTH_SOCK:-}" && test $SSH_AUTH_SOCK != $HOME/.ssh_auth_sock && {
test -L $HOME/.ssh_auth_sock && \
test "$(readlink $HOME/.ssh_auth_sock)" = $SSH_AUTH_SOCK || \
ln -sf $SSH_AUTH_SOCK $HOME/.ssh_auth_sock
export SSH_AUTH_SOCK=$HOME/.ssh_auth_sock
}
@artyom
artyom / lockme.py
Created September 11, 2012 20:46
freebsd/linux pidfile+lockfile
#!/usr/bin/env python
import os, fcntl, time
def locked(func):
def wrapper(*args, **kwargs):
with open('LOCKFILE','a+') as lf:
try:
fcntl.flock(lf.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
@artyom
artyom / lockme.py
Created September 12, 2012 09:33
*bsd/linux lockfile+pidfile as contextmanager
#!/usr/bin/env python
import os, fcntl, time
from contextlib import contextmanager
@contextmanager
def lockfile(filename):
with open(filename,'a+') as lf:
try:
fcntl.flock(lf.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
@artyom
artyom / newerthan.sh
Created September 12, 2012 14:19
Check if file is newer than X minutes
#!/bin/sh -eu
usage () { printf "%s file [time-in-minutes]\n" ${0##*/} >&2 ; }
test $# -eq 0 && { usage ; exit 2 ; }
WHAT=$1
test -e $WHAT || { echo "$WHAT not found" >&2 ; exit 2 ; }
MINUTES=${2:-30}
case ${0##*/} in
older*)
test $(($(date +%s)-$(stat --printf "%Y\n" "$WHAT"))) -gt $(($MINUTES*60))