Skip to content

Instantly share code, notes, and snippets.

@zippy1981
zippy1981 / Import-ParkAndRides.ps1
Created May 21, 2011 02:15
Powershell ETL of NYS Thruway park and rides into MongoDB
[string] $mongoDriverPath;
# Check to see if we are running the 64 bit version of Powershell.
# See http://stackoverflow.com/questions/2897569/visual-studio-deployment-project-error-when-writing-to-registry
if ([intptr]::size -eq 8) {
$mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.0").'(default)';
}
else {
$mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.0").'(default)';
}
@zippy1981
zippy1981 / database.properties
Created June 5, 2011 21:45
Example hibernate config files
#Updated at Sun Jun 05 14:55:40 EDT 2011
#Sun Jun 05 14:55:40 EDT 2011
database.password=postgres
database.url=jdbc\:postgresql\://localhost\:5432/myproject
database.username=postgres
database.driverClassName=org.postgresql.Driver
C:\Users\zippy>pathed /machine /remove 27
PATHED - Version 3.2
Freeware written by Gerson Kurz (http://p-nand-q.com)
00 C:\Program Files (x86)\PHP
01 C:\Windows\system32
<snip> . . . . . .</snip>
25 c:\Program Files\MongoDB\mongodb-win32-x86_64-1.8.1\bin
26 c:\Program Files (x86)\GnuWin32\bin
27 c:\Program Files\TortoiseHg
DROP TABLE etr;
GO
CREATE TABLE etr (
col_1 real NOT NULL,
col_2 real NOT NULL,
col_3 real NOT NULL,
col_4 real NOT NULL,
col_5 real NOT NULL,
col_6 real NOT NULL,
@zippy1981
zippy1981 / Get-Rows.ps1
Created September 7, 2011 20:07
Powershell script to demo Jorge's (@sqlchicken) Problem
$cn = New-Object System.Data.SqlClient.SqlConnection 'Data Source=.;Initial Catalog=master;Integrated Security=SSPI;';
$cn.Open();
$cmd = $cn.CreateCommand()
$cmd.CommandText="SELECT * FROM sys.tables"
$rdr = $cmd.ExecuteReader();
$dt = New-Object System.Data.DataTable;
$dt.Load($rdr);
$dt.Rows | Format-Table;
@zippy1981
zippy1981 / scratch.sql
Created September 8, 2011 21:29
Demonstrating CREATE DATABASE file case insensitivity to @grrl_geek
USE master;
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'dropMe')
DROP DATABASE [dropMe]
GO
CREATE DATABASE dropMe;
GO
DECLARE @fileName VARCHAR(MAX)
*** Assembly Binder Log Entry (9/23/2011 @ 10:19:11 PM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
--- A detailed error log follows.
=== Pre-bind state information ===
@zippy1981
zippy1981 / mstsc-Ac.ps1
Created January 7, 2012 21:21
Mstsc Autoconnect
<#
.SYNOPSIS
mstsc-Ac.ps1 (Version 1.0, 7 Jan 2012)
The author may be contacted via zippy1981@gmail.com
The latest authoritative version of this script is always available at
http://bit.ly/mstsc-Ac
.DESCRIPTION
This script will see if a host is up and listening on a given port, and start a
remote desktop connection to it. The idea is you run this script after rebooting a windows server
.EXAMPLE
@zippy1981
zippy1981 / integerDivision.test.ps1
Created January 10, 2012 03:33
Powershell [int][Math]::Floor($a/$b) versus [Math]::Floor([int]$a / [int]$b)
<#
In which I prove that that the terser [int][Math]::Floor($a/$b) gives the
same results as the technet recommended [Math]::Floor([int]$a / [int]$b)
Said technet recomendation is available at:
http://technet.microsoft.com/en-us/library/ee176879.aspx
One extra cast is probably slower too.
#>
1.. 1000 | ForEach-Object {
Foreach ($divisor in 2,3,5,7) {
@zippy1981
zippy1981 / Foreach-Scope.ps1
Created March 5, 2012 22:28
Illustrates Foreach-Object scope weirdness.
$script:filename = ""
1..100 | % {
$script:filename = "$($env:temp)\deleteme-$($_).txt"
"Code: $(Get-Random 4-9)-$($_)"
} | Set-Content $script:filename