Using the clipboard in WSH
How to get the text from the clipboard
objIE.Navigate("about:blank")
textFromClipboard = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
WScript.Echo textFromClipboard
How to put the text into clipboard
Set objIE = WScript.CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop
objIE.document.ParentWindow.ClipboardData.SetData "text", textIntoClipboard
objIE.Quit
The detailed explanation could be found here.
Topics: Windows scripts, clipboard, copy | No Comments »
Oracle: check the existance of logon/logoff triggers
FROM sys.dba_triggers
WHERE TRIGGERING_EVENT LIKE 'LOGON%' AND status='ENABLED' AND owner='SYS'
UNION
SELECT DECODE((COUNT(trigger_name)),0,'LOGOFF trigger missing','', 'Number of logoff triggers:' || COUNT(trigger_name)) "INFO"
FROM sys.dba_triggers
WHERE TRIGGERING_EVENT LIKE 'LOGOFF%' AND status='ENABLED' AND owner='SYS'
The field TRIGGERING_EVENT could have the spaces at the end! Very clever...
Topics: Oracle, login, trigger | No Comments »
Unix shell: workaround for loop problem
It's not possible to get the value of the loop variables in some versions of ksh.
Example:
num=0
cat $0 | while read line ; do
let num=num+1
done
echo "Number=$num"
This script will return "Number=0" as the result.
Here is the workaround for the problem: You should change the redirection method for the input file.
l=0
while read line ; do
let l=l+1
done < $0
echo "Number=$l"
The last script will return the correct result: "Number=9"
Topics: Unix Shell | 1 Comment »
JavaScript: edit web page in browser
Here is small bookmarklet, which allows to edit the web page for any site (ok, You could save the results on Your local machine only).
Topics: browser, javascript | No Comments »
Oracle: redo log switches by date
The following script help to find, how often the redo logs were switched.
It calculates the number by date and by hour.
Topics: Oracle | No Comments »
JavaScript: Soundex implementation
There is a special algorithm for comparision strings, which sound similar (Soundex).
Here is JavaScript Soundex implementation:
{
var s_rez = "0000" ;
var new_code, prev, idx
a_codes = { "bfpv": 1, "cgjkqsxz":2, "dt": 3, "l": 4, "mn": 5, "r": 6 };
s_src = s_src.toLowerCase().replace(/ /g,"")
if ( s_src.length < 1) {
return(s_rez);
}
s_rez = s_src.substr(0,1);
prev = "0";
for ( idx = 1 ; idx < s_src.length ; idx++) {
new_code = "0";
cur_char = s_src.substr(idx,1)
for (s_code in a_codes)
if (s_code.indexOf(cur_char) >= 0)
{ new_code = a_codes[ s_code ] ; break ; }
if (new_code != prev && new_code != "0" ) {
s_rez += new_code;
}
prev = new_code;
}
s_rez = s_rez + "0000"
return s_rez.substr(0,4);
}
Topics: javascript | No Comments »
Dynamic image resizing in PHP
Via Darren Hoyt we found a reference to TimThumb, a quick and fast PHP script for on-the-fly image resizing. Once the script is on the server, and named timthumb.php, you can use the following reference to launch it:
<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />
Here's the source code for timthumb.php:
// http://code.google.com/p/timthumb/
// MIT License: http://www.opensource.org/licenses/mit-license.php
/* Parameters allowed: */
// w: width
// h: height
// zc: zoom crop (0 or 1)
// q: quality (default is 75 and max is 100)
// HTML example: <img src="/scripts/timthumb.php?src=/images/whatever.jpg&w=150&h=200&zc=1" alt="" />
if( !isset( $_REQUEST[ "src" ] ) ) { die( "no image specified" ); }
// clean params before use
$src = preg_replace( "/^(\.+(\/|))+/", "", $_REQUEST['src'] );
$src = preg_replace( '/^(s?f|ht)tps?:\/\/[^\/]+/i', '', $src );
$new_width = preg_replace( "/[^0-9]/", "", $_REQUEST[ 'w' ] );
$new_height = preg_replace( "/[^0-9]/", "", $_REQUEST[ 'h' ] );
$zoom_crop = preg_replace( "/[^0-9]/", "", $_REQUEST[ 'zc' ] );
if( !isset( $_REQUEST['q'] ) ) { $quality = 80; } else { $quality = preg_replace("/[^0-9]/", "", $_REQUEST['q'] ); }
// set path to cache directory (default is ./cache)
// this can be changed to a different location
$cache_dir = './cache';
// get mime type of src
$mime_type = mime_type( $src );
// check to see if this image is in the cache already
check_cache( $cache_dir, $mime_type );
// make sure that the src is gif/jpg/png
if( !valid_src_mime_type( $mime_type ) ) {
$error = "Invalid src mime type: $mime_type";
die( $error );
}
// check to see if GD function exist
if(!function_exists('imagecreatetruecolor')) {
$error = "GD Library Error: imagecreatetruecolor does not exist";
die( $error );
}
// set document root
$doc_root = $_SERVER['DOCUMENT_ROOT'];
// get path to image on file system
$src = $doc_root . '/' . $src;
if(strlen($src) && file_exists( $src ) ) {
// open the existing image
$image = open_image($mime_type, $src);
if ($image === false) { die ('Unable to open image : ' . $src ); }
// Get original width and height
$width = imagesx($image);
$height = imagesy($image);
// generate new w/h if not provided
if($new_width && !$new_height) {
$new_height = $height * ($new_width/$width);
}
elseif($new_height && !$new_width) {
$new_width = $width * ($new_height/$height);
}
elseif(!$new_width && !$new_height) {
$new_width = $width;
$new_height = $height;
}
// create a new true color image
$canvas = imagecreatetruecolor($new_width, $new_height);
if( $zoom_crop ) {
$src_x = $src_y = 0;
$src_w = $width;
$src_h = $height;
$cmp_x = $width / $new_width;
$cmp_y = $height / $new_height;
// calculate x or y coordinate and width or height of source
if ( $cmp_x > $cmp_y ) {
$src_w = round( ( $width / $cmp_x * $cmp_y ) );
$src_x = round( ( $width - ( $width / $cmp_x * $cmp_y ) ) / 2 );
}
elseif ( $cmp_y > $cmp_x ) {
$src_h = round( ( $height / $cmp_y * $cmp_x ) );
$src_y = round( ( $height - ( $height / $cmp_y * $cmp_x ) ) / 2 );
}
imagecopyresampled( $canvas, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h );
}
else {
// copy and resize part of an image with resampling
imagecopyresampled( $canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
}
// output image to browser based on mime type
show_image( $mime_type, $canvas, $quality, $cache_dir );
// remove image from memory
ImageDestroy( $canvas );
} else {
if( strlen( $src ) ) { echo $src . ' not found.'; } else { echo 'no source specified.'; }
}
function show_image ($mime_type, $image_resized, $quality, $cache_dir) {
// check to see if we can write to the cache directory
$is_writable = 0;
$cache_file_name = $cache_dir . '/' . get_cache_file();
if( touch( $cache_file_name ) ) {
// give 666 permissions so that the developer
// can overwrite web server user
chmod( $cache_file_name, 0666 );
$is_writable = 1;
}
else {
$cache_file_name = NULL;
header('Content-type: ' . $mime_type);
}
if(stristr( $mime_type, 'gif' ) ) {
imagegif( $image_resized, $cache_file_name );
}
elseif( stristr( $mime_type, 'jpeg' ) ) {
imagejpeg( $image_resized, $cache_file_name, $quality );
}
elseif( stristr( $mime_type, 'png' ) ) {
imagepng( $image_resized, $cache_file_name, ceil( $quality / 10 ) );
}
if( $is_writable ) { show_cache_file( $cache_dir, $mime_type ); }
exit;
}
function open_image ($mime_type, $src) {
if(stristr($mime_type, 'gif')) {
$image = imagecreatefromgif($src);
}
elseif(stristr($mime_type, 'jpeg')) {
$image = imagecreatefromjpeg($src);
}
elseif(stristr($mime_type, 'png')) {
$image = imagecreatefrompng($src);
}
return $image;
}
function mime_type ($file) {
$frags = split("\.", $file);
$ext = strtolower( $frags[ count( $frags ) - 1 ] );
$types = array(
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'doc' => 'application/msword',
'xls' => 'application/msword',
'xml' => 'text/xml',
'html' => 'text/html'
);
$mime_type = $types[$ext];
if(!strlen($mime_type)) { $mime_type = 'unknown'; }
return($mime_type);
}
function valid_src_mime_type ( $mime_type ) {
if( preg_match( "/jpg|jpeg|gif|png/i", $mime_type ) ) { return 1; }
return 0;
}
function check_cache ( $cache_dir, $mime_type ) {
// make sure cache dir exists
if(!file_exists($cache_dir)) {
// give 777 permissions so that developer can overwrite
// files created by web server user
mkdir( $cache_dir );
chmod( $cache_dir, 0777 );
}
show_cache_file( $cache_dir, $mime_type );
}
function show_cache_file ( $cache_dir, $mime_type ) {
$cache_file = get_cache_file();
if( file_exists( $cache_dir . '/' . $cache_file ) ) {
// check for updates
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ]);
$gmdate_mod = gmdate('D, d M Y H:i:s', filemtime( $cache_dir . '/' . $cache_file ) );
if(strstr($gmdate_mod, 'GMT')) {
$gmdate_mod .= " GMT";
}
//error_log("TimThumb: $gmdate_mod == $if_modified_since");
if ( $if_modified_since == $gmdate_mod ) {
header( "HTTP/1.1 304 Not Modified" );
exit;
}
// send headers then display image
header( "Content-Type: " . $mime_type );
header( "Last-Modified: " . gmdate('D, d M Y H:i:s', filemtime( $cache_dir . '/' . $cache_file ) . " GMT" ) );
header( "Content-Length: " . filesize( $cache_dir . '/' . $cache_file ) );
header( "Cache-Control: max-age=9999, must-revalidate" );
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 9999 ) . "GMT" );
readfile( $cache_dir . '/' . $cache_file );
exit;
}
}
function get_cache_file () {
$request_params = $_REQUEST;
$cachename = $_REQUEST['src'] . $_REQUEST['w'] . $_REQUEST['h'] . $_REQUEST['zc'] . $_REQUEST['q'];
$cache_file = md5( $cachename );
return $cache_file;
}
Topics: PHP | 1 Comment »
Oracle: usage of the tablespaces (permanent and temporary)
SET COLSEP '|'
SET VERIFY off
SET serveroutput ON SIZE 1000000
BREAK ON report
COLUMN tablespace_name format a30 heading 'TABLESPACE'
COLUMN sizegb format 9999999999D9 heading 'SIZE-Gb'
COLUMN usedproc format 999D99 heading 'USED-%'
COLUMN status format a10 heading 'STATUS'
COMPUTE SUM LABEL 'Total size:' OF sizegb ON report
SELECT b.tablespace_name ,
b.bytes/1024/1024/1024 AS sizegb ,
NVL(100-((a.bytes/b.bytes)*100), 100) usedproc,
REPLACE(c.status,' ','_') status
FROM
( SELECT tablespace_name,
SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name
) a ,
( SELECT tablespace_name,
SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name
) b ,
dba_tablespaces c
WHERE b.tablespace_name = a.tablespace_name (+)
AND b.tablespace_name = c.tablespace_name
UNION
SELECT f.TABLESPACE_NAME,
f.TOTAL_MB/1024 sizegb,
NVL( (u.USED_MB/f.TOTAL_MB)*100, 0 ) usedproc,
'TEMPORARY' status
FROM
(
SELECT f1.TABLESPACE_NAME,SUM( f1.BYTES/1024/1024 ) TOTAL_MB
FROM (
SELECT TABLESPACE_NAME,BYTES
FROM dba_temp_files
UNION ALL
SELECT TABLESPACE_NAME,BYTES
FROM dba_data_files
WHERE TABLESPACE_NAME IN (
SELECT TABLESPACE_NAME
FROM dba_tablespaces
WHERE CONTENTS='TEMPORARY'
)
) f1
GROUP BY f1.TABLESPACE_NAME
) f,
(
SELECT u1.TABLESPACE,
SUM(u1.blocks) * MAX((SELECT VALUE FROM v$parameter WHERE name='db_block_size')/1024/1024) USED_MB
FROM v$sort_usage u1
GROUP BY u1.TABLESPACE
) u
WHERE f.TABLESPACE_NAME = u.TABLESPACE (+)
ORDER BY 1;
Topics: Oracle, space, tablespace, temp | No Comments »
AppleScript: rotate mov file in QuickTime Pro
Some kind of life hack: it's very easy to make mov file with digital camera, rotating it 90 degrees. However, it's not so easy to convert the result file to the 'visible' form.
QuickTime Pro could do this, and I found the AppleScript script, which could make it even more easy.
set m to (get movie 1)
rotate m by -90
save self contained m in (choose file name with prompt "save self contained movie")
end tell
The script is mentioned here
Topics: AppleScript, video | 1 Comment »
Oracle: plan of the running query
SELECT operation,
options,
object_name,
partition_id
FROM v$sql_plan
WHERE address IN
( SELECT sql_address FROM v$session WHERE sid = &sid.)
ORDER BY id;
Topics: Oracle, performance | No Comments »