Skip to content

Instantly share code, notes, and snippets.

@greenkey
greenkey / gcj-2017-C.py
Last active April 12, 2017 12:19
My solution for the Problem C of the qualification of 2017's edition of Google Code Jam: Bathroom Stalls
#! /usr/bin/env python
import sys
def progress(s):
print("%-80s\r" % s, file=sys.stderr, end='')
def solve2(line):
@greenkey
greenkey / tablespace_shrink.sql
Created June 14, 2016 13:49
Shrink an oracle tablespace
/*
It is not possible to shrink a tablespace that's being used, in order to reclaim the unused space you can use this script (remember to change the value of OLD_TBSP variable)
The script essentially does the following:
- create a new tablespace appending "_TMP" at the end, it's going to use a datafile with the same name, adding (or incrementing) an id;
- move all the object from the old tablespace to the new one;
(this means that on the filesystem there should be enough space for the new datafile, consider also the extra space for the index rebuild!)
- prints the commands to execute in order to drop the old tablespace and rename the new.
At the end it is possible that the space on the filesystem is not freed, follow the instructions here: http://serverfault.com/questions/501963/how-to-recover-free-space-on-deleted-files-without-restarting-the-referencing-pr
@greenkey
greenkey / fraction_exercise_generator.py
Last active March 2, 2016 10:58
To help my daughters learn fractions, I made an exercise generator. Now they hate me.
#!/usr/bin/python3
from random import randrange, random
from fractions import Fraction
from functools import reduce
from operator import mul
def pf(f):
'''Pretty print the fraction'''
return "{}/{}".format(f.numerator,f.denominator)
@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:"
@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 / 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 / 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 / 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 / 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 / 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