Skip to content

Instantly share code, notes, and snippets.

View nvarscar's full-sized avatar

Kirill Kravtsov nvarscar

  • Victoria, BC
View GitHub Profile
@nvarscar
nvarscar / conf.py
Created June 23, 2021 17:20
Sphinx Confluence config
# activating extensions
extensions = ["sphinxcontrib.napoleon", "sphinxcontrib.confluencebuilder"]
# supported source file types
source_suffix = [".rst"]
# Confluence general configuration
confluence_publish = True
confluence_server_url = "https://<server name here>.atlassian.net/wiki/"
# Confluence credentials are retrieved from environment variables in this example
@nvarscar
nvarscar / conf.py
Created June 23, 2021 17:19
Sphinx general config
project = "mymodulename"
copyright = "<license>"
author = "<Your name here>"
release = "<version string if you need it>"
@nvarscar
nvarscar / conf.py
Created June 23, 2021 17:17
Sphinx import
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
import mymodulename
@nvarscar
nvarscar / class.py
Created June 23, 2021 17:14
Docstring example
class MyClass(object):
"""Short description here.
Args:
input (str): first argument here
num (int): some other arg
Attributes:
attribute (str): Attribute description
num (int): some other attribute
class testclass {
[string]$foo
testclass($input) {
$this.foo = $input
}
}
enum testenum {
foo
bar
}
@nvarscar
nvarscar / clone_login_permissions.ps1
Created January 17, 2020 21:38
Clone login and apply permissions
Param (
$SourceServer,
$TargetServer,
$Login
)
$loginObject = Get-DbaLogin -SqlInstance $SourceServer -Login $Login
Copy-DbaLogin -Destination $TargetServer -Login $loginObject
foreach ($dbName in $login.EnumDatabaseMappings()) {
$db = Get-DbaDatabase -SqlInstance $SourceServer -Database $dbName
@nvarscar
nvarscar / clone_user_permissions.ps1
Created January 17, 2020 21:21
Clone user permissions with dbatools
Param (
$SourceServer,
$TargetServer,
$SourceDatabase,
$TargetDatabase
)
$permissions = Export-DbaUser -SqlInstance $SourceServer -Database $SourceDatabase
Invoke-DbaQuery -SqlInstance $TargetServer -Database $TargetDatabase -Query $permissions
@nvarscar
nvarscar / prompt.ps1
Created February 15, 2019 18:14
prompt function for Powershell
function Prompt {
try {
$history = Get-History -ErrorAction Ignore -Count 1
if ($history) {
$ts = New-TimeSpan $history.StartExecutionTime $history.EndExecutionTime
switch ($ts) {
{$_.TotalMinutes -ge 1 } {
'[{0,5:f1} m]' -f $_.TotalMinutes | Write-Host -ForegroundColor Red -NoNewline
}
{$_.TotalMinutes -lt 1 -and $_.TotalSeconds -ge 1} {
# install a DBOps package to the MySQL server
Install-DBOPackage -Type MySQL -Server localhost -Database mydb -Path .\package.zip
# invoke a query against a remote PostgreSQL server
Invoke-DBOQuery -Type PostgreSQL -SqlInstance pgsql1:5432 -Database mydb -Query 'SELECT current_database();'
# change the default connection -Type (SQLServer) to PostgreSQL:
Set-DBODefaultSetting -Name rdbms.type -Value 'PostgreSQL'
@nvarscar
nvarscar / examples_invoke-dboquery.ps1
Last active January 24, 2019 17:52
Examples for Invoke-DBOQuery
# Get current database from a PostgreSQL server
Invoke-DBOQuery -Type PostgreSQL -Server localhost:5432 -Database postgres -Query 'SELECT current_database()' -As SingleValue
# Run a query against MySQL database
Invoke-DBOQuery -Type MySQL -Server localhost -Database mysql -Query 'SELECT Name from Users'
# Run multiple files from a folder in a specific SQL Server database
Get-ChildItem .\Scripts | Invoke-DBOQuery -SqlInstance 'SqlServer1:1443' -Database MyDB
# Connect to an Oracle database interactively as SYSDBA