Skip to content

Instantly share code, notes, and snippets.

View tsertkov's full-sized avatar
🖐️
Say Hello

Aleks Tsertkov tsertkov

🖐️
Say Hello
View GitHub Profile
@tsertkov
tsertkov / shell-exif-rename-images.sh
Created September 9, 2013 15:42
One liner to rename image files in current folder using exif data. Requires "identify" tool from imagemagick to read exif.
for f in *; do; t=`identify -format '%[exif:DateTime]' "$f" 2>/dev/null | sed -e 's/[: ]//g' -e 's/^\(.\{12\}\)\(.*\)/\1.\2/'`; echo -n "$t $f\t\t"; touch -t $t "$f" 2>/dev/null && echo "done" || echo "fail"; done
@tsertkov
tsertkov / modrewrite-htaccess
Created September 9, 2013 16:05
Print mod_rewrite server variables using special mod_rewrite rules exporting internal variables via environment variables and PHP script printing there vars.
RewriteEngine On
# special mod_rewrite variables
RewriteRule .* - [E=MR_SPECIALS_API_VERSION:%{API_VERSION},NE]
RewriteRule .* - [E=MR_SPECIALS_THE_REQUEST:%{THE_REQUEST},NE]
RewriteRule .* - [E=MR_SPECIALS_REQUEST_URI:%{REQUEST_URI},NE]
RewriteRule .* - [E=MR_SPECIALS_REQUEST_FILENAME:%{REQUEST_FILENAME},NE]
RewriteRule .* - [E=MR_SPECIALS_IS_SUBREQ:%{IS_SUBREQ},NE]
RewriteRule .* - [E=MR_SPECIALS_HTTPS:%{HTTPS},NE]
@tsertkov
tsertkov / mysqldump-wrapper.sh
Created September 9, 2013 16:12
A simple bash script for dumping MySQL table data and structure separately. This one is ancient, comes from 2008 :-)
#!/bin/bash
PATH=/bin:/usr/bin
HOSTNAME=localhost
USERNAME=username
PASSWORD=password
DATABASE=database
# list of tables to be ignored in "data" mode
DATA_IGNORE=( table1 table2 table2 )
@tsertkov
tsertkov / redirect-js.html
Created September 9, 2013 16:46
Client side redirect service intended to hide referrer for external urls. http://example.com/?r=http://google.com
<script>window.location = window.location.href.replace(/^.*\?r=/, "");</script>
@tsertkov
tsertkov / _reverse-apache.conf
Last active December 23, 2015 02:09
Reverse proxy apache setup (mod_poxy, mod_rewrite)
#
# Reverse proxy (mod_proxy, mod_rewrite)
#
# http[s]://<hostX>[<.subdomain>...].example.com
# \_
# | http://<subdomain[.subdomain]...>.example.com:<portX>
#
# Mark requests with http header to distinguish forwarded requests on
# backends and apply special rules
@tsertkov
tsertkov / _rewrite-vhosts-apache.conf
Created September 14, 2013 20:11
Virtual host apache setup with mod_rewrite
#
# Virtual hosts by mod_rewrite
#
RewriteEngine On
RewriteMap lowercase int:tolower
# Domain to path mapping overriding default rule below
#
# File format:
@tsertkov
tsertkov / rename-exif.sh
Created October 2, 2013 10:52
Exiftool command for renaming images to datetime name
# exiftool command for renaming images to datetime name
exiftool -d %y%m%d-%H%M%S%%-c.%%e "-filename<datetimeoriginal" "$@"
# change file modtime as well (this one does not work sometimes for some reason)
# exiftool -d %y%m%d-%H%M%S%%-c.%%e "-filename<datetimeoriginal" -execute "-filemodifydate<datetimeoriginal" "$@"
@tsertkov
tsertkov / osx-luminance.sh
Last active December 27, 2015 01:49
Get terminal background color luminance
#!/usr/bin/env zsh
# Get terminal background color luminance as integer 0..100
# 0 - white, 100 - black
if [ $TERM_PROGRAM = 'Apple_Terminal' ]; then
colors_string=$(osascript -e 'tell application "Terminal" to get background color of current settings of selected tab of front window')
elif [ $TERM_PROGRAM = 'iTerm.app' ]; then
colors_string=$(osascript -e 'tell application "iTerm.app" to get background color of current session of current terminal')
else
echo "Error: Could not get terminal background color"
@tsertkov
tsertkov / gentoo_chroot.sh
Created November 11, 2013 11:34
Chroot into Gentoo partition and setup environment
# Chroot into Gentoo partition
mount /dev/sdc4 /mnt/gentoo
mount -t proc none /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
grep -v rootfs /proc/mounts > /etc/mtab
source /etc/profile
export PS1="(chroot) $PS1"
@tsertkov
tsertkov / switch_variables_values.js
Created May 14, 2014 08:01
Switch values of two variables without creating intermediate buffer variable
var a = 1, b = 2;
a = [b, b = a][0];