Skip to content

Instantly share code, notes, and snippets.

@WimObiwan
WimObiwan / check-cron.sh
Last active November 27, 2015 10:19
cron-test.sh: tests if a date/time (or the current time if no time) matches a cron specifier. Only the *standard* special characters are supported:
#!/bin/bash
target=$1
datetime=$2
if [ -z "$target" ] ; then
>&2 echo 'No target is specified.'
>&2 echo "Usage: $0 <cron-specification> [<date-time>]"
>&2 echo " e.g. $0 '* 16,17 * * *'"
>&2 echo " e.g. $0 '* 16,17 * * *' '2014-01-01 17:32'"
@WimObiwan
WimObiwan / fnRunningQueries.sql
Last active April 8, 2016 10:42
Check current SQL Server activity
-- Usage:
-- SELECT * FROM fnRunningQueries
-- SELECT * FROM fnRunningQueries(2) ORDER BY totalCpu DESC
-- SELECT GETDATE() DateTime, * INTO QueryHistory FROM fnRunningQueries(0)
-- INSERT INTO QueryHistory SELECT GETDATE() DateTime, * FROM fnRunningQueries(0)
-- SELECT * FROM QueryHistory ORDER BY DateTime DESC
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
@WimObiwan
WimObiwan / Get-TaggedItem.ps1
Last active July 18, 2016 12:39
Rename a file (include git describe in filename) and copy to server location
[cmdletbinding()]
Param(
[string]$Item,
[string]$TagMatch = "*"
)
$ErrorActionPreference = "Stop"
$Item = (Resolve-Path $Item).Path
[CmdletBinding(SupportsShouldProcess)]
param
(
[Parameter(Mandatory = $True)]
[string]$SourceBranch,
[Parameter(Mandatory = $True)]
[string[]]$DestinationBranches
)
@WimObiwan
WimObiwan / Automerge2
Last active August 25, 2017 11:25
Hooks to automerge (fix) branches
#!/bin/sh
# Explanation
#
# 1/ Put the 3 scripts (2 hooks) in .git/hooks of your repository
# 2/ Adjust .git/config to set merge targets:
# e.g.
#
# [branch "fix-MyFixBranch"]
# remote = origin
@WimObiwan
WimObiwan / GitListBiggestFiles.sh
Last active May 4, 2016 08:12
Show biggest files in a GIT repository
#!/bin/sh
# linux / cygwin
git rev-list --objects --all | sort -k 2 > /tmp/allfileshas.txt
git verify-pack -v .git/objects/pack/pack-*.idx | egrep "^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$" | sort -k 3 -n -r | head -25 > /tmp/bigobjects.txt
echo > /tmp/bigtosmall.txt
for SHA in `cut -f 1 -d\ < /tmp/bigobjects.txt`; do
#echo $(grep $SHA /tmp/bigobjects.txt) $(grep $SHA /tmp/allfileshas.txt) | awk '{print $1,$3,$7}' >> /tmp/bigtosmall.txt
echo $(grep $SHA /tmp/bigobjects.txt) $(grep $SHA /tmp/allfileshas.txt) | awk '{print $1,$3,substr($0,index($0,$7))}' >> /tmp/bigtosmall.txt
@WimObiwan
WimObiwan / Default .bashrc
Created May 4, 2016 08:14
Default .bashrc
# Rename/move to ~/.bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
#alias telnet="telnet -e ^["
alias ll="ls -l"
$match = 'CTArchitect-*'
git branch | %{ $_ -replace '^[* ] ([^ ]*$)', '$1' } | ?{ $_ -match '^(Version-.*)|(master)$' } | %{ git describe --match $match $_ }
$contains=''
git branch --contains $contains | %{ $_ -replace '^[* ] ([^ ]*$)', '$1' } | ?{ $_ -match '^(Version-.*)|(master)$' } | %{ git describe --match $match $_ }
git branch -r --contains $contains | %{ $_ -replace '^[* ] ([^ ]*)(?: -> .*)?$', '$1' } | ?{ $_ -match '^(?:.*/)?(Version-.*)|(master)$' } | %{ git describe --match $match $_ }
git tag --contains $contains | Group-Object { $_ -replace '^(.*-v?\d+\.\d+\.\d+)\.\d+$', '$1' } | Where-Object { $_.Name -like $match } | %{ $_.Group[$_.Group.Count - 1]}
(sip && !(sip.CSeq.method == "REGISTER")) || h323
# How-to to copy take a directory 'BuildScripts' out of a big GIT repository 'ContactCentre', retainining history
# STEP 1: Create the BuildScripts repository
# Clone the big repository, which will be stripped down to the directory BuildScripts
git clone ContactCentre BuildScripts
# Safety measure: detach from server, to prevent pushing a split back to the server by mistake
git remote rm origin