home / blog

Minimal jenkins, git, gradle setup on Ubuntu 12.04

Minimal jenkins, git, gradle setup on Ubuntu 12.04

Although gradle is available via app-get, the current version is broken

Manual install of jenkins

apt-get remove gradle
wget http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-8-bin.zip
sudo mv gradle-1.0-milestone-8 /usr/share/
sudo ln -s /usr/share/gradle-1.0-milestone-8/bin/gradle /usr/bin/

Normal install of jenkins.

sudo apt-get install jenkins

Setup of jenkins.

  • Add plugin : git
  • Add plugin : gradle
  • Create new project
    • set repository URL /data/development/repo
    • set poll SCM * * * * *
    • Select git advanced options – skip internal tag
    • Add build step – gradle
    • Set gradle root directory java/TestProject
Posted in geek | Tagged , , , | Leave a comment

Gradle for MacOSX

Pretty much the absolute minimum build.gradle file…

apply plugin: 'java'
apply plugin: 'eclipse'

Project structure

./build.gradle
./src
./src/main
./src/main/java
./src/main/java/com
./src/main/java/com/adamish
./src/main/java/com/adamish/testproject
./src/main/java/com/adamish/testproject/Main.java

Now install gradle and build it.

sudo port install gradle
sudo port selfupdate
gradle clean ec build
....
:clean UP-TO-DATE
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
:check
:build

BUILD SUCCESSFUL

Total time: 11.212 secs
Posted in geek | Tagged , | Leave a comment

Command line WPA connect

There may be circumstances where you need wireless connectivity but you’ve not got network manager running – perhaps you corrupted your installation :(…

wpa_passphrase networkname password > foo.conf
killall -9 wpa_supplicant
sudo wpa_supplicant -Dwext -i wlan0 -c foo.conf
Posted in geek | Tagged , | Leave a comment

Comparing maps

Using a combination of cloning constructors and removeAll() for subsetting…

Map<String, String> beforeMap = new HashMap<String, String>();
beforeMap.put("a", "1");
beforeMap.put("b", "2");
beforeMap.put("c", "3");
Map<String, String> afterMap = new HashMap<String, String>();
afterMap.put("a", "1");
afterMap.put("c", "333");

Code

Set<String> removedKeys = new HashSet<String>(beforeMap.keySet());
removedKeys.removeAll(afterMap.keySet());

Set<String> addedKeys = new HashSet<String>(afterMap.keySet());
addedKeys.removeAll(beforeMap.keySet());

Set<Entry<String, String>> changedEntries = new HashSet<Entry<String, String>>(afterMap.entrySet());
changedEntries.removeAll(beforeMap.entrySet());

System.out.println("added " + addedKeys);
System.out.println("removed " + removedKeys);
System.out.println("changed " + changedEntries);

Output

added []
removed [b]
changed [c=333]
Posted in geek | Tagged | Leave a comment

List partitioning

I’ve seen this done so many times in different ways, the easiest is definitely using subList. Note how use of Math.min removes need for a if statement.

int partitionSize = 2;
List<List<String>> partitions = new LinkedList<List<String>>();
for (int i = 0; i < messages.size(); i += partitionSize) {
    partitions.add(messages.subList(i,
            i + Math.min(partitionSize, messages.size() - i)));
}
Posted in geek | Tagged | Leave a comment

Simple port scanner in BASH using netcat

for port in {1..65535}; do
  nc -w 1 localhost $port > /dev/null && echo "Port $port open" || echo "Port $port closed";
done;
Posted in geek | Tagged | Leave a comment

Convert dotted IP to decimal IP – my comedy answer

String input = "134.115.64.1";
String sum = input.replaceAll("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)",
        "($1 * 16777216) + ($2 * 65536) + ($3 * 256) + $4");
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");

double result = (Double) engine.eval(sum);
System.out.println((long) result);
Posted in geek | Tagged , | Leave a comment

Reverse geocode using PHP

function getPostcode($lat, $lng) {
  $returnValue = NULL;
  $ch = curl_init();
  $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&sensor=false";
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $result = curl_exec($ch);
  $json = json_decode($result, TRUE);

  if (isset($json['results'])) {
     foreach    ($json['results'] as $result) {
        foreach ($result['address_components'] as $address_component) {
          $types = $address_component['types'];
          if (in_array('postal_code', $types) && sizeof($types) == 1) {
             $returnValue = $address_component['short_name'];
          }
    }
     }
  }
  return $returnValue;
}

echo getPostcode(51.4691, -0.2963);

Posted in geek | Tagged , | Leave a comment

PDF page selection on the command line

How to make extract a number of pages from a PDF doc on the command line… Here we extract pages 43 and 44.

pdftk A=Vol_3_Issue_2.pdf cat A43-44 output out.pdf
Posted in geek | Leave a comment

HTML5 animated fundraising thermometer

My 2nd experiment with HTML5 canvas drawing API… an animated fundraising thermometer. There are a number of existing solutions on the open source market but most seem quite clumsy and none make use of HTML5. So in an attempt to be the first I thought I’d have a go. See live demo page. The code is still a little rough around the edges but feel free to use under LGPL.

Posted in geek | Leave a comment