Skip to content

Instantly share code, notes, and snippets.

View constructor-igor's full-sized avatar

Igor Ziselman constructor-igor

View GitHub Profile
@constructor-igor
constructor-igor / nested-brackets
Created April 22, 2015 12:55
parsing nested parentheses in python, grab content by level
#http://stackoverflow.com/questions/4284991/parsing-nested-parentheses-in-python-grab-content-by-level
def parenthetic_contents(string):
"""Generate parenthesized contents in string as pairs (level, contents)."""
stack = []
for i, c in enumerate(string):
if c == '(':
stack.append(i)
elif c == ')' and stack:
start = stack.pop()
yield (len(stack), string[start + 1: i])
@constructor-igor
constructor-igor / powershell-list-of-all-entries-from-Outlook-GAL
Last active January 12, 2022 23:32
Powershell: list of all entries from Outlook Global Address List (GAL)
[Microsoft.Office.Interop.Outlook.Application] $outlook = New-Object -ComObject Outlook.Application
$entries = $outlook.Session.GetGlobalAddressList().AddressEntries
$count = $entries.Count
$count
foreach($entry in $entries)
{
[console]::WriteLine("{0}: {1}", $entry.Name, $entry.GetExchangeUser().MobileTelephoneNumber)
}
@constructor-igor
constructor-igor / UnhandledException.cs
Created December 27, 2016 09:26
UnhandledException in WPF
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var ex = e.Exception;
string message = ex.NameAndMessage();
string details = ex.GetDetailedMessage();
@constructor-igor
constructor-igor / powershell-send-email-via-Outlook-and-insert-image-to-body
Last active September 5, 2018 17:55
Powershell: send email via Outlook and insert image to body
function SendEmailWithEmbeddedImage([String] $to, [String] $subject, [String] $body, [String] $attachment, [String] $imageFile)
{
#$htmlHeader = "<HEAD>Text<B>BOLD</B> <span style='color:#E36C0A'>Color Text</span></HEAD>"
$htmlText = "<HTML>{0}</HTML><img src='cid:{1}'>"
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $to #"boss@company.com"
$Mail.Subject = $subject
$Mail.HTMLBody = [string]::Format($htmlText, $body, ExtractFileName $imageFile)
@constructor-igor
constructor-igor / powershell-list-of-all-outlook-contacts
Created November 27, 2014 12:59
Powershell: list of all Outlook contacts
$Outlook=NEW-OBJECT –comobject Outlook.Application
$Contacts=$Outlook.session.GetDefaultFolder(10).items
$Contacts | Format-Table FullName,MobileTelephoneNumber
function obj = LoadNetDll()
dllPath = '<full path to folder with .NET dll>\';
if isdir(dllPath)
dllPath = fullfile(dllPath,'<.NET dll name>.dll');
end
a = NET.addAssembly(dllPath);
@constructor-igor
constructor-igor / AssemblyDirectory
Created October 24, 2016 21:40
AssemblyDirectory
//
// http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in
//
private static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
@constructor-igor
constructor-igor / Send email (outlook) from cake
Created October 16, 2016 08:52
Sending email (Outlook) from cake script.
#addin "Microsoft.Office.Interop.Outlook"
using Outlook = Microsoft.Office.Interop.Outlook;
// ...
Task("Send-email")
.Does(()=>
{
//https://msdn.microsoft.com/en-us/library/office/bb644320.aspx
var reportFilePath = MakeAbsolute(File("testReport.html")).ToString();
@constructor-igor
constructor-igor / powershell-embed-2-images-to-Outlook-emails-body
Created November 26, 2014 15:34
Powershell: embed 2 images to Outlook emails body
function SendEmailWithEmbeddedImages([String] $to, [String] $subject, [String] $body, [String] $attachment, [array] $imageFiles)
{
$htmlText = "<HTML>{0}</HTML>"
foreach ($imageFile in $imageFiles) {
$fileName = ExtractFileName $imageFile
$imageTag = [string]::Format("<img src='cid:{0}'>", $fileName)
$htmlText = $htmlText + $imageTag
}
$Outlook = New-Object -ComObject Outlook.Application
PM> $Mail = $Outlook.CreateItem(0)
PM> $Mail.to = "<email>"
PM> $Mail.Body = $dte.Debugger.CurrentStackFrame.Locals | ForEach-Object {$_.Name, $_.Type}
PM> $Mail.Send()