Skip to content

Instantly share code, notes, and snippets.

View 0x1b-xyz's full-sized avatar

Jason Stiefel 0x1b-xyz

View GitHub Profile
@0x1b-xyz
0x1b-xyz / FileBotRename.groovy
Created March 11, 2012 15:24
KMTTG "Custom" script that delegates file renaming to FileBot through the -script feature.
/**
* A FileBot (http://filebot.sourceforge.net) script that first renames the incoming file using the TiVo metadata
* then delegates to the rename() call of FileBot to translate the airdate of TV shows into an SXXEXX format. Movies
* should just pass through without change as long as we had a "movieYear" attribute in the metadata.
*
* To use from KMTTG, set something like this for your "Custom Command" and make sure your "metadata files" is set
* to "last". You should be able to use this strategy with encoded OR mpg files. Your file naming pattern within KMTTG
* shouldn't matter, but my setting is below.
*
* file naming value:
@0x1b-xyz
0x1b-xyz / binarySearch.groovy
Created April 13, 2012 20:41
Some binary searching
/**
* search the (sorted) array for the indicated value
*
* @return index of the value or -1 when not found.
*/
def search(arr, int val) {
int min = 0
int max = arr.size() - 1
while (max > min) {
int piv = Math.abs((min + max) / 2)
@0x1b-xyz
0x1b-xyz / EhcacheStage.groovy
Created September 11, 2012 20:29
A generic ehcache "Stage"
package pbatch.rt.staging
import groovy.util.logging.Log4j
import net.sf.ehcache.Cache
import net.sf.ehcache.CacheManager
import net.sf.ehcache.Element
import net.sf.ehcache.config.CacheConfiguration
import net.sf.ehcache.store.MemoryStoreEvictionPolicy
import org.springframework.util.Assert
import pbatch.BatchId
@0x1b-xyz
0x1b-xyz / clean-jenkins-workspaces.groovy
Created March 20, 2013 19:26
Script that will clean up orphaned or unused workspaces on all slaves. There are a few environment specific tweaks in the script you may need to remove: 1- We use the Cloudbees folders plugin - if you don't then you'll need to refactor to remove folder support 2- Our standard slave names are prefixed with "worker-" and this script will ignore an…
import hudson.node_monitors.*
import hudson.slaves.*
import hudson.model.*
def hudson = Hudson.instance
hudson.slaves.findAll { it.name.startsWith("worker-") }.each { slave ->
println "\n\nExamining ${slave.name} workspaces ..."
def wsRoot = slave.getWorkspaceRoot()
@0x1b-xyz
0x1b-xyz / tree.groovy
Last active December 31, 2015 02:49
Print a hierarchical tree from a direct relationship model
class Tree {
private model = new HashMap<String, Set<String>>()
void add(String node, String dep) {
if (!model[node])
model[node] = new HashSet<String>();
model[node] << dep
}
@0x1b-xyz
0x1b-xyz / gist:9139708
Created February 21, 2014 18:06
Simple cpu benchmark
echo '2^2^20' | time bc > /dev/null
SELECT
'grant '||DECODE(object_type,'TABLE','select,insert,delete,update ','VIEW',
'select,insert,delete,update ','SEQUENCE','SELECT ','PROCEDURE','EXECUTE ','PACKAGE','EXECUTE '
,'TRIGGER','EXECUTE ','FUNCTION','EXECUTE ')|| ' on '||owner||'.'||object_name||
' to xpappusr;'
FROM
dba_objects
WHERE
OWNER='ODMT'
AND object_type IN ('TABLE',
@0x1b-xyz
0x1b-xyz / readwrite.groovy
Created October 10, 2014 16:58
Read/write avro dynamic
/**
* Writes the {@link Encounter}s into the specified avro file.
*/
void write(List<Encounter> encounters, Path output) {
AvroKeyValue<EncounterKey, Encounter> kvRecord =
new AvroKeyValue<EncounterKey, Encounter>(new GenericData.Record(schemaEncounterKv))
DataFileWriter<GenericRecord> fileWriter =
new DataFileWriter<GenericRecord>(dataModel.createDatumWriter(schemaEncounterKv))
@0x1b-xyz
0x1b-xyz / GroovyDates.groovy
Created July 30, 2015 01:22
Date examples I bust out when I'm showing off Groovy
def tomorrow = new Date() + 1
use (TimeCategory) {
def appointment = now + 1.week + 1.days + 15.hours + 10.minutes
def monday = new Date().with { it.clearTime(); it - it.calendarDate.dayOfWeek }
def recurringWeeklyForYear = (1..52).collect { monday + it.weeks }
}
# Call with a machine name to load the environment for that machine. Called
# without a machine name it will load a ~/.docker_env file into the shell
# environment and into launchctl
#
# Added a new var to the mix - DOCKER_HOST_IP
function useDockerMachine() {
if [ $# -eq 0 ]; then
if [ ! -f ~/.docker_env ]; then
>&2 printf "Error: No ~/.docker_env file exists. Specify machine to use.\n"
return