Skip to content

Instantly share code, notes, and snippets.

View sandorjanssen's full-sized avatar

Sandor Janssen sandorjanssen

View GitHub Profile
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
Or:
$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.Proxy.Address = "http://proxyurl"
@sandorjanssen
sandorjanssen / kill-orphaned-connections.sql
Created April 5, 2018 14:05
Kill orphaned connections
DECLARE @SQL AS VARCHAR(255)
DECLARE @SPID AS SMALLINT
DECLARE @Loginname AS VARCHAR(500)
DECLARE @HoursSinceLastBatch AS SMALLINT = 4
SET @Loginname = '<<Loginname>>'
DECLARE Murderer CURSOR FOR
SELECT spid FROM sys.sysprocesses WHERE loginame = @Loginname AND last_batch < DATEADD(HOUR, -1 * @HoursSinceLastBatch, GETDATE()) AND [status] = 'sleeping' ORDER BY last_batch DESC
OPEN Murderer
@sandorjanssen
sandorjanssen / magic.ps1
Created July 13, 2017 13:36
Get filenames from files in serveral subfolders that have a specific range for the LastWriteTime property
# Get filenames from files in serveral subfolders that have a specific range for the LastWriteTime property
$path = "FileSystem::\\path\to\files\**\in\several\subfolders"
$start = Get-Date -Date "2017-06-27"
$end = $start.AddDays(1)
Get-ChildItem -Path $path -Recurse | `
Where-Object { $_.LastWriteTime -ge $start -and $_.LastWriteTime -le $end } | `
Select-Object { $_.Name }
@sandorjanssen
sandorjanssen / windows-startup-folders
Created June 30, 2015 09:56
Open startup folder in windows (user or common)
#Open startup folder in windows (user or common)
##User
- Run (WinKey+R)
- shell:Startup
##Common
- Run (WinKey + R)
- shell:Common Startup
@sandorjanssen
sandorjanssen / Delete obj and bin folders recusive
Last active April 7, 2017 12:16
Delete obj and bin folders recusive
Get-ChildItem .\ -Include bin,obj -Recurse -Force | Remove-Item -Force -Recurse
@sandorjanssen
sandorjanssen / powershell-profile
Created July 15, 2014 08:42
Powershell profile (edit using vim $profile) incl. .NET, Visual Studio, Azure, etc. tools
$env:path = $env:path + ";C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
$env:path = $env:path + ";C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE"
$env:path = $env:path + ";C:\Program Files (x86)\Vim\vim73"
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
& 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat' x86
# Change the prompt to show only the current folder using a different color
function prompt {
$p = Split-Path -leaf -path (Get-Location)
Write-Host "$p> " -nonewline -foregroundcolor Green
@sandorjanssen
sandorjanssen / Node.js webserver for serving static files
Last active December 25, 2015 16:19
Node.js webserver for serving static files (run npm install connect first)
var connect = require('connect');
connect.createServer(
connect.static(__dirname)
).listen(8080);
@sandorjanssen
sandorjanssen / html5-template-semantic-tags
Created August 14, 2013 14:00
Basic HTML5 template using semantic tags
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<header>Header</header>
<nav>
<a href="#">Home</a>
@sandorjanssen
sandorjanssen / colored-current-folder-prompt
Last active December 21, 2015 01:39
Change the prompt to show only the current folder using a different color (add to $profile using vim $profile)
function prompt {
$p = Split-Path -leaf -path (Get-Location)
Write-Host "$p> " -nonewline -foregroundcolor Green
return ' '
}