Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Comparer
{
public class SemiNumericComparer : IComparer<string>
{
public int Compare(string s1, string s2)
@bungard
bungard / SplitWordDoc.ps1
Last active February 1, 2022 10:27
Powershell script to split a word document into separate pages. Assumes each page should be its own document and the name for each document can be extracted from each page.
#Author: Matt Bungard / bungard at g-mail d com
#
#Pull bits from various sources, if you've been exluded let me know and I'll cite accordingly
#http://stackoverflow.com/questions/26737239/powershell-add-a-new-document-to-exisitng-word-file-with-page-number-of-2
## -- Settings --
#$fileNamePattern = "ID #:\s+(\d+)"
$fileNamePattern = "Student ID #:\s+# (\d+)"
$pageLength = 1
@bungard
bungard / SqlEscape.cs
Last active September 16, 2015 00:45
private static void SQLServerEscapeObject(object obj)
{
foreach (System.Reflection.PropertyInfo property in obj.GetType().GetProperties())
{
try
{
if (property.PropertyType.FullName == "System.String" && property.GetValue(obj, null) != null)
{
property.SetValue(obj, property.GetValue(obj, null).ToString().Replace("'", "''"), null);
}
Application Error:
Application: Plex.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
Stack:
at System.Environment.FailFast(System.String, System.Exception)
at Plex.App+<FlushBugSenseAndFailFastAsync>d__47.MoveNext()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
//As pulled from: http://support.microsoft.com/kb/306158
static private bool impersonateValidUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
$query_select = "select lead.id ";
$query_from = "";
$query_where = " where lead.form_id = $form_id";
$query_order = "";
if(!empty($orderby_field))
$query_order = " ORDER BY " . preg_replace("([^0-9A-Za-z_])","",$orderby_field[0]["label"]) . ".value desc ";
$query_from .= " from wp_rg_lead lead
INNER JOIN wp_rg_lead_detail approval on lead.form_id = approval.form_id and lead.id = approval.lead_id
@bungard
bungard / WP-clean.sh
Created February 19, 2015 00:12
Shell script to try and detect and clean common WP infections
grep -lr --include \*.php --exclude \*id3v2.php "%x[0-9]" . | tee infected-files.txt
while read -r filename ; do
cp -v "$filename" "$filename.dirty"
sed -i "s/<?php \$\w\+ = '.*%x[0-9].*?>//g" "$filename"
done < infected-files.txt
cp $1 $1.oldKey
AUTH_KEY=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'AUTH_KEY'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
SECURE_AUTH_KEY=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'SECURE_AUTH_KEY'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
LOGGED_IN_KEY=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'LOGGED_IN_KEY'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
NONCE_KEY=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'NONCE_KEY'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
AUTH_SALT=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'AUTH_SALT'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
SECURE_AUTH_SALT=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/ | grep "'SECURE_AUTH_SALT'" | sed 's/[^-A-Za-z0-9_]/\\&/g')
require 'rails/commands/server'
require 'socket'
module Rails
class Server
alias :default_options_alias :default_options
def default_options
ip_addr_list = Socket.ip_address_list
#puts ip_addr_list.inspect
if ip_addr_list.count >= 2
function parseExcel{
param(
[string] $strFileName = $(throw "Please specify an excel file to parse."),
[string] $strSheetName = 'Sheet1$',
[string] $callListId = $(throw "Please specify a callListId.")
)
$strProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
$strDataSource = "Data Source = $strFileName"
$strExtend = "Extended Properties=Excel 8.0"
$strQuery = "Select * from [$strSheetName]"