Skip to content

Instantly share code, notes, and snippets.

View brazilnut2000's full-sized avatar

Jon Crowell brazilnut2000

View GitHub Profile
@brazilnut2000
brazilnut2000 / Dapper Scalar Query.cs
Created August 17, 2015 20:46
Dapper: Execute Scalar query
int value = conn.Query<int>(sql, args).Single();
string value = conn.Query<string>(sql, args).Single();
http://stackoverflow.com/questions/8050636/is-there-an-executescalar-in-dapper
@brazilnut2000
brazilnut2000 / GlobalAutohotkey.ahk
Last active September 28, 2015 15:42
AHK: Default autohotkey script. This should grow substantially over time as I begin to use autohotkey more.
; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments. They are not executed.
; This script has a special filename and path because it is automatically
; launched when you run the program directly. Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it. You can have as many .ahk
; files as you want, located in any folder. You can also run more than
; one .ahk file simultaneously and each will get its own tray icon.
@brazilnut2000
brazilnut2000 / Powershell add Active Directory Module.ps1
Last active August 8, 2022 15:08
How to install the AD Module for Powershell
#How to install the Active Directory module for Powershell
#Source: https://blogs.technet.microsoft.com/ashleymcglone/2016/02/26/install-the-active-directory-powershell-module-on-windows-10/
# Download the script referenced in the post and follow the directions
@brazilnut2000
brazilnut2000 / PsBackupSqlServer.ps1
Created March 22, 2016 22:58
Back up a SQL Server database, regardless of version (certain versions don't support scheduled backups via SSMS)
$instanceName = "[db instance name goes here]"
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
$databasename = "[db name goes here]"
$timestamp = Get-Date -Format yyyyMMddHHmmss
$backupfolder = "[full path to backup folder]"
$backupfile = "$($databasename)_Full_$($timestamp).bak"
$fullBackupFile = Join-Path $backupfolder $backupfile
Backup-SqlDatabase `
@brazilnut2000
brazilnut2000 / SQL:RestoreAndRenameFromBackup.sql
Created March 31, 2017 21:11
Create a copy of a database by restoring and renaming from a backup
-- SOURCE: http://stackoverflow.com/questions/6267273/how-to-restore-to-a-different-database-in-sql-server
-- Get the files, note the logical names of the .mdf and .ldf files
restore filelistonly from disk='E:\MSSQL\Backup\NewProjectExplorer\NewProjectExplorer_20170330.bak'
-- Restore and rename the backup
restore database [NewName] from disk = 'E:\MSSQL\Backup\NewProjectExplorer\NewProjectExplorer_20170330.bak'
with
move '[LogicalNameForMdf]' to 'E:\MSSQL\[NewName].mdf',
move '[LogicalNameForLdf]' to 'E:\MSSQL\[NewName]_log.ldf'
@brazilnut2000
brazilnut2000 / SQL: convert extended events file into table.sql
Created May 26, 2017 19:09
Convert an Extended Events .xel file into a queryable table in SQL Server
-- convert all .xel files in a given folder to a single-column table
-- (alternatively specify an individual file explicitly)
select event_data = convert(xml, event_data)
into #eeTable
from sys.fn_xe_file_target_read_file(N'd:\killme\extended events\*.xel', null, null, null);
-- select from the table
select * from #eeTable
-- and click on a hyperlink value to see the structure of the xml
@brazilnut2000
brazilnut2000 / random number.js
Created February 1, 2018 22:50
Get a random number between 0 and whatever upper-range you specify
function randomNumber(range) {
return Math.round(Math.random() * range);
}
// Usage:
console.log(`This is a random number from 0 to 20: ${randomNumber(20)}`);
@brazilnut2000
brazilnut2000 / backupsqlserverwithpowershell.ps1
Created April 11, 2018 18:35
Backup SQL Server Database with Powershell
# Install SQL Server PowerShell module
# https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module
Install-Module -Name SqlServer
# Backing Up SQL Server Databases is Easier in PowerShell than T-SQL
# http://www.sqlservercentral.com/articles/PowerShell/151510/
Get-SqlDatabase -ServerInstance [SERVERNAME]\SQLEXPRESS |
Where { $_.Name -eq '[DATABASENAME]' } |
Backup-SqlDatabase -BackupFile "c:\temp\[FILE PREFIX]$(Get-Date -UFormat %Y%m%d_%H%M).bak" -Script
@brazilnut2000
brazilnut2000 / .block
Created May 8, 2018 03:34
Morphing Curve: Radial Gradient
license: gpl-3.0
@brazilnut2000
brazilnut2000 / .block
Created May 8, 2018 03:36
Brushable Horizontal Bar Chart - I
height: 540