Skip to content

Instantly share code, notes, and snippets.

@Tatsh
Tatsh / sync-debs.sh
Last active April 8, 2020 00:14
Backup deb files of stuff you installed on your iOS device to your system. Just pass the IP address or host name and the place where to store them (that directory will not be created for you). This works best if you use key authentication with SSH (as you always should). Before using this you also need to install sudo, visudo to make sure you ca…
#!/usr/bin/env bash
rsync='rsync --progress --force --delete-before -rltvd'
target="${1:-tatshphone}"
target_local="${2}"
if [ -z "$target_local" ]; then
target_local="/mnt/spare/backup/${target}"
fi
@Tatsh
Tatsh / log-reader.py
Created March 7, 2014 20:30
Read in a typical Apache log and parse into consumable YAML format.
#!/usr/bin/env python
import re
import sys
import yaml
line_prog = re.compile(r"""^(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) # IP Address
[^\]]+ # ? What do the numbers represent in this field(s)?
\[(?P<date>\d{1,2}\/(?:[^\/]+)\/\d{4})\: # Date
(?P<time>(?:\d{2}\:){2}\d{2}\s+[\-\+]\d{1,4})\]\s # Time
@Tatsh
Tatsh / show_dump.c
Created May 10, 2014 03:31
dumps bytes to something readable
#include "show_dump.h"
void show_dump(unsigned char *data, unsigned int len, FILE *stream) {
const static char hex[] = "0123456789abcdef";
static unsigned char buff[67]; /* HEX CHAR\n */
unsigned char chr,
*bytes,
*p,
*limit,
*glimit = data + len;
@Tatsh
Tatsh / argparse-dir-arg.py
Last active November 11, 2023 22:34
Check if a directory argument is writeable or readable.
from os.path import isdir, realpath
import argparse
import os
class ReadableDirectoryAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
prospective_dir = values
if not isdir(prospective_dir):
raise argparse.ArgumentTypeError('%s is not a valid directory' % (
@Tatsh
Tatsh / .gitignore
Last active August 29, 2015 14:01 — forked from octocat/.gitignore
# Compiled
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
*.pyo
__pycache__/
@Tatsh
Tatsh / README.md
Created June 2, 2014 02:16
Apache Bloodhound with virtualenv, PostgreSQL, Supervisor, uWSGI, and nginx

Install virtualenv nginx, Supervisor, PostgreSQL, and uwsgi

I recommend the latest versions for Supervisor and uwsgi. I am using nginx 1.4.7 as that is the latest available on Gentoo (unmasked for ~amd64).

Gentoo

Unmask app-admin/supervisor and www-servers/uwsgi. In the case of x86-64:

app-admin/supervisor ~amd64
@Tatsh
Tatsh / MtCipher-setKeyString.S
Last active July 13, 2020 18:16
Get the key!
; MtCipher::setKeyString(char const*)
; EXPORT __ZN8MtCipher12setKeyStringEPKc
; __ZN8MtCipher12setKeyStringEPKc
PUSH {R4,R7,LR}
MOV R4, R0
MOV R0, R1 ; char *
ADD R7, SP, #4
STR R1, [R4,#4]
BLX _strlen
STR R0, [R4,#8]
@Tatsh
Tatsh / find-excl-use-flags.py
Last active July 13, 2020 18:20
Exceptional USE flags
#!/usr/bin/env python
import re
import sys
from sh import eix
if __name__ == '__main__':
atoms = eix(('-I', '--nocolor', '--only-names')).strip().splitlines()
with open('/etc/portage/make.conf') as fp:
use_flags = []
@Tatsh
Tatsh / mysql_db_utils.py
Created July 30, 2014 21:48
General MySQL database utility functions.
# coding: utf-8
from sh import cat, mysql, mysqladmin, ErrorReturnCode as ShellReturnCodeError
from pipes import quote as shell_quote
import re
def _drop_create_common_args(database_name, action='create', user=None, passwd=None, host='localhost', verbose=False):
args = []
if user:
@Tatsh
Tatsh / a-alert-jquery.js
Last active July 13, 2020 18:22
Acceptable answers for 'Make every link on the page alert with 'Hello' and not navigate'
// Only partially acceptable, raw JS/DOM knowledge is preferred
$('a').on('click', function () {
alert('Hello');
return false; // or take in event argument and use event.preventDefault()
});