Skip to content

Instantly share code, notes, and snippets.

@jpoehls
jpoehls / wrapper.bat
Last active January 16, 2023 22:37
Batch file wrapper for a PowerShell script. Wraps execution of a PowerShell script inside a Windows batch file.
@echo off
:: Execute the PS1 file with the same name as this batch file.
set filename=%~d0%~p0%~n0.ps1
if exist "%filename%" (
PowerShell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Unrestricted -Command "& '%filename%'"
:: Collect the exit code from the PowerShell script.
set err=%errorlevel%
@jpoehls
jpoehls / smtp-test.ps1
Created December 14, 2011 17:26
SMTP Test Script (in PowerShell)
$smtp = New-Object System.Net.Mail.SmtpClient
$smtp.Host = "127.0.0.1"
$smtp.Port = 587
$creds = New-Object System.Net.NetworkCredential
# $currentCreds = Get-Credential
$creds.Domain = ""
$creds.UserName = "my_user" # $currentCreds.UserName
$creds.Password = "my_pass" # $currentCreds.GetNetworkCredential()
@jpoehls
jpoehls / Elevate-Process.ps1
Created December 14, 2011 20:34
Elevate-Process (sudo) for PowerShell
# Put this in your PowerShell profile.
function Elevate-Process
{
<#
.SYNOPSIS
Runs a process as administrator. Stolen from http://weestro.blogspot.com/2009/08/sudo-for-powershell.html.
#>
$file, [string]$arguments = $args
$psi = New-Object System.Diagnostics.ProcessStartInfo $file
@jpoehls
jpoehls / main.js
Created February 17, 2012 16:33
Benchmark.js deferred
var Benchmark = require('benchmark');
var request = require('request');
var suite = new Benchmark.Suite;
// add tests
suite.add('Calling cow api', {
defer: true,
fn: function(deferred) {
request({
@jpoehls
jpoehls / fibonacci.hs
Created February 27, 2012 19:07
Fibonacci Haskell
-- seen here: http://academicearth.org/lectures/introduction-to-haskell (@ ~14m)
-- returns an infinite fibonacci sequence
fib = 1:1:zipWith (+) fib (tail fib)
@jpoehls
jpoehls / gist:2030795
Created March 13, 2012 19:02
Using CTRL+W to close tabs in Visual Studio

In Tools | Options | Keyboard...

  1. Add CTRL+W as a Global shortcut for Window.CloseDocumentWindow
  2. Remove the CTRL+W shortcut for Edit.SelectCurrentWord

The caveat to this is if you are used to using CTRL+W to select the current word. If you do, find another shortcut that works for that.

@jpoehls
jpoehls / ios_6_wishlist.md
Created March 21, 2012 17:19
iOS 6 Wish List

Not necessarily in order of preference.

  1. Picture lock, ala Windows 8. Not face recognition, the photo password thing.
  2. Ability for apps to plug into Spotlight. Ex. Search my Evernote from Spotlight.
  3. More app integration points like "Open With". Allow any app to register itself as a "photo provider" (fb, flickr) or "share provider" (twitter, fb). Instead of importing photos from the camera roll, allow import from any photo provider, of which the camera roll is just one of many. Android has this as well as Windows Phone 7 and Windows 8.

The photos example is one of the best, but also imagine a more generic "document provider". I'm in a text editing app like Byword and choose to "open document", I see a list of apps that provide documents. In that list is Dropbox. I open the file. Document providers are 2-way, so as I make changes to my document in Byword it is saving back to Dropbox. Byword doesn't have to do anything special to implement this. The Dropbox app, as provider, handles all

@jpoehls
jpoehls / output.txt
Created March 26, 2012 16:48
PowerShell benchmarking function. Or, the Windows equivalent of Unix's `time` command.
PS> time { ping -n 1 google.com } -Samples 10 -Silent
..........
Avg: 62.1674ms
Min: 56.9945ms
Max: 87.9602ms
PS> time { ping -n 1 google.com } -Samples 10 -Silent -Long
..........
Avg: 00:00:00.0612480
Min: 00:00:00.0572167
@jpoehls
jpoehls / get_modelstate_errors.cs
Created March 28, 2012 20:30
Get dictionary of errors from ModelState in ASP.NET MVC
var errorList = ModelState
.Where(x => x.Value.Errors.Count > 0)
.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
);
@jpoehls
jpoehls / node-cluster-messaging.js
Created March 29, 2012 01:48
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.