Skip to content

Instantly share code, notes, and snippets.

View seantunwin's full-sized avatar

Sean T. Unwin seantunwin

View GitHub Profile
@seantunwin
seantunwin / pagebreak.md
Last active June 26, 2019 18:01
Markdown: Insert page break
@seantunwin
seantunwin / host-by-ip-and-back.ps
Last active June 26, 2019 15:07
Powershell: ComputerName By IP and vice-versa
### Source: https://www.morgantechspace.com/2015/06/powershell-find-machine-name-from-ip-address.html
## Get Computer Name from IP
# Set the known IP Address (variable not required)
# NOTE: MUST be enclosed in quotes
$ipAddress= "192.168.1.54"
[System.Net.Dns]::GetHostByAddress($ipAddress).Hostname
## Get IP from Computer Name
# Set the known computer name (variable not required)
# NOTE: MUST be enclosed in quotes
@seantunwin
seantunwin / get-table-column-names-and-count.sql
Created February 7, 2019 15:00
MSSQL: Get Table Coumns Names and Column Count
-- Get Column Name from a table
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @table;
-- Get total number of Columns
SELECT COUNT(*) FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @table;
@seantunwin
seantunwin / list-linked-servers.sql
Created February 7, 2019 14:58
MSSQL: List Linked Servers
EXEC sys.sp_linkedservers
@seantunwin
seantunwin / decode-ssl-cert.sh
Created February 7, 2019 14:57
SSL: Decode Certificate
openssl x509 -in CERT_NAME -text -noout
@seantunwin
seantunwin / rows-with-duplicate-column-values.sql
Created February 7, 2019 14:56
MSSQL: Rows with Duplicate Column Values
SELECT * FROM @table
WHERE
@column IN (
SELECT @column FROM @table
GROUP BY @column HAVING COUNT(*) > 1)
@seantunwin
seantunwin / substring-before-character.sql
Created February 7, 2019 14:56
MSSQL: Substring Before Specific Character
LEFT(@column, IIF(CHARINDEX('@needle', @column) > 0, CHARINDEX(@needle, @column) - 1, LEN(@column)))
@seantunwin
seantunwin / get-range-of-rows.sql
Created February 7, 2019 14:54
MSSQL: Get Range of Rows
SELECT
ROW_NUMBER() OVER (ORDER BY @id) AS num
[, columns]
FROM @table
WHERE
@id BETWEEN @start AND @end
ORDER BY @id
@seantunwin
seantunwin / md-array-search.php
Last active August 20, 2018 20:29
PHP: Search multi-dimensional array for specific key value and return another key's value from the same sub-array
<?php
// Multi-dimensional Array to search through
$a = [
[
'item' => 1,
'code' => 100
],
[
'item' => 2,
'code' => 200
@seantunwin
seantunwin / verify-unique-file-name.php
Last active July 6, 2018 15:49
PHP: Check if file name exists in directory
public function verifyUniqueFileName($fileName, $pathToCheck, $fileExtension)
{
// Check for upper and lower case file extension
$extensionsBrace = "{" . $fileExtension . "," . strtoupper($fileExtension) . "}";
// Require GLOB_BRACE for linux style multi-glob
$filesCollection = glob($pathToCheck . "*" . $extensionsBrace, GLOB_BRACE);
$files = array_map(function($item) {
// Get the tail of the path URI
return substr($item, strrpos($item, '/') + 1);