Skip to content

Instantly share code, notes, and snippets.

@ran488
ran488 / VersionId.java
Created May 24, 2011 20:54
SCM Version Annotation
package com.ran488.samples.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Documented;
/**
* Custom annotation type used to annotate classes with the SCM version id
@ran488
ran488 / WriteApplLogTest.groovy
Created May 24, 2011 21:03
Groovy and JUnit testing for PL/SQL
package com.XXXXX.XXX.plsql
import static org.junit.Assert.*
import org.junit.After
import org.junit.Before
import org.junit.Test
import groovy.sql.Sql
class XXXWriteApplLogTest {
@ran488
ran488 / WriteApplLogTest.story
Created May 24, 2011 21:04
Easyb testing for PL/SQL
package com.XXXXX.XXX.plsql
import groovy.sql.Sql
description """
Prototype of PL/SQL unit testing using Easyb.
Have full access to the Groovy libraries so we can avoid the messy JDBC baggage.
"""
scenario "Writing log message to APPL_LOG table via XXX.WRITE_APPL_LOG procedure",{
@ran488
ran488 / StubTest.groovy
Created June 1, 2011 18:51
Simple sample of using Groovy's dynamic stubs for testing
package com.XXXXX.XXX
import static org.junit.Assert.*
import groovy.mock.interceptor.*
import java.util.List
import org.junit.*
class StubTest {
@ran488
ran488 / PropertiesUtil.java
Created June 1, 2011 19:42
Utility class for reading and writing Properties files
package com.XXXX.XXX.common.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
@ran488
ran488 / JmxOperationsSample.groovy
Created June 2, 2011 13:19
Sample of invoking JMX operations from Groovy
#!/usr/bin/env groovy
import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:9987/jmxrmi'
String beanName = "com.somecompany.Scheduler:k=ScheduledTasks"
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def gmxb = new GroovyMBean(server, beanName)
@ran488
ran488 / oracle_lock_info.sql
Created August 9, 2011 19:59
Show locks being held and by whom (Oracle)
-- show locks in Oracle
select owner||'.'||object_name obj
,oracle_username||' ('||s.status||')' oruser
,os_user_name osuser
,machine computer
,l.process unix
,s.sid||','||s.serial# ss
,r.name rs
,to_char(s.logon_time,'yyyy/mm/dd hh24:mi:ss') time
from v$locked_object l
@ran488
ran488 / simple-ftp-sample.groovy
Created August 9, 2011 20:03
Simple FTP file retrieval sample (Groovy)
@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient
println("About to connect....");
new FTPClient().with {
connect "some-server.some-domain.com"
enterLocalPassiveMode()
login "your-username", "your-password"
changeWorkingDirectory "/var/appl/some/remote/dir/"
def incomingFile = new File("some-file-to-retrieve.log")
@ran488
ran488 / OverrideHostnameVerifierSnippet.java
Created August 11, 2011 13:39
Java snippet to override SSL hostname verifier for DEV purposes
// for when you encounter this crap in your dev or troubleshooting...
// java.security.cert.CertificateException: No name matching somedomain.com found
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
return true;
}
});
@ran488
ran488 / gget.groovy
Created August 11, 2011 13:48
Simple Groovy script to get URL resource (as text) and blast it to stdout
if(args){
def url = args[0]
def text = url.toURL().text
println text
}
else {
println "USAGE: gget url"
}