Skip to content

Instantly share code, notes, and snippets.

View janbaer's full-sized avatar
🏠
Working from home

Jan Baer janbaer

🏠
Working from home
View GitHub Profile
@janbaer
janbaer / gist:4585893
Created January 21, 2013 13:05
GetAssemblyDirectory - Returns the directory name for the executing assembly
private static string GetAssemblyDirectory()
{
return new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory.FullName;
}
@janbaer
janbaer / gist:4690841
Created February 1, 2013 11:43
Thread.IsUIThread
public static class ThreadExtensions
{
public static bool IsUIThread(this Thread thread)
{
return SynchronizationContext.Current != null;
}
}
@janbaer
janbaer / gist:5045798
Created February 27, 2013 06:55
Convert CSV to Json with powershell
param
(
[string] $inputFile,
[string] $outputFile
)
if (($inputFile -eq $null) -or ($outputFile -eq $null)) {
"usage: convert_csv_to_json.ps1 [inputFile] [outputFile]"
return;
}
@janbaer
janbaer / gist:5276178
Created March 30, 2013 09:59
Restart your current powershell console as Administrator
function adminMode() {
Start-Process -FilePath "$PSHOME\powershell.exe" -Verb runas -WorkingDirectory $PWD.Path
Exit
}
Set-Alias -Name "elevated" -Value "adminMode"
@janbaer
janbaer / gist:5411748
Created April 18, 2013 10:30
Detect the active window in an WPF application
Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
@janbaer
janbaer / wpfdoevents.cs
Created April 18, 2013 10:40
DoEvents in Wpf applications
public static class WpfApplicationExtensions
{
public static void DoEvents(this Application application)
{
if (application != null)
{
application.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
}
}
}
@janbaer
janbaer / gist:5476117
Created April 28, 2013 06:36
Replace parts of the content of a textfile with regular expressions in Powershell
(Get-Content -path $inputFile) -Replace '"(\d+),(\d{1,})"', '$1.$2' -Replace '"(\d+)"'| Out-File $outputFile
@janbaer
janbaer / array_foreach
Last active December 17, 2015 19:29
Polyfill for missing forEach function an an Array object in JavaScript
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fn, scope) {
for (var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
}
@janbaer
janbaer / find_content_with_regex.ps1
Created June 20, 2013 09:46
Find a specific content of a file with a regular expression in powershell
cls
$path = 'd:\Git\sp'
$file = '*.csproj'
$regex = "^.*(?=Output).*\.dll</HintPath>"
Get-ChildItem -Path $path -Name $file -Recurse | where {(get-Content $_ | Select-String $regex)}
@janbaer
janbaer / request_password.ps1
Created June 26, 2013 08:53
Request a password with a masked password-dialog in powershell
$securestring = Read-Host -AsSecureString "Please enter your password"
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securestring))