Skip to content

Instantly share code, notes, and snippets.

View josheinstein's full-sized avatar

Josh Einstein josheinstein

  • Einstein Technologies
  • USA
View GitHub Profile
@josheinstein
josheinstein / IPv4Block.cs
Last active December 27, 2015 08:09
Classes and extension methods that make it easy to work with blocks of IPv4 addresses in .NET.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
public sealed class DynamicMatch : DynamicObject
{
private readonly Regex _Regex;
private readonly Match _Match;
public DynamicMatch( Regex regex, Match match )
{
Contract.Requires( regex != null, "Regex cannot be null." );
@josheinstein
josheinstein / @Measure-Progress-Example.ps1
Last active December 22, 2015 18:09
A simple, drop-in replacement for ForEach-Object that automatically gathers up objects from the input pipeline and presents a progress bar as each item is processed by subsequent pipeline commands. Flexible options for presenting progress messages along with the progress bar.
Import-Module ActiveDirectory
# Get all of the computer names in active directory.
# Displays a progress bar as each computer is queried for
# the state of its hard drives using WMI.
# The Status parameter selects the computer name to display
# in the progress message.
Get-ADComputer -Filter * |
Measure-Progress -Status { $_.Name } {
@josheinstein
josheinstein / TransposeOilVendorData.vb
Created July 29, 2013 17:30
Transposes a contiguous range of selected cells in Excel and repeats the header rows.
' TRANSPOSEOILVENDORDATA.VB
' BY JOSH EINSTEIN
'
' This is an Excel VBA macro that transposes a contiguous range of selected cells in Excel
' and repeats the header rows. Created specifically for a friend of mine, so probably not
' generally useful.
' INSTRUCTIONS
' To use, select a rectangular range of cells containing the table that you want to transpose.
' The first row should include the header values across that you want to be repeated
@josheinstein
josheinstein / gist:5586469
Last active October 15, 2022 02:13
Handle back button issues with Twitter Bootstrap's tab component.
// Handle back button issues with Twitter Bootstrap's tab component.
// Based on: http://stackoverflow.com/a/10120221/81769
// It has been changed to avoid the following side effects:
// - Switching tabs was being added to navigation history which is undesirable
// (Worked around this by using location.replace instead of setting the hash property)
// - Browser scroll position was lost due to fragment navigation
// (Worked around this by converting #id values to #!id values before navigating.)
$(document).ready(function () {
if (location.hash.substr(0,2) == "#!") {
@josheinstein
josheinstein / WolframAlpha.psd1
Last active December 16, 2015 16:29
A PowerShell implementation of my Wolfram Alpha API search script. Unlike the Bash version, this one doesn't use XSLT to produce the output so it's easier to read.
# Module manifest for module 'WolframAlpha'
# Generated by: Josh Einstein
# Generated on: 4/25/2013
@{
RootModule = 'WolframAlpha.psm1'
ModuleVersion = '1.0'
GUID = 'bddce958-afa6-46d5-baa4-a277e0f9ccc1'
Author = 'Josh Einstein'
@josheinstein
josheinstein / wolf.sh
Last active July 4, 2022 19:40
Simple Wolfram Alpha queries from the Mac terminal. The XML parsing is incredibly basic (it just looks complicated because of the work needed to indent the lines to make it look good) so I haven't really tested it with any other results yet.
url="http://api.wolframalpha.com/v2/query"
appid="YOUR APP ID" # get one at https://developer.wolframalpha.com/portal/apisignup.html
query="$@"
value="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$query")"
echo "Computing: $query"
curl -s -L -G -d "input=$value&appid=$appid&format=plaintext" $url >/tmp/wolfram-alpha.xml
xsltproc ~/Scripts/wolf.xslt /tmp/wolfram-alpha.xml
@josheinstein
josheinstein / Disable-TemporaryRules.ps1
Last active December 16, 2015 01:30
Create temporary rules in Outlook by naming them with " (Until date)" or " (Until date time)" and then run this script at periodic intervals to disable those rules when they expire.
##############################################################################
#.SYNOPSIS
# Scans your Outlook rules (Outlook must be running) and disables any rules
# whose name matches a specific pattern such as:
# Move Stuff (Until 4/10/2013 5:00 PM)
# Ignore Stuff (Until 4/11/2013)
#
#.DESCRIPTION
#
# To create temporary rules in Outlook, just create rules as you would
@josheinstein
josheinstein / index.html
Created March 5, 2013 18:24
A CodePen by Josh Einstein. Keyboard Navigation in Table Cells - Uses jQuery to enable arrow key functionality in tables. Pressing up/down/left/right in input fields will move focus to adjacent cells. Doesn't currently deal with column spans or custom input scenarios such as on-the-fly input fields.
<table id="people">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Location</th>
</thead>
<tbody>
<tr>
<td><input /></td>
@josheinstein
josheinstein / New-PSObject.ps1
Created October 9, 2012 15:37
I wish PowerShell object literals worked like this...
# PowerShell 3 adds the new [PSCustomObject] pseudo type attribute which
# lets you declare an object literal using a syntax very similar to that
# of an ordinary Hashtable. (There's also a new [Ordered] attribute that
# creates a hash table with the order of keys preserved.)
#
# But it only lets you declare an object literal with NoteProperties.
# What I would really love to have seen is the syntax look for script
# blocks and create ScriptProperties out of them if there is no param
# block or ScriptMethods out of them if there is a param block.
#