Skip to content

Instantly share code, notes, and snippets.

View philippwiddra's full-sized avatar

Philipp Widdra philippwiddra

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@philippwiddra
philippwiddra / firewall.sh
Created October 30, 2015 23:20
Simple iptables configuration script
#!/bin/sh
IPT=/sbin/iptables
case "$1" in
start)
$IPT -F INPUT # Flush Input
$IPT -F OUTPUT # Flush Output
$IPT -F FORWARD # Flush Forward
@philippwiddra
philippwiddra / TransactSqlScriptDomTest.cs
Created March 22, 2016 23:12
Some examples with Microsoft.SqlServer.TransactSql.ScriptDom and TSql generation and parsing
using Microsoft.SqlServer.TransactSql.ScriptDom;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TransactSqlScriptDomTest
{
@philippwiddra
philippwiddra / ConsoleReadPassword.cs
Created June 23, 2016 08:14
Simple function to let the user enter a password for C# console applications.
static string ConsoleReadPassword()
{
StringBuilder stringBuilder = new StringBuilder();
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
while (keyInfo.Key != ConsoleKey.Enter)
{
if (keyInfo.Key == ConsoleKey.Backspace)
{
stringBuilder.Remove(stringBuilder.Length - 1, 1);
$filterXml = '<QueryList>
<Query Id="0" Path="System">
<Select Path="System">*[System[(Level=1 )]]</Select>
</Query>
</QueryList>'
$pcs = (Get-ADComputer -Filter * | ? { Test-Connection $_.DNSHostName -Quiet -Count 1 }).DNSHostName
$pcs | % {
Get-WinEvent -FilterXml $filterXml -ComputerName $_ | ? TimeCreated -GT (Get-Date).AddMonths(-1)
$pcs = (Get-ADComputer -Filter * | ? { Test-Connection $_.DNSHostName -Quiet -Count 1 }).DNSHostName
Invoke-Command -ComputerName $pcs -ScriptBlock {
$result = query user
$success = $result[1] -match "^[> ]([^ ]+) +([^ ]+) +([0-9]+) +([^ ]+) +([^ ]+) +(.+)$"
if ($success) {
New-Object PSObject -Property @{
PC = $env:computername;
Benutzername = $Matches[1];
Sitzungsname = $Matches[2];
@philippwiddra
philippwiddra / jquery.validateext.date.js
Created October 4, 2017 14:22
Extension for jquery.validate to be used with ASP.Net MVC
$.validator.methods.date = function (value, element) {
var extractGermanDate = function (dateString) {
var matches = /^(\d{1,2})\.(\d{1,2})\.(\d{4})( (\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/.exec(dateString);
if (matches == null) {
return false;
} else {
return {
day: matches[1],
month: matches[2] - 1,
year: matches[3],
@philippwiddra
philippwiddra / 201701010000000_FileTableAdded.cs
Created October 6, 2017 11:57
Example of how to use SQL Server FileTables with Entity Framework 6 Code First Migrations.
namespace Project.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class FileTableAdded : DbMigration
{
public override void Up()
{
Sql(@"
@philippwiddra
philippwiddra / Create or Alter View.sql
Created November 29, 2017 13:01
T-SQL Template to Create or Alter a View without loosing already configured metadata like authorization.
-- =============================================
-- Create or Alter View template
-- =============================================
USE <database_name, sysname, AdventureWorks>
GO
IF OBJECT_ID(N'[<schema_name, sysname, dbo>].[<view_name, sysname, Top10Sales>]', 'V') IS NULL
EXEC sp_executesql N'CREATE VIEW [<schema_name, sysname, dbo>].[<view_name, sysname, Top10Sales>] AS SELECT '''' as [x]'
GO
@philippwiddra
philippwiddra / TableColumnAnalysis.sql
Created March 19, 2018 16:05
Read Microsoft SQL Server Schema Information using T-SQL
SELECT t.[name] AS [Table],
c.[name] AS [Column],
ex1.[value] AS [Description],
CASE
WHEN ty.[name] IN ('geometry', 'geography') THEN ty.[name]
WHEN ty.[name] IN ('decimal', 'numeric') THEN ty.[name] + '(' + CAST(c.[precision] AS VARCHAR(10)) + ', ' + CAST(c.[scale] AS VARCHAR(10)) + ')'
WHEN ty.[max_length] = c.[max_length] THEN ty.[name]
WHEN c.[max_length] = -1 THEN ty.[name] + '(MAX)'
ELSE ty.[name] + '(' + CAST(c.[max_length] AS VARCHAR(10)) + ')'
END AS [Type],