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 / Module104-Table244.c
Created August 15, 2016 22:15
Excerpted from MetaSwitch BAFView.
/***************************************************************************/
/* BAF_F_244_TRUNK_IDENTIFICATION */
/***************************************************************************/
{
NULL,
"Trunk Identification",
10,
3,
{
{
@josheinstein
josheinstein / ModuleCodeLengths.cs
Last active June 8, 2016 18:39
Bellcore AMA Format - Module Code Lengths
// Creates a table of known BAF module codes and their corresponding
// length, in bytes, including the module code itself. (i.e. module
// code 000 contains only the module code, and thus is 2 bytes - 0x000C)
// This is required when implementing a BAF parser, even if it only
// intends to support a subset of the module codes, because there is
// no way to determine the length of a module to even skip over it.
ModuleLengths = new Dictionary<int, int>( );
ModuleLengths[0x000C] = 2; // MODULE 000 - TRAILER
@josheinstein
josheinstein / Get-ModuleConflict.ps1
Created January 28, 2016 21:32
Checks a set of modules for conflicting command names.
<#
.SYNOPSIS
Checks the exported commands in a set of modules looking for commands
that have naming conflicts.
.DESCRIPTION
When two modules export commands with the same name, there can be
unpredictable results when the unqualified name of the module is
used in scripts.
@josheinstein
josheinstein / TextWrapping.psm1
Created January 25, 2016 23:50
Text wrapping module for PowerShell
#.SYNOPSIS
# Takes one or more lines of text that were produced by a text-wrapping algorithm
# and attempts to 'unwrap' them so that the line breaks that were added are removed.
#
#.DESCRIPTION
# Unwrapping text is an error-prone process, because it is impossible to know for sure
# whether or not a hard line break was intentional or added as a result of word-wrapping.
# This function makes several assumptions about wrapped text. For example, if there are
# spaces at the end of a line and the following line is not blank, it is assumed that the
# line was wrapped. If there is a space on a blank line, it is assumed that the line
@josheinstein
josheinstein / flushdns.sh
Last active January 13, 2016 16:22
Flushes the DNS cache in all recent versions of OSX. I'm not a Bash guy so this is probably sloppy.
# Adapted from the following post:
# How to Flush DNS Cache in Mac OS X
# http://osxdaily.com/2008/03/21/how-to-flush-your-dns-cache-in-mac-os-x/
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." 1>&2
exit 1
fi
OSVERSION=$(sw_vers -productVersion)
@josheinstein
josheinstein / translations.php
Created October 8, 2015 21:53
WARNING -- I made this quick patch because my Brandoo MSSQL Wordpress installation got hosed when my site auto upgraded to 4.2.2. Brandoo no longer supports or updates their abstraction layer, so I, and many others, are SOL. However, making this change to translations.php I was able to log into the dashboard. Everything mostly works, but do your…
<?php
// In /wp-content/mu-plugins/wp-db-abstraction/translations/sqlsrv/translations.php,
// search for the lines that read:
//
// // SHOW COLUMNS
// if ( stripos($query, 'SHOW COLUMNS FROM ') === 0 ) {
// $end_pos = strlen($query);
// $param = substr($query, 18, $end_pos - 18);
// $param = "'". trim($param, "'") . "'";
// $query = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ' . $param;
@josheinstein
josheinstein / SurfacePenTweaks.ahk
Last active September 21, 2015 16:20
Disable Surface Touch Screen with Pen Button - At startup, ensures that the touch screen is enabled. When the Surface pen button is double clicked (sends F19 key) the script toggles the touch screen on and off. On exit, touch screen is re-enabled. In order to avoid UAC prompts on devmanview, this should be started with elevated permissions.
#NoEnv
#SingleInstance, Ignore
SendMode Input
SetWorkingDir C:\Users\jeinstein\Dropbox\Tools\DevManView\x64
OnExit, Cleanup
IsTouchEnabled = 1
@josheinstein
josheinstein / RegexExamples.sql
Last active March 30, 2021 19:40
Sure, lots of SQLCLR examples show you how to use .NET Regex to test if a string matches a pattern. But these functions will let you get a list of matches, replace substrings, capture named groups, split strings, and more. (Note that this is not a complete and buildable solution. There's plenty of info out there about creating a SQLCLR project i…
-- Produces a table of matches within the string, along with the
-- character position and length of the matches.
SELECT * FROM Utils.RegexMatches('There are 10 people in 5 groups of 2.', '\d+');
-- Produces a table of all the matched group expressions within the
-- string, along with the character position and length of the substrings.
SELECT * FROM Utils.RegexGroups('someone@somewhere.org', '^(?<user>[^@]+)@(?<domain>.*)$');
@josheinstein
josheinstein / Export-Excel.ps1
Created May 12, 2015 16:37
Exports PowerShell objects from the pipeline to an Excel spreadsheet by saving it to an HTML table, launching Excel using the COM object model, and applying formats and hidden columns as necessary.
#.SYNOPSIS
# Exports objects to an Excel spreadsheet by writing them to a temporary
# CSV file and using Excel automation model to import it into a workbook.
# This allows formatting to be applied to columns which would not otherwise
# be possible in a plain CSV export.
function Export-Excel {
[CmdletBinding()]
param(
@josheinstein
josheinstein / AzureTableBatchHelper.cs
Last active August 29, 2015 14:19
When doing batch operations in Azure tables, you gotta be sure all entities are in the same partition. Here's some helpful, generally useful code for taking any IEnumerable of table entities and turning it into an IEnumerable of BATCHES of table entities. Nerd boner!
internal static class ExtensionMethods
{
/// <summary>
/// The largest batch size allowed by Azure table storage.
/// </summary>
public const int MaxBatchSize = 100;
/// <summary>
/// Given a sequence of <see cref="ITableEntity"/> objects, returns them in batches of up to 100 entities