Skip to content

Instantly share code, notes, and snippets.

View AndrewBarfield's full-sized avatar

Andrew Barfield AndrewBarfield

View GitHub Profile
@AndrewBarfield
AndrewBarfield / gist:2552013
Created April 29, 2012 17:13
DOS Batch File: Windows 7 Cleanup Script
echo off
REM Replace [[[USER]]] with your local user account name
REM Clean Libraries
del /Q /S "C:\Users\[[[USER]]]\Contacts\*.*" > nul
del /Q /S "C:\Users\[[[USER]]]\Downloads\*.*" > nul
del /Q /S "C:\Users\[[[USER]]]\Music\*.*" > nul
del /Q /S "C:\Users\[[[USER]]]\Pictures\*.*" > nul
del /Q /S "C:\Users\[[[USER]]]\Videos\*.*" > nul
@AndrewBarfield
AndrewBarfield / gist:2552137
Created April 29, 2012 17:31
PowerShell: Display file descriptions of all executables in the System32 folder
cls
# Change the current directory to the System folder
cd C:\Windows\System32\
# Display all executable files along with their file description
get-childitem * -include *.exe | foreach-object {
"{0}, {1}" -f $_.Name,
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileDescription }
@AndrewBarfield
AndrewBarfield / gist:2552163
Created April 29, 2012 17:37
PowerShell: Generate a set of N random integers between -9 and 9
cls
$N = 5;
# --------------------------------------------------------------------------------
#
# FUNCTION NAME: GenerateSet
#
# DESCRIPTION: Generates a set of N random integers between -9 and 9
#
# --------------------------------------------------------------------------------
@AndrewBarfield
AndrewBarfield / gist:2556400
Created April 30, 2012 08:01
C#: System.Collections: Display binary values using BitArray class
using System;
using System.Collections;
namespace BitArrayExample {
class Program {
static void Main(string[] args) {
bool le = BitConverter.IsLittleEndian;
if ( le ) {
@AndrewBarfield
AndrewBarfield / gist:2556422
Created April 30, 2012 08:05
C#: Bit Twiddling: Determine the minimum or maximum of two integers
using System;
namespace BitTwiddling {
class Program {
// Compute the minimum of two integers without branching
static int Min(int x, int y) {
return y + ( ( x - y ) & ( ( x - y ) >> ( sizeof( int ) * 8 - 1 ) ) );
}
// Compute the maximum of two integers without branching
@AndrewBarfield
AndrewBarfield / gist:2556440
Created April 30, 2012 08:09
C#: delegate: Calling static and instance methods with delegates
using System;
namespace DelegateExample {
class Program {
// Declares a delegate for the methods
public delegate String myMethodDelegate();
// Defines an instance and static method
public class myMethodsClass {
@AndrewBarfield
AndrewBarfield / gist:2556506
Created April 30, 2012 08:18
C#: System.Collections.Generic: Custom Generic list class
using System;
using System.Collections.Generic;
namespace GenericList {
class Program {
static void Main(string[] args) {
// int is the type argument
GenericList<int> list = new GenericList<int>();
for ( int x = 0 ; x < 10 ; x++ ) {
@AndrewBarfield
AndrewBarfield / gist:2556542
Created April 30, 2012 08:27
C#: System.Collections.Generic: Enumerating a Generic list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericListEnumerator {
class Program {
public class Domain {
@AndrewBarfield
AndrewBarfield / gist:2556734
Created April 30, 2012 09:08
C#: System.Collections.Generic: Generic Queue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericQueue {
class Program {
static void Main(string[] args) {
// Creates and initializes a new Queue<string>.
@AndrewBarfield
AndrewBarfield / gist:2556740
Created April 30, 2012 09:09
C#: System.Collections.Generic: Enumerating a Generic Queue
using System;
using System.Collections.Generic;
namespace GenericQueueEnumerator {
class Program {
static void Main(string[] args) {
// Initialize a new instance of Queue<string>
Queue<string> myQ = new Queue<string>();