Skip to content

Instantly share code, notes, and snippets.

@raidzero
raidzero / .bashrc
Created April 25, 2016 20:56
show git branch in command prompt
function get_git_branch_prompt() {
echo " `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\(\1\)\ /'`"
}
function git_prompt {
local __git_branch='`get_git_branch_prompt`'
export PS1="\@ \W\[\033[32m\]$__git_branch\[\033[00m\]\$ "
}
git_prompt
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define BUF_SIZE 4096
typedef struct {
unsigned long int user;
unsigned long int nice;
unsigned long int system;
@raidzero
raidzero / tcbuilds.py
Created June 28, 2016 17:02
get list of running & queued builds on a teamcity server
#!/usr/bin/env python
import base64
import os
import sys
import urllib2
import xml.etree.ElementTree
def openUrl(urlStr, user, passwd):
req = urllib2.Request(urlStr)
authStr = base64.encodestring('%s:%s' % (user, passwd)).strip()
@raidzero
raidzero / dates.groovy
Last active December 22, 2015 19:40
groovy extract date range in days from xml (for soapui)
import groovy.time.TimeCategory
// create XmlHolder for request content
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
// get arguments
def startDateStr = holder["//b:StartDate"]
def endDateStr = holder["//b:EndDate"]
log.info "start: " + startDateStr + " end:" + endDateStr
@raidzero
raidzero / launchOrRaiseTerm.sh
Created March 20, 2015 17:29
Launch a new terminal or just find one and bring it to the foreground - meant for a keyboard shortcut or WM menu option
#!/bin/sh
HOSTNAME=`hostname`
# command to launch terminal
TERM_CMD="xfce4-terminal"
# what my terminal window name will always start with
NAME_PREFIX="#!"
@raidzero
raidzero / panalyze.py
Last active August 29, 2015 14:17
python script to analyze directory and print number of lines found in each type of file
#!/usr/bin/python2
import os, sys
# list comprehension to stick a dot onto each given extension
exts = ['.' + ext for ext in sys.argv[2:]]
# dictionaries that hold the count data
fileCount = dict(); lineCount = dict()
# functin to count lines in a file
@raidzero
raidzero / git_find.sh
Created March 2, 2015 22:56
Simple script to find occurrences of a git commit in all branches
#!/bin/sh
if [ -z "$1" ]; then
bname=`basename $0`
echo "Usage: $bname SHA"
exit 1
fi
PATCH_ID=`git show -p $1 | git patch-id | awk '{print$1}'`
@raidzero
raidzero / split.c
Created October 21, 2014 19:02
Split X into N uniformly-distributed pieces (C)
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
int* split(int n, int numPieces);
int randInt(int min, int max);
int sumList(int* list, int size);
void printList(int* list, int size);
void seedrand();
@raidzero
raidzero / Split.java
Created October 21, 2014 18:34
Split X into N uniformly-distributed pieces (java)
import java.util.ArrayList;
import java.util.Random;
import java.lang.Math;
public class Split {
private static Random rand = new Random();
public static void main(String[] args) {
ArrayList<Integer> list = splitNum(Integer.valueOf(args[0]), Integer.valueOf(args[1]));
@raidzero
raidzero / split.py
Created October 21, 2014 17:09
Split N into X uniformly-distributed pieces
#!/usr/bin/python2.7
import sys
from random import randrange
def split(n, numPieces):
rtn = []
for i in range(numPieces):
# get a good starting position to deviate from