Skip to content

Instantly share code, notes, and snippets.

@sanmadjack
sanmadjack / Get Due Date Warning.sql
Last active December 10, 2015 13:59
This program I'm working on needs to be able to display a warning indicator when a task gets too close to its due date. I allowed the user to specify how many days until due date is safe. The problem is, this needs to take into account weekends and holidays (if respected). So, I needed a way to query what the "warning date" is.
SELECT MIN(days.SD)
FROM
(SELECT SYSDATE + 366 - ROWNUM SD,
EXTRACT(YEAR FROM SYSDATE + 366 - ROWNUM) Y,
EXTRACT(MONTH FROM SYSDATE + 366 - ROWNUM) M,
EXTRACT(DAY FROM SYSDATE + 366 - ROWNUM) D
FROM ALL_OBJECTS WHERE ROWNUM < 368) days
LEFT JOIN WF_NON_WORK_DAYS holidays ON holidays.DAY = days.D AND holidays.MONTH = days.M
WHERE days.SD <= :DUE_DATE AND
(holidays.NON_WORK_DAY IS NULL OR holidays.NON_WORK_DAY = 0) AND
@sanmadjack
sanmadjack / dna.pl
Created January 23, 2013 22:35
Perl class script for loading/writing Blue Martini DNA file
#!/usr/bin/perl
######################################################################
######################################################################
##
## Name: dna.pm
##
## Prpose: Object for the reading and writing of DNA files
##
## Author: Matthew Barbour
@sanmadjack
sanmadjack / jenkins_export.sh
Created January 23, 2013 22:39
Jenkins User Import/Export
# This should be changed to your system's jenkins root JENKINS_ROOT="/var/lib/jenkins"
JENKINS_USERS="$JENKINS_ROOT/users"
JENKINS_JOBS="$JENKINS_ROOT/jobs"
JENKINS_CONFIG="$JENKINS_ROOT/config.xml"
# This variable is used so that we can verify that a user is not found
FAIL_TEST=0
exportUserFolder() {
if [ -d "$JENKINS_USERS/$1" ]; then
@sanmadjack
sanmadjack / WTFException.cs
Created February 13, 2013 14:41
A C# WTF Exception. Is for exceptions that should never, ever happen. And then they do.
using System;
namespace Exceptions {
public class WTFException : Exception {
public WTFException(Exception ex) : base(null, ex) { }
public WTFException(string message, Exception ex) : base(message, ex) { }
public WTFException(string message) : base(message) { }
}
}
@sanmadjack
sanmadjack / Database.php
Created February 13, 2013 15:21
A database connection wrapper that I wrote in 2012. Designed to mimic the Wikimedia's database wrapper. Currently only supports MySQL.
<?php
// Database connection wrapper library written by Matthew Barbour in 2012
// Kind of mimics Wikipedia's db wrapper
class Database {
public $server;
public $user;
public $password;
public $db;
public $link;
@sanmadjack
sanmadjack / FormatDuration.vb
Created March 12, 2013 20:26
Takes a number of minutes as input, and outputs a string formatted as: 9d 09h 09m Leaves off days/hours if not supplied
Private Function FormatDuration(ByVal total As Integer) As String
Dim days As Integer = Math.Floor(total / (60 * 24))
Dim hours As Integer = Math.Floor((total Mod (60 * 24)) / 60)
Dim minutes As Integer = (total Mod (60 * 24)) Mod 60
Dim output As New StringBuilder
If days <> 0 Then
output.Append(days)
output.Append("d ")
End If
If output.Length = 0 Then
@sanmadjack
sanmadjack / PrintDataSetToHTML.vb
Created May 2, 2013 16:16
A function to create a string containing the html table representation of a DataSet
Private Function PrintDataSetToHTML(ByRef ds As DataSet) As String
Dim output As New StringBuilder
For Each dt As DataTable In ds.Tables
output.AppendLine("<table>")
output.Append("<caption>")
output.Append(dt.TableName)
output.AppendLine("</caption>")
output.AppendLine("<tr>")
For Each dc As DataColumn In dt.Columns
output.Append("<th>")
@sanmadjack
sanmadjack / zfs.php
Created September 23, 2013 21:17
PHP ZFS Info Display
<html>
<head>
<script type="text/javascript">
var filesystems=<?php
$filesystems = array();
$header_regex = "|^([A-Za-z0-9/]+)\s+([a-z]+)\s+([^\s]+)\s+([a-z-]+)$|";
$output = array();
@sanmadjack
sanmadjack / crossword.html
Created September 26, 2013 21:23
A crossword puzzle solving assistant
<html>
<head>
<script>
function process() {
var element = document.getElementById("input");
var input = element.value;
var data = new Array();
@sanmadjack
sanmadjack / sysinfo.motd.pl
Last active April 7, 2022 21:02
A MOTD script for displaying system information.
#!/usr/bin/perl
use Data::Dumper;
sub GetIpAddresses{
my $output = qx(ifconfig);
my $hash = {};
my $interface;
foreach my $line (split /[\r\n]+/, $output) {
if($line =~ m/^([^ ]+)/) {