Skip to content

Instantly share code, notes, and snippets.

@ivangeorgiev
ivangeorgiev / invoke_capture.py
Last active December 24, 2021 12:19
Python tasks with invoke
import invoke
import io
@invoke.task
def ls(ctx):
result = ctx.run("dir", hide="out")
lines = [line.strip() for line in io.StringIO(result.stdout) if not line.startswith(" ")]
filenames = [fn for *_, fn in [line.rsplit(" ", 1) for line in lines if line != ""]]
print("\n".join(filenames))
@ivangeorgiev
ivangeorgiev / basic_shell.py
Last active December 24, 2021 11:06
Python interactive shell with cmd module
import cmd
class BasicShell(cmd.Cmd):
"""Basic shell
To create interactive shell, subclass the cmd.Cmd class.
To start the shell, call the `cmdloop()` method, implemented in the base class.
"""
@ivangeorgiev
ivangeorgiev / AzureFunctions.ps1
Last active April 15, 2021 19:49
Azure Helper Functions
<#
.SYNOPSIS
The function returns an OAuth2 access token for the resource specified with URI.
.DESCRIPTION
Obtains and returns an OAuth2 access token for the resource specified with URI.
.OUTPUTS
Token object
#>
@ivangeorgiev
ivangeorgiev / is_databricks.py
Last active November 9, 2020 10:31
Detect if Python code is running in Datrabricks
def is_databricks():
'''Detect if Python code is running in Databricks'''
import os
return 'DATABRICKS_RUNTIME_VERSION' in os.environ
@ivangeorgiev
ivangeorgiev / Add-AzAdApplicationUserOwnerXYZ.ps1
Created September 24, 2020 17:47
Azure Active Directory (AD) With PowerShell
<#
.SYNOPSIS
Add Application Registration Owner
#>
function Add-AzAdApplicationUserOwnerXYZ($ApplicationName, $UserName) {
$ApplicationId = (Get-AzureADApplication -SearchString $ApplicationName).ObjectId
if (!$ApplicationId) { Throw "Unable to find application $ApplicationName" }
$UserId = (Get-AzureADUser -ObjectId $UserName).ObjectId
if (!$UserId) { Throw "Unable to find user $UserId" }
Add-AzureADApplicationOwner -ObjectId $ApplicationId -RefObjectId $UserId
@ivangeorgiev
ivangeorgiev / - SQL Server Snippets
Last active April 17, 2024 10:33
SQL Server Snippets
.
@ivangeorgiev
ivangeorgiev / hello-mars.ipynb
Created September 3, 2020 06:47
Hello-Mars
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivangeorgiev
ivangeorgiev / singleton-with-decorator.ipynb
Last active April 4, 2024 14:45
Python Singleton Class with Decorators
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivangeorgiev
ivangeorgiev / CountLinesInMultipleFiles.ipynb
Last active August 25, 2020 19:05
CountLinesInMultipleFiles.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivangeorgiev
ivangeorgiev / pipe.py
Last active August 24, 2020 22:31
Data pipelining in Python
import itertools
class Pipe:
def __init__(self, seq):
self._seq = seq
def __iter__(self):
return iter(self._seq)
def map(self, func):