Skip to content

Instantly share code, notes, and snippets.

@biiont
biiont / gist:7928f1490b20051a5008c3b85bc65123
Created September 5, 2016 13:12
ISO TO_DATE TO_TIMESTAMP format
select to_timestamp('1970-01-01T00:00:00.000Z', 'YYYY-MM-DD"T"HH24:MI:SS.FFF"Z"') as ts from dual;
@biiont
biiont / reboot-test.sh
Created February 25, 2016 14:44
Continiosly reboot target system by ssh until ssh returns connection error then beep.
CNT=1; ERR=0; while test $ERR -eq 0; do printf "Attempt: %3d at %s\n" $CNT "$(date)"; ssh -o 'VisualHostKey=no' root@192.168.21.72 /sbin/reboot; ERR=$?; test $ERR -eq 0 && sleep $((2 * 60)); CNT=$CNT+1; done; test $ERR -ne 0 && printf "Failed with code %d at %s" $ERR "$(date)" && paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga
#!/bin/bash
# Since we're dealing with dd, abort if any errors occur
set -e
SOURCE_FILE=${1:-/dev/zero}
TEST_FILE=${2:-dd_obs_testfile}
[ -e "$TEST_FILE" ]; TEST_FILE_EXISTS=$?
TEST_FILE_SIZE=${3:-$((128*1024*1024))} # 128Mb
@biiont
biiont / profile
Created January 26, 2016 10:34
Universal way to find out scripts BASEDIR. Can be used as base for sourcable 'profile' to alter current environment for particular use (e.g. cross-compiler environment).
if [ "${0#/*profile*}" != "${0}" ]
then
BASEDIR=$(dirname "$(readlink -f "$0")")
else
if [ $# -gt 0 -a "${1#/*profile*}" != "${1}" ]
then
BASEDIR=$(dirname "$(readlink -f "$1")")
else
echo 'NOTE: When sourcing this profile on some shells (e.g. Busybox) you need to profile file name twice.'
echo 'Usage: . path/to/profile path/to/profile'
@biiont
biiont / yacy_alternative_search.js
Created January 17, 2016 12:18
Add search links to alternative engines. To be able to continue to search other search engines if Yacy does not give you the answer.
// Go to "Administration > Portal Configuration"
// Replace donation box at "'About' Column" with:
<div style="padding:8px;"><a id="googlesearchlink" href="https://google.com/">Google</a></div>
<div style="padding:8px;"><a id="yandexsearchlink" href="https://yandex.ru/">Yandex</a></div>
<div style="padding:8px;"><a id="wikisearchlink" href="https://wikipedia.org/">Wikipedia</a></div>
<script>
function updateSearchLink(elid, hrefPref, captionPref, srch) {
var searchlink = document.getElementById(elid);
@biiont
biiont / multipdf.sh
Created November 10, 2015 19:55
Create multipage scanned pdf files
#!/bin/sh
OUT="result" convert source1.tiff source1.tiff ... -depth 75 -units pixelsperinch -compress zip $OUT.pdf && pdf2ps $OUT.pdf && ps2pdf $OUT.ps && rm -f $OUT.ps
@biiont
biiont / xelatex-word-replace.tex
Last active October 22, 2015 13:23
This gist allows to programmatically search and replace in latex taking in consideration word form.
\documentclass{article}
\usepackage{xltxtra}
\usepackage{xecyr}
\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\newfontfamily\cyrillicfont{DejaVu Serif}
@biiont
biiont / mass_rename.sh
Last active October 6, 2015 11:53
Mass files rename in shell
#!/bin/false
## First: select file set.
/bin/ls -1 prefix_to_remove_*
## Second: test transformation.
/bin/ls -1 prefix_to_remove_* | sed 's/^prefix_to_remove_\(.*\)$/\1/'
## Third: execute
## NOTE: Added 'mv \0 ' to the sed command and '| sh' to the pipe.
@biiont
biiont / gist:6744b1bae9c7bb1cd6ca
Created October 1, 2015 10:08
Fix dhcp name change
#!/bi/sh
# Fix dhcp name change. Works for Debian on 2015-07-11.
sudo echo "supersede host-name gethostname();" >> /etc/dhcp/dhclient.conf
@biiont
biiont / ssh-sync-date.sh
Created October 1, 2015 10:08
Sync local time to remote host over ssh
#!/bin/sh
# Sync local date to remote host over ssh
ssh remote.host.net sudo date $(date "+%m%d%H%M%Y.%S")