Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
"""Usage:
X.py < X.in > X.out
"""
################################################################################
# util functions
logging = False
@greenkey
greenkey / elementary_setup.sh
Last active August 29, 2015 14:09
This script is a useful setup after a fresh installation of elementaryos (see http://elementaryos.org/)
#!/bin/bash
open_browser () {
URL=$1
[[ -x $BROWSER ]] && exec "$BROWSER" "$URL"
path=$(which xdg-open || which gnome-open) && exec "$path" "$URL"
echo "Can't find browser"
}
@greenkey
greenkey / backup.bash
Created January 30, 2015 19:30
poor man's backup script
#!/bin/bash
while IFS=, read -r from to
do
echo copying from $from to $to
cp -vufr "$from" "$to" 2>> ~/cperrors.txt
done <<EOF
/home/myuser/important_files/,/media/myuser/externalHD/backup/important_files
/home/myuser/another_dir/,/media/myuser/externalHD/backup/another_dir
EOF
@greenkey
greenkey / renameImage.sh
Created February 14, 2015 17:32
rename images based on EXIF data, move it in proper directory
#!/bin/bash
# usage:
# $0 path/to/image/or/dir path/to/destination/dir
#
# the file will be renamed using EXIF data:
# YYYYMMDD-image_name
#
# if the second parameter is specified, a directory structure will be created:
# path/to/destination/dir/YYYY/YYYY-MM/image_new_name
@greenkey
greenkey / export_schema.sql
Last active August 29, 2015 14:18
Export Oracle Schema
set long 10000000
set head off
set echo off
set pagesize 0
set verify off
set feedback off
SET LINESIZE 32000
COL ddl FORMAT A32000
spool schema.sql
@greenkey
greenkey / Oracle_String_To_Array_and_Query.sql
Last active August 29, 2015 14:18
The problem: you have a comma separated string that you have to use for a query.
DECLARE
a dbms_utility.uncl_array;
len PLS_INTEGER;
input_string STRING(999) := '0099905666,0099905667,0099905668,0099905669';
my_code STRING(99);
BEGIN
-- add a letter to make it works
input_string := 'x' || Replace(input_string,',',',x');
-- convert the string in an array
dbms_utility.Comma_to_table(input_string, len, a);
@greenkey
greenkey / waitUntilSQL.vbs
Created April 29, 2015 16:10
vbscript: Execute an SQL query until the result is as expected
' executes the query to the DB while the results is not as expected
' the query MUST return at least one record with a field named CHECK_VAL
' the loop will stop when CHECK_VAL = check_val (Function parameter)
' or when the timeout is reached (milliseconds)
' the return value will be True (check ok) or False (timeout reached)
' waitBetweenQueries is the milliseconds to wait between the query execution
Function waitUntilSQL(connection, sql, check_val, timeout, waitBetweenQueries)
Dim response, startTime
' default values
If IsEmpty(timeout) Then timeout = 60000
@greenkey
greenkey / proxied_chrome.sh
Created December 22, 2015 18:54
Use this as a launcher to have a chromium that uses a quick socks proxy via SSH
#!/bin/bash
PROXY_IP=192.168.1.100
PROXY_PORT=4444
ssh -N -D $PROXY_PORT $PROXY_IP &
ID=$!
chromium-browser --proxy-server="socks://127.0.0.1:$PROXY_PORT"
kill $ID
@greenkey
greenkey / sql_parametric.vbs
Last active February 25, 2016 12:43
VBScript, ADO and query parameters (question marks), a handy function
' inspired by:
' http://stackoverflow.com/questions/2557606/how-do-i-associate-parameters-to-command-objects-in-ado-with-vbscript
' http://stackoverflow.com/questions/10352211/vba-ado-connection-and-query-parameters
' The function takes three parameters: ADOConnection; sql (string); params, an Array() of parameters
Function sqlOperationParametric(ADOConnection,sql,params)
Dim Cm, Pm, i, p
Set Cm = CreateObject("ADODB.Command")
With Cm
@greenkey
greenkey / ssh-regsrv.sh
Last active February 25, 2016 12:46 — forked from anonymous/ssh-regsrv.sh
#!/bin/bash
if [ ! -f ~/.ssh/id_rsa.pub ]; then
ssh-keygen
fi
echo "Server host:"
read SRV
echo "User on the server host:"