Skip to content

Instantly share code, notes, and snippets.

View brazilnut2000's full-sized avatar

Jon Crowell brazilnut2000

View GitHub Profile
@brazilnut2000
brazilnut2000 / ListAllTriggers.sql
Created May 22, 2013 13:35
SQL: List all triggers and definitions
select OBJECT_NAME(triggers.parent_id) as [object_name],
triggers.name,
triggers.parent_class_desc,
triggers.type_desc,
triggers.is_disabled,
triggers.is_instead_of_trigger,
OBJECT_DEFINITION(triggers.object_id)
as trigger_definition
from sys.triggers
@brazilnut2000
brazilnut2000 / ColumnLetter
Created June 19, 2013 18:52
VBA: Returns the column letters for the column given.
Function ColumnLetter(colNum As Long) As String
Dim vArr
vArr = Split(Cells(1, colNum).Address(True, False), "$")
ColumnLetter = vArr(0)
End Function
@brazilnut2000
brazilnut2000 / Check if file or path exist.bas
Created July 5, 2013 20:17
VBA: Check to see if a given path or file exist
' Code based on snippet from John Walkenbach
Function FileExists(fileName) As Boolean
FileExists = Dir(fileName) <> ""
End Function
Function PathExists(pathName) As Boolean
' Returns TRUE if the path exists
On Error Resume Next
PathExists = (GetAttr(pathName) And vbDirectory) = vbDirectory
@brazilnut2000
brazilnut2000 / RemoveInvalidCharacters.bas
Created July 11, 2013 05:06
VBA: Remove list of characters from a string using Regex
Function RemoveInvalidCharacters(cleanMe As String) As String
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Global = True
.Pattern = "[\<\>\*\'\,\$\#\@\.\""\?\!\/\[\]\:\|\\\/\?|]"
RemoveInvalidCharacters = .Replace(cleanMe, "")
End With
End Function
@brazilnut2000
brazilnut2000 / Get Pluralized Word.cs
Created July 26, 2013 19:17
C#: Return the singular or plural version of a word based on how many there are
static string GetPluralized(string word, int count)
{
return count == 1 ? word : word + "s";
}
@brazilnut2000
brazilnut2000 / GeolocationFromLatLon.sql
Created August 23, 2013 21:27
SQL: Populate GeoLocation table from Latitude and Longitude
/*
Assumes table has populated Latitude and Longitude columns
Populates the GeoLocation column from Lat ad Lon
*/
UPDATE [dbo].[TableX]
SET [GeoLocation] = geography::Parse('POINT(' + CAST([Longitude] AS VARCHAR(20)) + ' ' +
CAST([Latitude] AS VARCHAR(20)) + ')')
GO
@brazilnut2000
brazilnut2000 / Find Column From All Tables of Database.sql
Created September 25, 2013 19:40
SQL: Find column from all tables of database
/*
Replace COLUMNNAME with the column you are looking for...
Source: Pinal Dave
*/
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
@brazilnut2000
brazilnut2000 / Generic HTML5 Page
Last active December 28, 2015 11:09
EMMET: Script to generate generic semantic html5 page
<!DOCTYPE html>
html>head>title+link^body>(header.top>a.logo>img)+nav.primary>a{Link$}*3^(div.main>(aside.sidebar>nav>a{Sublink$}*3)+section.content>article>header>h1+p>lipsum)+footer.bottom>nav>a{social$}*3
@brazilnut2000
brazilnut2000 / IsStringNumeric.cs
Last active January 2, 2016 00:29
C#: Determine whether a string is numeric
public static bool isNumeric(string val, System.Globalization.NumberStyles NumberStyle)
{
Double result;
return Double.TryParse(val, NumberStyle,
System.Globalization.CultureInfo.CurrentCulture, out result);
}
/*
USAGE: