Skip to content

Instantly share code, notes, and snippets.

@jabez007
jabez007 / NuGetODataController.cs
Last active March 21, 2018 20:41
Extend NuGet.Server to search Global Repo when it fails to find a package locally
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
@jabez007
jabez007 / ElmahErrorLogger.cs
Last active March 9, 2018 18:32
Using ELMAH for error logging on a NuGet.Server
using Elmah;
using System.Web;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
namespace LocalNuGet.Elmah
{
class ElmahErrorLogger : DelegatingHandler
{
@jabez007
jabez007 / States.cs
Created February 27, 2018 21:17
C# enum for US States
using System.ComponentModel;
namespace StateAbbreviations
{
public enum States
{
[Description("Alabama")]
AL,
[Description("Alaska")]
AK,
@jabez007
jabez007 / pip_upgrade_all.py
Created February 16, 2018 03:03
A Python script to upgrade all installed libraries
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
print dist.project_name
ret = call('pip install --upgrade ' + dist.project_name)
#if ret != 0:
#if ret < 0:
#print " Killed by Signal: ",ret
#else:
@jabez007
jabez007 / Read-ApacheLogs.sh
Created February 12, 2018 15:39
A Bash script to do some basic analysis on Apache access logs
#!/bin/bash
####
# reads an Apache access log with the following fields
# "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
####
# Set the internal field separator
IFS=$'\n'
@jabez007
jabez007 / Monitor-PublicIP.sh
Created February 12, 2018 15:36
Monitors your public IP address and removes your default gateway if it doesn't like what it finds
#!/bin/bash
ADDRESS="69.65.44.96" # default for my public IP now
PAUSE=1 # default to 1 second for now
# Get command line arguments
# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
# argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.
# some arguments don't have a corresponding value to go with it).
@jabez007
jabez007 / Enable-ClientCertNegotiation.ps1
Created February 12, 2018 15:30
A PowerShell Script for enabling client certifcate negotiation on Windows Server 2008 and 2012 while not presenting a trusted issuers list
param (
[string]$ipPort = "0.0.0.0:443"
)
# Make sure we are running as Admin
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
@jabez007
jabez007 / Export-ClientCertificates.ps1
Created February 12, 2018 15:28
A PowerShell script to mass export client certificates from a server
param(
[Parameter(Mandatory = $true)]
[String[]]$Thumbprints,
[Parameter(Mandatory = $true)]
[String]$Password
)
#### Usage ####
# .\Export-ClientCertificates.ps1 -Thumbprints "array","of","thumbprints","and","subject","common","names" -Password "PrivateKeyPassword"
####
@jabez007
jabez007 / Ping-LocalNetwork.sh
Created February 12, 2018 15:22
A rough Bash script from my Linux server class to ping all the IP addresses on our network
#!/bin/bash
# Set the internal field separator
IFS=$'\n'
ping_count=3
ping_deadline=1
# regex pattern for IP addresses
grep_ip="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
@jabez007
jabez007 / Create-InternalCertificate.ps1
Created February 12, 2018 15:17
Quick PowerShell script for requesting, issuing, and installing certificates issued from an internal CA
param (
[string]$CAHost = "default.ca-server.com",
[string]$CA = "default certificate authority"
)
# Make sure we are running as Admin
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments