Skip to content

Instantly share code, notes, and snippets.

View jhinrichsen's full-sized avatar

Jochen Hinrichsen jhinrichsen

View GitHub Profile
@jhinrichsen
jhinrichsen / uptime.groovy
Created March 12, 2014 13:52
Java VM uptime, useful to check if a service has been restarted
def ms = java.lang.management.ManagementFactory.getRuntimeMXBean().getUptime()
def s = ms / 1000
def min = s / 60
def hours = min / 60
println "Uptime: ${s} seconds/ ${min} minutes/ ${hours} hours."
// Sort by multiple keys
Collection.metaClass.sort = { Closure... closures ->
delegate.sort(false) { a, b ->
closures.findResult { c -> c(a) <=> c(b) ?: null }
}
}
List threads = Thread.getThreads()
println "${threads.size()}: Threads:"
threads.sort({it.threadGroup.name}, {it.name}).each { println "${it.threadGroup.name}: ${it.name.take(80)}" }
def isAuthenticated(User u) {
try {
return u.impersonate().isAuthenticated()
}
// Users pulled from SCM history e.a. are not GUI users
catch (org.acegisecurity.userdetails.UsernameNotFoundException xc) {
return false
}
}
// Fetch all deployed artifacts of a Maven build
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
@jhinrichsen
jhinrichsen / main.go
Created March 8, 2018 11:39
Jenkins average job build time
// Show average duration of all builds for a given Jenkins job
// return codes:
// 1: bad usage
 
package main
 
import (
"encoding/json"
"flag"
"fmt"
@jhinrichsen
jhinrichsen / main.go
Created March 21, 2018 11:32
convert jaxws's wsimport from Maven to Bazel
// Generate buildozer commands from POM for wsimport tasks
// Needs to be executed in the root of the Maven project because files are
// looked up relative to module directory
package main
import (
"encoding/xml"
"flag"
"fmt"
@jhinrichsen
jhinrichsen / main.go
Created April 12, 2018 11:27
Jenkins: find jobs without a corresponding config.xml (can happen if Jenkins gets bent out of shape)
package main
import (
"flag"
"fmt"
"log"
"os"
"path"
)
@jhinrichsen
jhinrichsen / main.go
Created April 12, 2018 11:39
Low budget man-in-the-middle
package main
import (
"flag"
"fmt"
"io"
"log"
"net"
"os"
)
@jhinrichsen
jhinrichsen / main.go
Created April 12, 2018 11:45
Schedule Sonatype Nexus tasks that rebuild npm metadata via REST
// Schedule Nexus tasks that rebuild npm metadata via REST
// Logging on stderr, run response as JSON on stdout
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
@jhinrichsen
jhinrichsen / main.go
Created April 12, 2018 11:48
BMI commandline calculator
package main
import (
"fmt"
"os"
"strconv"
)
func Bmi(m, l float64) int {
return int(m/(l*l) + 0.5)