Skip to content

Instantly share code, notes, and snippets.

View johnmcbride's full-sized avatar

John McBride johnmcbride

View GitHub Profile
@johnmcbride
johnmcbride / getActiveVSProject.cs
Last active March 15, 2017 19:20
Get Active Project in Visual Studio Extension
var _dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
Array _projects = DTE.ActiveSolutionProjects as Array;
if ( _projects.Length != 0 && _projects != null)
{
Project _selectedProject = _projects.GetValue(0) as Project;
//get the project path
string _directoryPath = new FileInfo(_selectedProject.FullName).DirectoryName;
Console.WriteLine(_selectedProject.FullName);
@johnmcbride
johnmcbride / ListFilesPS.ps1
Created September 29, 2016 18:15
Powershell command to list files in a directory and write out its name
Get-ChildItem | ForEach-Object { write-host $_.name }
@johnmcbride
johnmcbride / renamefiles.sh
Created March 28, 2016 18:25
Shel script to replace all spaces in a filename with dashes (and makes lower case)
for file in *
do
updatedFileName=`echo "$file" | awk '{print tolower($0)}' | sed s/' '/'-'/g`
echo "$updatedFileName"
mv "$file" "$updatedFileName"
done
@johnmcbride
johnmcbride / CitrixNetscaler_ListVirtualServers
Created July 15, 2013 19:04
A quick C# console application that demonstrates how to use the Citrix Netscaler C# SDK to authenticate to a Netscaler appliance and list the current virtual servers with their state (down, up, etc) and IP address
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Citrix Netscaler nitro namespaces
using com.citrix.netscaler.nitro.service;
using com.citrix.netscaler.nitro.resource.config.lb;
namespace NetscalerSDKShowcase
@johnmcbride
johnmcbride / CreateMongoDB-C#
Last active December 19, 2015 06:39
Quick C# method for creating a MongoDB database using the InGen MongoDB driver (located here http://www.nuget.org/packages/mongocsharpdriver/). This method will try and connect to you local mongodb instance and check for the existence of the defined database and delete it. Once deleted it will try and create a new database instance.
private bool CreateDatabaseWithDelete()
{
internal const string ConnectionString = "mongodb://localhost";
try
{
MongoClient Client = new MongoClient(ConnectionString);
MongoServer Server = Client.GetServer();
if (Server.DatabaseExists("mydatabase"))
{
@johnmcbride
johnmcbride / MongoTestClassObject
Last active December 17, 2015 02:39
MongoDB Child Class example
class Customer
{
public string Id { get;set;}
public string Name { get;set;}
public List<Order> Orders
}
class Order
{
public string Id {get;set;}
public string Name { get;set;}
@johnmcbride
johnmcbride / Netscaler.cs
Last active July 1, 2017 16:35
C# code that demonstrates using the Citrix Netscaler NITRO API to return a list of Citrix Access Gateways configured on the Netscaler appliance.
using com.citrix.netscaler.nitro.service;
private List<string> GetGateways()
{
List<string> _accessGateways = new List<string>();
nitro_service _ns = new nitro_service(@"[Your Netscaler IP]", "http");
_ns.login("[Username]", "[Your Password]");
foreach (var _gateway in com.citrix.netscaler.nitro.resource.config.vpn.vpnvserver.get(_ns))
using com.citrix.netscaler.nitro.service;
private List<string> GetGateways()
{
List<string> _accessGateways = new List<string>();
nitro_service _ns = new nitro_service(@"[Your Netscaler IP]", "http");
_ns.login("[Username]", "[Your Password]");
foreach (var _gateway in com.citrix.netscaler.nitro.resource.config.vpn.vpnvserver.get(_ns))
@johnmcbride
johnmcbride / XenServer.cs
Created January 17, 2013 21:25
XenSever .NET example for listing all Virtual Machines on a XenServer. This also excludes virtual machines that are listed as templates.
//build the XenServer session object that will hold a validated/authenticated
//session to the specified xenserver
XenAPI.Session _session = new XenAPI.Session("server address", 80);
try
{
//try to login to the specified xenserver with the
//supplied credentials
_session.login_with_password("Username", "Password");
if (_session != null)
{