Skip to content

Instantly share code, notes, and snippets.

View jstrassburg's full-sized avatar

JiM Strassburg jstrassburg

View GitHub Profile
@jstrassburg
jstrassburg / gist:4583405
Last active December 11, 2015 09:58
Python unittest Test Case
import unittest
class testSomething(unittest.TestCase):
def testSomethingSpecific(self):
self.assertTrue(True)
@jstrassburg
jstrassburg / PowerShell-Log.ps1
Last active August 29, 2015 13:56
Log PowerShell commands with Start-Transcript
$logFile = ".\MyLogFile.log"
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | Out-Null
$ErrorActionPreference = "Continue"
Start-Transcript -path $logFile
# Do Stuff
# If running commands with & some.exe pipe to Out-Default
& some.exe | Out-Default
@jstrassburg
jstrassburg / PowerShell-Params.ps1
Created February 26, 2014 16:33
Using required or optional with default parameters to PowerShell scripts
param (
[string]$requiredParam = $(throw "-requiredParam FOO|BAR is expected"),
[string]$optionalParam = "DefaultValue"
)
@jstrassburg
jstrassburg / PowerShellProxy.txt
Last active August 29, 2015 13:56
A simple proxy for launching a PowerShell script from the regular command prompt
@echo off
SET DIR=%~dp0%
@PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%MyScript.ps1' %*"
pause
@jstrassburg
jstrassburg / ReadPassword.cs
Created February 26, 2014 19:08
Read a password from the console in C#
public string GetPassword()
{
Console.Write("Enter password: ");
var password = new StringBuilder();
while (true)
{
var readKey = Console.ReadKey(true);
if (readKey.Key == ConsoleKey.Enter)
{
Console.Write("\n");
@jstrassburg
jstrassburg / ReadPassword.ps1
Created March 3, 2014 18:50
Read a password (***) from the console with PowerShell
$password = Read-Host -assecurestring "Please enter the password"
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
# Rename *.log files to be prefixed with YYYYmmdd- and upload to an S3 bucket
# Author: James Strassburg <[email protected]>
$bucketName = "myS3bucket"
$sourceLogs = "\\myfileserver\mylogdir"
$logFilter = "*.log"
$date = Get-Date -UFormat "%Y%m%d"
$bucket = Get-S3Bucket -BucketName $bucketName
if ($bucket -eq $null)
{
@jstrassburg
jstrassburg / jetty.xml
Last active March 27, 2020 18:10
Solr Jetty Authorization
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- only the relevant addition is listed here -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">MySolrRealm</Set>
<Set name="config">
@jstrassburg
jstrassburg / .vimrc
Last active August 29, 2015 13:57
My .vimrc
colorscheme koehler
set number
set ignorecase
set shiftwidth=4 softtabstop=4
set autoindent smartindent
set smarttab
set foldmethod=indent foldlevel=99
filetype indent plugin on
syntax on
map <F1> :!git status<ENTER>
@jstrassburg
jstrassburg / Arguments.cs
Created March 28, 2014 17:55
Parsing command line parameters C# using CmdLine
[CommandLineArguments(Program = "MyProgram", Title = "MyProgramTitle", Description = "My awesome program")]
internal class Arguments
{
[CommandLineParameter(Command = "?", Default = false, Description = "Show help", Name = "Help", IsHelp = true)]
public bool Help { get; set; }
[CommandLineParameter(Name = "requiredParameter", ParameterIndex = 1, Required = true,
Description = "This parameter is required")]
public string RequiredParameter { get; set; }