Skip to content

Instantly share code, notes, and snippets.

@jwoschitz
jwoschitz / gist:1127168
Created August 5, 2011 09:06
Recursion in T-SQL
/*
* Example usage
* EXEC TestRecursion 5
*
* Expected Output
* -----5 - NESTED LEVEL: 1
* ----4 - NESTED LEVEL: 2
* ---3 - NESTED LEVEL: 3
* --2 - NESTED LEVEL: 4
* -1 - NESTED LEVEL: 5
@jwoschitz
jwoschitz / gist:1129249
Created August 6, 2011 10:29
Brute force implementation / C#
class Program
{
#region Private variables
// the secret password which we will try to find via brute force
private static string password = "p123";
private static string result;
private static bool isMatched = false;
@jwoschitz
jwoschitz / gist:1142462
Created August 12, 2011 16:55
Parse XML in T-SQL
DECLARE @XML XML
SET @XML ='<Facility>
<Resources>
<Resource Type="Printer">
<Item Id="3" Value="Bubbleshots Deskjet Pro" />
<Item Id="253" Value="Topware LaserPrinter 5000" />
<Item Id="7" Value="Jabberbox ClassyImage" />
<Item Id="89" Value="Photoopia Megastar Over9000" />
</Resource>
<Resource Type="Phone">
@jwoschitz
jwoschitz / gist:1143599
Created August 13, 2011 08:11
Load a XML file with OPENROWSET
DECLARE @XML AS XML
SELECT @XML = BulkColumn FROM OPENROWSET(BULK '\\a\file\path\to\your\document.xml', single_blob) AS R
@jwoschitz
jwoschitz / gist:1143601
Created August 13, 2011 08:12
Create multiple batch statements with a delay in between each batch execution / T-SQL
/*
Creates multiple batch statements to run a sql statement with a delay in between each batch execution.
*/
DECLARE
@ReportTimeStamp DATETIME,
@ExitConditionTimeStamp DATETIME,
@Sql NVARCHAR(MAX),
@ParamsDefinition NVARCHAR(MAX),
@IntervalInSeconds INT,
@jwoschitz
jwoschitz / gist:1211077
Created September 12, 2011 11:43
Get date part in MySQL
SELECT DATE('2011-09-10 11:24:03');
#Prints 2011-09-10
SELECT CURDATE()
#Prints the current date, e.g. 2011-09-10
@jwoschitz
jwoschitz / gist:1211105
Created September 12, 2011 12:03
Get date part in T-SQL
SELECT DATEADD(DAY, 0, DATEDIFF(DAY, 0, GETDATE()))
-- Selects the current date as datetime, e.g. 2011-09-10 00:00:00.000
SELECT CONVERT(VARCHAR(8), GETDATE(), 112)
-- Selects the current date as varchar, e.g. 20110910
@jwoschitz
jwoschitz / gist:1427299
Created December 3, 2011 14:48
lifts json format
/api/stations/status
============
stations: [
{
"id": 1,
"name": "U Friedrichstr.",
"lifts_total": 4,
"lifts_working": 3
},
{
@jwoschitz
jwoschitz / gist:1473762
Created December 13, 2011 20:34
Safari & JavaScript Audio
<html>
<body>
html5 audio test
</body>
<script>
/*
tried to use the HTML5 audio without <audio /> tags, just JavaScript
works in Chrome, also in FF if you replace .mp3 with .ogg - does not work in Safari
*/
window.onload = function(){
@jwoschitz
jwoschitz / http_check.py
Created January 23, 2012 18:10
Simple Http check utility
import httplib
import time
def get_current_time():
return time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
def get_connection(domain, port):
if port == httplib.HTTPS_PORT:
return httplib.HTTPSConnection(domain)
return httplib.HTTPConnection(domain)