Skip to content

Instantly share code, notes, and snippets.

@yekm
Last active August 29, 2015 14:06

Revisions

  1. Pavel revised this gist Apr 2, 2015. 1 changed file with 12 additions and 5 deletions.
    17 changes: 12 additions & 5 deletions generic.mk
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,31 @@
    TARGET = prog
    TARGET = netup
    LIBS = -lm
    CC = gcc
    CXX = g++
    CFLAGS = -g -Wall
    CXXFLAGS = -g -Wall -std=c++0x -Wextra

    .PHONY: default all clean

    default: $(TARGET)
    all: default

    OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
    OBJECTS += $(patsubst %.cpp, %.o, $(wildcard *.cpp))
    HEADERS = $(wildcard *.h)
    HEADERS += $(wildcard *.hpp)

    %.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@
    $(CC) $(CFLAGS) -c $< -o $@

    %.o: %.cpp $(HEADERS)
    $(CXX) $(CXXFLAGS) -c $< -o $@

    .PRECIOUS: $(TARGET) $(OBJECTS)

    $(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) -Wall $(LIBS) -o $@
    $(CXX) $(OBJECTS) -Wall $(LIBS) -o $@

    clean:
    -rm -f *.o
    -rm -f $(TARGET)
    -rm -f *.o
    -rm -f $(TARGET)
  2. Pavel revised this gist Apr 2, 2015. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions generic.mk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    TARGET = prog
    LIBS = -lm
    CC = gcc
    CFLAGS = -g -Wall

    .PHONY: default all clean

    default: $(TARGET)
    all: default

    OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
    HEADERS = $(wildcard *.h)

    %.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@

    .PRECIOUS: $(TARGET) $(OBJECTS)

    $(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) -Wall $(LIBS) -o $@

    clean:
    -rm -f *.o
    -rm -f $(TARGET)
  3. Pavel revised this gist Mar 30, 2015. 5 changed files with 8 additions and 5 deletions.
    File renamed without changes.
    File renamed without changes.
    5 changes: 0 additions & 5 deletions snip
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    russian wordlist generator from any text
    sed -e 's/[^йцукенгшщзхъфывапролджэячсмитьбюё]/ /gi; s/ \+/ /g; s/ /\n/g; s/.*/\L&/' | TMPDIR=. TMP=. sort -u

    keyboard translation
    perl -C -pe "use utf8; y/йцукенгшщзхъфывапролджэячсмитьбюё/qwertyuiop[]asdfghjkl;'zxcvbnm,.t/"
    8 changes: 8 additions & 0 deletions snip.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # russian wordlist generator from any text
    sed -e 's/[^йцукенгшщзхъфывапролджэячсмитьбюё]/ /gi; s/ \+/ /g; s/ /\n/g; s/.*/\L&/' | TMPDIR=. TMP=. sort -u

    # keyboard translation
    perl -C -pe "use utf8; y/йцукенгшщзхъфывапролджэячсмитьбюё/qwertyuiop[]asdfghjkl;'zxcvbnm,.t/"

    # cap2hccap
    nets=$(wpaclean wpa_clean.cap wpa.cap | grep Net | cut -f 2-3 -d\ ); echo "$nets" | while read mac name; do aircrack-ng wpa_clean.cap -b $mac -J $mac-$name; done
    File renamed without changes.
  4. Pavel revised this gist Mar 25, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions useless md5 play
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash

    LC_ALL=C

    for f in *; do
    s=$(stat -c %s $f)
    if tail -c 27 $f | grep MD5CHANGE_; then
    echo "updating $f $s"
    date '+%F %R' | dd of=$f bs=1 seek=$(( $s - 17 )) &>/dev/null
    else
    echo "modifying $f $s"
    echo "MD5CHANGE_$(date '+%F %R')" | dd of=$f bs=1 seek=$s &>/dev/null
    fi
    done
  5. Pavel revised this gist Dec 12, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions snip
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    russian wordlist generator from any text
    sed -e 's/[^йцукенгшщзхъфывапролджэячсмитьбюё]/ /gi; s/ \+/ /g; s/ /\n/g; s/.*/\L&/' | TMPDIR=. TMP=. sort -u

    keyboard translation
    perl -C -pe "use utf8; y/йцукенгшщзхъфывапролджэячсмитьбюё/qwertyuiop[]asdfghjkl;'zxcvbnm,.t/"
  6. Pavel revised this gist Dec 12, 2014. 1 changed file with 0 additions and 51 deletions.
    51 changes: 0 additions & 51 deletions helper
    Original file line number Diff line number Diff line change
    @@ -1,51 +0,0 @@
    #!/bin/bash -i

    while true; do
    cat <<EOF
    l -- list file names in current directory
    c -- bring up calculator
    f -- sign off this session
    d -- display the time and date
    b -- background job (See Note 1 below)
    s -- interactive shell (See Note 2 below)
    q -- quit
    pick something:
    EOF
    read opt
    case "$opt" in
    l)
    echo "Listing files in current directory:"
    ls -la
    ;;
    c)
    echo "A calculator. Type something like 2+3 and hit enter. Then done hit Ctrl+d:"
    bc
    ;;
    f)
    echo "siging off..."
    sleep 2
    # this would not work since we are not a login shell
    logout
    ;;
    d)
    echo "time and date"
    date
    ;;
    b)
    echo "running some bg job"
    sleep 100 &>/dev/null &
    ;;
    s)
    echo "running interactive shell"
    bash -i
    ;;
    q)
    echo "quitting"
    sleep 2
    exit 0
    ;;
    esac
    echo "waiting before clearing the screen..."
    sleep 3
    clear
    done
  7. Pavel revised this gist Dec 8, 2014. 1 changed file with 51 additions and 0 deletions.
    51 changes: 51 additions & 0 deletions helper
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/bin/bash -i

    while true; do
    cat <<EOF
    l -- list file names in current directory
    c -- bring up calculator
    f -- sign off this session
    d -- display the time and date
    b -- background job (See Note 1 below)
    s -- interactive shell (See Note 2 below)
    q -- quit
    pick something:
    EOF
    read opt
    case "$opt" in
    l)
    echo "Listing files in current directory:"
    ls -la
    ;;
    c)
    echo "A calculator. Type something like 2+3 and hit enter. Then done hit Ctrl+d:"
    bc
    ;;
    f)
    echo "siging off..."
    sleep 2
    # this would not work since we are not a login shell
    logout
    ;;
    d)
    echo "time and date"
    date
    ;;
    b)
    echo "running some bg job"
    sleep 100 &>/dev/null &
    ;;
    s)
    echo "running interactive shell"
    bash -i
    ;;
    q)
    echo "quitting"
    sleep 2
    exit 0
    ;;
    esac
    echo "waiting before clearing the screen..."
    sleep 3
    clear
    done
  8. Pavel revised this gist Nov 9, 2014. 1 changed file with 21 additions and 10 deletions.
    31 changes: 21 additions & 10 deletions find subimage
    Original file line number Diff line number Diff line change
    @@ -11,19 +11,30 @@ template = cv2.imread(sys.argv[2])
    result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
    #cv2.imshow('res', result)

    result = numpy.abs(result)**3
    #val, result = cv2.threshold(result, 0.9, 0, cv2.THRESH_TOZERO)
    val, result = cv2.threshold(result, 0.9, 255, cv2.THRESH_BINARY)
    #cv2.imshow('res2', result)
    #print result.shape

    nimg = numpy.asarray(result)
    ii = numpy.argwhere(nimg == 255)
    if len(ii) > 0:
    print "{} {}".format(ii[0][1]+468, ii[0][0]+318)
    else:
    amax = numpy.amax(nimg)
    argmax = numpy.argmax(nimg)
    x,y = numpy.unravel_index(argmax, nimg.shape)
    #print "amax {}".format(amax)
    #print "argmax {}".format(argmax)
    #print "shape {}".format(nimg.shape)
    #print "x,y {} {}".format(x, y)

    if amax < 0.6:
    exit(-1)

    print "{} {}".format(y+468, x+318)

    #val, result = cv2.threshold(result, amax-0.05, 255, cv2.THRESH_BINARY)
    #cv2.imshow('threshold', result)
    #print result.shape

    #nimg = numpy.asarray(result)
    #ii = numpy.argwhere(nimg == 255)
    #print "{} {}".format(ii[0][1]+468, ii[0][0]+318)
    #else:
    # exit(-1)

    #while cv2.waitKey(33) != ord('q'):
    # True
    #cv2.destroyAllWindows()
  9. Pavel revised this gist Nov 9, 2014. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions find subimage
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    import cv2, sys
    import numpy

    image = cv2.imread(sys.argv[1])
    image = image[318:812,468:1156,:]
    template = cv2.imread(sys.argv[2])
    #template = image[30:40,30:40,:]

    #cv2.imshow('image', image)

    result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
    #cv2.imshow('res', result)

    result = numpy.abs(result)**3
    #val, result = cv2.threshold(result, 0.9, 0, cv2.THRESH_TOZERO)
    val, result = cv2.threshold(result, 0.9, 255, cv2.THRESH_BINARY)
    #cv2.imshow('res2', result)
    #print result.shape

    nimg = numpy.asarray(result)
    ii = numpy.argwhere(nimg == 255)
    if len(ii) > 0:
    print "{} {}".format(ii[0][1]+468, ii[0][0]+318)
    else:
    exit(-1)

    #while cv2.waitKey(33) != ord('q'):
    # True
    #cv2.destroyAllWindows()
  10. Pavel created this gist Sep 19, 2014.
    50 changes: 50 additions & 0 deletions saxo-reddit-bot
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/usr/bin/env python3

    import os, time, datetime, re
    import praw
    import saxo

    subreddit_r = re.compile('[a-z0-9]+')

    @saxo.command()
    def r(arg):
    if not arg:
    return "Fetch links from reddit"
    if not saxo.env("base"):
    return "Sorry, this command requires an IRC instance"
    if not subreddit_r.match(arg):
    return "Sorry, subreddit name must match " + subreddit_r.pattern

    sname = arg

    path = os.path.join(saxo.env("base"), "database.sqlite3")
    with saxo.database(path) as db:
    c = db.connection.cursor()
    if not "reddit_stat" in db:
    db['reddit_stat'].create(("name", "text unique"), ("value", str))

    tname = "reddit_%s" % sname
    if not tname in db:
    db[tname].create(('url', 'text unique'), ('req_by', str))

    url = c.execute("select url from %s where req_by = ''" % tname).fetchone()
    if url == None:
    rtime = c.execute("select value from reddit_stat where name = ?", [tname]).fetchone()
    if rtime != None and rtime[0] == str(datetime.date.today()):
    return "No more %s for today" % sname
    reddit = praw.Reddit(user_agent='irc_pic_bot')
    s = reddit.get_subreddit(sname).get_hot(limit=32)
    for x in s:
    if x.url.endswith(('.jpg', '.jpeg', '.gif', '.png')):
    c.execute("replace into %s values(?, '')" % tname, [x.url])
    db.commit()
    c.execute("replace into reddit_stat values (?, ?)", [tname, str(datetime.date.today())])
    db.commit()
    url = c.execute("select url from %s where req_by = ''" % tname).fetchone()

    if url == None:
    return "No more urls. Maybe reddit is down."

    c.execute("replace into %s values (?, ?)" % tname, [url[0], saxo.env("nick")])
    db.commit()
    return url[0]