Stubbisms – Tony’s Weblog

Scripts and Code Snippits

A collection of scripts and code snippits I’ve written to help me do stuff.

I’ll add to this page as I go. I’m not going to try and back-post every little nifty thing I’ve ever written! 🙂

Linux Bash

line count:wc -l `find . -name "*.[ch]" -print` | tail -1 | awk '{print $1}'

Nifty Maven Bits

dependency:sources to get once-off sources for all your dependencies instead of telling m2eclipse to get sources. This avoides constant re-trying to get sources that don’t exist (that can take ages).

Groovy

Unfortunately the WordPress formatter doesn’t support Groovy yet. Closest you can get is Java.

generateTestSuite.groovy

Reads in the list of files in the current directory and creates a Selenese test suite script. Intended to gather together Selenese tests into a suite.

I don’t use this script anymore as I prefer using Selenium through Selenium Remote Control.

writer = new File("test.html").newWriter()
writer.writeLine("
<table><tbody>
<tr>
<td><a href="${fn}" target="testFrame">${fn}</a></td>
</tr>
</tbody></table>
")
writer.close()

Oracle

Enable and disable triggers in Oracle

ALTER TRIGGER trigger_name DISABLE;
ALTER TRIGGER trigger_name ENABLE;

Analyse Oracle lock states

select * from dba_blockers;
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;

SELECT s.sid,
s.serial#,
s.osuser,
s.program
FROM   v$session s
WHERE s.sid in (34,10,39);

ALTER SYSTEM KILL SESSION '10,1688' IMMEDIATE;
ALTER SYSTEM KILL SESSION '34,19649' IMMEDIATE;
ALTER SYSTEM KILL SESSION '39,19948' IMMEDIATE;

Various other little bits I haven’t properly categorised yet.

# Shows blocking sessions

select l1.sid, ' IS BLOCKING ', l2.sid from v$lock l1, v$lock l2 where l1.block =1 and l2.request > 0 and l1.id1=l2.id1 and l1.id2=l2.id2 ;

# Shows the two blocking sessions plus information

select s1.username || '@' || s1.machine || ' ( SID=' || s1.sid || ' )  is blocking ' || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status from v$lock l1, v$session s1, v$lock l2, v$session s2 where s1.sid=l1.sid and s2.sid=l2.sid and l1.BLOCK=1 and l2.request > 0 and l1.id1 = l2.id1 and l2.id2 = l2.id2 ;

select object_name from dba_objects where object_id=3009 ;

select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row# from v$session where sid=33;

select do.object_name, row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#, dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# ) from v$session s, dba_objects do where sid=30 and s.ROW_WAIT_OBJ# = do.OBJECT_ID ;

select * from tstlock where rowid='AAAVnHAAQAAAp0tAAA' ;

# shows blocking sql
select s.sid, q.sql_text from v$sqltext q, v$session s
where q.address = s.sql_address
and s.sid = &sid
order by piece;

#Shows session information
SELECT s.sid, s.serial#, s.osuser, s.program FROM v$session s WHERE s.osuser='astubbs';
ALTER SYSTEM KILL SESSION 'sid,serial#';

ALTER SYSTEM KILL SESSION '32,7561';
ALTER SYSTEM KILL SESSION '35,10761';
ALTER SYSTEM KILL SESSION '37,11261';
ALTER SYSTEM KILL SESSION '39,13269';

select * from dba_blockers;
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;

SELECT s.sid,
s.serial#,
s.osuser,
s.program
FROM   v$session s
WHERE s.sid in (34,10,39);

ALTER SYSTEM KILL SESSION '10,1688' IMMEDIATE;
ALTER SYSTEM KILL SESSION '34,19649' IMMEDIATE;
ALTER SYSTEM KILL SESSION '39,19948' IMMEDIATE;

sed magic

sed command to insert toDate() fuction into sample data build script:

cat db2_sample_data.sql | sed "s| '[-0-9]\+'| to_date\(&, 'yyyy-mm-dd')|g" | sed "s|'[-0-9]\+ [0-9\:\.]\+'| to_date\(&, 'yyyy-mm-dd hh24:mi:ss.ms')|g" > result.sql

cat db2_sample_data.sql | sed "s| '[-0-9]\+'| to_date\(&, 'yyyy-mm-dd')|g" | sed "s|'[-0-9]\+ [0-9\:\.]\+'| to_date\(
&, 'yyyy-mm-dd hh24:mi:ss')|g" | sed "s|.0'|'|g" > result.sql

WordPressPosting Sourcecode

[sourcecode language='css']…[/sourcecode].

Currently they support syntax highlighting for the following language codes:

  • cpp
  • csharp
  • css
  • delphi
  • java
  • jscript
  • php
  • python
  • ruby
  • sql
  • vb
  • xml
Advertisements

1 Comment »

  1. for some reason when I use the term CASE in my sql statement within the “

    " it does not display the coloring correctly.
    
    [sourcecode language="sql" padlinenumbers="2"]
    SET @srv = CASE
    		-- Check for back slash if not return server name
    		WHEN CHARINDEX('\',@@SERVERNAME) = 0
    		THEN @@SERVERNAME
    		-- if back slash found return all leading char
    		WHEN CHARINDEX('\',@@SERVERNAME) > 0
    		THEN PARSENAME(REPLACE(@@SERVERNAME,'\','.'),2)
    	   END
    

    "
    SET @srv = CASE
    		-- Check for back slash if not return server name
    		WHEN CHARINDEX('\',@@SERVERNAME) = 0
    		THEN @@SERVERNAME
    		-- if back slash found return all leading char
    		WHEN CHARINDEX('\',@@SERVERNAME) > 0
    		THEN PARSENAME(REPLACE(@@SERVERNAME,'\','.'),2)
    	   END
    "

    Comment by Samson J. Loo — December 23, 2010 @ 8:45 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: