Skip to content

Instantly share code, notes, and snippets.

Craig Phillips craigtp

Block or report user

Report or block craigtp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TruncateAtWordStringExtension.cs
public static class StringExtentionMethods
{
public static string TruncateAtWord(this string input, int maxlength, bool addEllipsis)
{
if (input == null || input.Length <= maxlength) return input;
var ellipsisLengthDeduction = (addEllipsis ? 3 : 0);
var iLastSpace = input.LastIndexOf(" ", (maxlength - ellipsisLengthDeduction), StringComparison.Ordinal);
var iLength = 0;
if (iLastSpace < 0)
{
@craigtp
craigtp / RandomString.cs
Created Apr 29, 2016
RandomString - A class containing methods to produce some handy random string combinations.
View RandomString.cs
using System;
using System.Text;
namespace RandomString
{
public class RandomString : IDisposable
{
// Can use the BetterRandom class here or just use the built-in System.Random class.
private BetterRandom random = new BetterRandom();
private const string alpha_selection = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@craigtp
craigtp / CleanUpTemporaryASPNETFiles.ps1
Last active Apr 29, 2016
Clean Up Temporary ASP.NET Files with Powershell
View CleanUpTemporaryASPNETFiles.ps1
# Run this as Administrator
net stop w3svc
Get-ChildItem "C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files" -Recurse | Remove-Item -Recurse -Force
net start w3svc
@craigtp
craigtp / LargestDBs
Last active Aug 30, 2016
List the largest databases on a SQL Server instance
View LargestDBs
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
ORDER BY SizeMB DESC
@craigtp
craigtp / ShortCodes.cs
Last active Mar 21, 2017
Short code generator.Converts a long integer to a "short code" (a seemingly random string of characters - as seen on many popular URL Shortener utilities.) and vice-versa.See: http://stackoverflow.com/a/529852/57477
View ShortCodes.cs
using System;
namespace ShortCodes
{
public static class ShortCodes
{
// You may change the "shortcode_Keyspace" variable to contain as many or as few characters as you
// please. The more characters that are included in the "shortcode_Keyspace" constant, the shorter
// the codes you can produce for a given long.
private static string shortcodeKeyspace = "abcdefghijklmnopqrstuvwxyz0123456789";
@craigtp
craigtp / NumericHelpers.cs
Last active Apr 21, 2017
Provides a function that will allow two imprecise floating point numbers to be compared for "near" equality and also an "IsNumeric" function.
View NumericHelpers.cs
public static class NumericHelpers
{
// Float point maths is whack. We can't check for absolute equality as floating point numbers are imprecise
// and are subject to rounding issues (See: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)
// Therefore, we can't check for absolute equality, but instead we have to need to check for values being
// "nearly" equal, which allows a small margin of error (i.e. something known as the "Epsilon" value for
// the given data type for this CPU that this code is running on).
public static bool NearlyEqual(double a, double b, double epsilon)
{
var absA = Math.Abs(a);
@craigtp
craigtp / touch.ps1
Created Sep 23, 2017
Windows Touch - Update Last Write / Modified Date of files recursively.
View touch.ps1
gci -recu -inc "*.*" | % { $_.LastWriteTime = Get-Date }
@craigtp
craigtp / .gitignore
Last active Nov 29, 2017
Standard Git gitignore file
View .gitignore
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
*.sln.ide/
.vs/
@craigtp
craigtp / .hgignore
Last active Dec 5, 2017
Standard Visual Studio .hgignore file for Mercurial
View .hgignore
syntax: glob
*.suo
*.obj
*.pdb
*.user
*.vspscc
*.bak
*.cache
*.log
*.lib
View keybase.md

Keybase proof

I hereby claim:

  • I am craigtp on github.
  • I am craigtp (https://keybase.io/craigtp) on keybase.
  • I have a public key whose fingerprint is 8FBD 50F4 7D2C E90F 95D6 1B27 3965 4610 07EB B49F

To claim this, I am signing this object:

You can’t perform that action at this time.