Sonntag, 18. Dezember 2011

Autowire Jira

When developing plugins for Jira (4.x) you may encountered auto wiring problems in modules with non trivial constructors. For example if you want to enhance time sheet plugin (link) with some custom functions and you want to inject UserManager from shared access layer (link). So you need to let Jira inject UserManager. It will not work via setters/getters if you have a complex constructor (i.e. one with parameters).
So you need to add to injected interface to your constructor - but you have to take care that this doesn't break anything else in your plugin. So overloading existing constructor is the only way to bypass this problem.
As Jira is based on Spring, if someone knows how to solve this problem more elegantly please let me know!

Mittwoch, 30. November 2011

Install Vmware Tools

Installing VMware Tools on CentOS

I don't remember ho often I installed CentOS on VMware and yet I always need to google how this tool installation works. So first of all you need to mount cdrom with vmware tools (image is inserted by player automatically). This can be done by:
mount /dev/cdrom /media/cdrom
Make sure cdrom folder exists. You can chose of course any existing folder. After that just copy VMware package to e.g. /tmp and extract it with:
tar -xzvf WMwareTools-...tar.gz
After that you can enter newly created folder with extracted tools and run vmware-install.pl

Mittwoch, 9. November 2011

Cygwin and telnet

If you are looking for small network tools like telnet, you may found it difficult to find via package search in cygwin's setup tool. That's because it is part of package inetutils. Thought that might save some folks out there google time :)

Mittwoch, 3. August 2011

Starbuck's Unix Tricks

This is just a collection of small tricks I found useful when working on a Unix shell

Rename multiple files
Following bash snippet solves a very common task. You have a list of files or folders and want to add a prefix or suffix. Please note that this little for loop do not differentiate folders and files. Found it nevertheless quite useful:

for f in `ls`;do mv "$f" "$(echo $f"_mysuffix")"; done

Recursive grep on Solaris
On Solaris you usually don't have a recursive grep so you need to work with find and grep.
find . -name *.conf | xargs grep -i 'PATTERN'

Creating folder structures
Following snippet shows how to create based on a list of base folder how to create a common deep folder structure. Things to notice here is -p switch for mkdir and how to iterate over comma separated lists.
#!/bin/bash

IFS=","
FOLDERS="a,b,c"
#cd /yourbasefolder
for i in $FOLDERS
do
   mkdir -p $i/your/folder/structure
done


Count frequencies
Below snippets extracts from an access logfile (apache, application server, etc) column with requester's IP address and compute frequencies. It is piping logfile content to awk to extract on column (separator configured with FS). Next pipe sorts IP addresses, couting step is then done with uniq another nice UNIX tool. Last not least couting is sorted to have a nice chartlist.

cat logs/access.log | awk '{FS = "\t"}; {print $5}' | sort | uniq -c | sort

Freitag, 3. Juni 2011

SQL Server Tools

This post contains some Powershell scripts to quick check some things on a running SQL Server instance. Imagine you got a SQL server delivered by a data centre team and now you are responsible for installing a software that shall use this server.
Before looking in all the various bugs in your delivered software, it is a good idea to check if SQL server was installed and prepared properly. Usually you have some credentials and a server address. So a little tool that checks if instance can be reached with this data would be nice.
Script you can find at [1] does exactly that. Just replace vars with your server's data (hostname, port, credentials). It also retrieves exact version with which you can check if correct patch level was installed (see Microsoft's info at [3]).
Another fancy thing would be to check which databases or roles are available with your user. This can be done using a nice object called Microsoft.SqlServer.Management.SMO.Server . Just google for this object to learn more. A script that retrieves databases, roles and some other interesting infos can be found at [4]. A much more extense example can be found at [5])


References
[1] UserConnectionTest.ps1
https://connectionteste.svn.sourceforge.net/svnroot/connectionteste/SQLTools/UserConnectionTest.ps1
[2] SQL Server Connection String Parameter
http://www.connectionstrings.com/Articles/Show/all-sql-server-connection-string-keywords
[3] SQL Version
http://support.microsoft.com/kb/321185
[4] GetSQLUserRoles.ps1
https://connectionteste.svn.sourceforge.net/svnroot/connectionteste/SQLTools/GetSQLUserRoles.ps1
[5] Lots of SQL Server instance details
http://mspowershell.blogspot.com/2009/12/most-dbas-have-had-to-examine-unknown.html

Dig and Cygwin

Just a quick tip today. If you need dig, a handy DNS query tool, on your cygwin bash you have to install bind package. Searching for Dig in cygwin's setup tool does not help, so after I figured out it is part of BIND I thought I help save some time ;)
Bind is a full blown DNS server but it's not that big to install and dig is definitly worth it ;)

Montag, 14. März 2011

My PowerShell Profile

Starbuck's Powershell profile
This article contains my growing PowerShell profile file. For those of you that are familiar with Unix shells this is a file similiar to .bashrc/.cshrc/... Per default executing this file this forbidden by policy, so you not to activate that. See this article for an interesting introduction to aliases and activation of profile files.

For the impatient reader execute the following command on a PS started as administrator:
Set-ExecutionPolicy Unrestricted 

And here is my (growing) Profile:

# implements a simple curl, lots of stuff still to do :)
function curl($url) {
    if($url){
        if(!$url.StartsWith("http://")) {
            $url = "http://" + $url;
        }
        return (new-object System.Net.WebClient).DownloadString($url);
    }
    else {
        return "Please provide a URL";
    }
}

# this is my tail -f
function tf ($file) {
    if($file) {
        get-content -wait $file;
    }
    else {
        write-host "Please provide a file to listen!";
    }
}

Montag, 28. Februar 2011

Call user functions with USER_INT

Custom PHP in Typoscript

These two listing just shall show you a working example of calling custom PHP functions from Typoscript. I just publish this because in all the existing examples I found some details were missing.

The following listing shows usage of USER_INT which causes no caching of this content element. Please note that your class needs to have a prefix "user_" to be excuted via userFunc. Use admin panel to get according feedback.

includeLibs.hashTools = fileadmin/hashTools.php
page.200 = USER_INT
page.200 {
  userFunc = user_MyTools->testFunction
 }

Following PHP listing shows a simple function to be called via Typoscript.
<?php

class user_MyTools {

  function testFunction($content,$conf) {
     return "Hallo Welt!";
  }

}

?>

Typoscript link with parameters

How to create an external link with parameters with Typoscript

Have you ever had the need to add to an external link some dynamic parameters? Well before you grab your PHP editor and start developing have a look into the following Typoscript listing:

[loginUser = *]

page.201 = COA_INT
page.201 {
10 = TEXT
10.value = My fancy link
10.typolink.parameter {
  dataWrap = http://www.mysite.de/index.php?param=value&id={TSFE:fe_user|user|uid}&name={TSFE:fe_user|user|username}_{TSFE:fe_user|user|city}
 }
}
[global]
What this script does is it creates a link using typolink function and you can add some parameters to it. Good thing here is, that can add some dynamic parameters such as user name of current logged in user.

With accessing TSFE which is the central array that Typo3 uses to store almost everything you can add many more interesting parameters.

Please note that content object used here is COA_INT and that means this is generated every time a page is displayed. This way for every user this example creates a proper parameter.

Dienstag, 22. Februar 2011

Powershell test Web Service

For all of you who haven't touched it yet - Microsoft has put an interesting shell to Windows operating systems called Powershell. Following code creates a web service stub (proxy in dot.net speak) and calls a method. If you call a web service that is running on a IIS you often need some kind of authentication.
#  build credential object 
$Pass = ConvertTo-SecureString " xxxx " –AsPlaintext –Force
$Cred = New-Object System.Management.Automation.PsCredential "domain\User",$Pass

# just a simple web service tester
$wsProxy = New-WebServiceProxy -Credential $Cred -URI http://yourserver.com/path?WSDL
$result = $wsProxy.WebServiceMethod('Parameter') 
$result


To use this example you need to replace WebServiceMethod with the web service method you want to use. It is up to you to provide proper parameters. Having a look into service's WSDL file will help here.

General note, execution of unsigend srcripts needs to be activated. Please see
http://www.windowsecurity.com/articles/PowerShell-Security.html for more information.