Skip to content

Instantly share code, notes, and snippets.

View hoffstein's full-sized avatar

Benjamin Hoffstein hoffstein

View GitHub Profile
@hoffstein
hoffstein / Default (Windows).sublime-keymap
Created July 18, 2011 15:08
Sublime Text 2 script to open the current file's parent directory in Windows Explorer
[
{ "keys": ["ctrl+shift+e"], "command": "open_folder_in_explorer" }
]
@hoffstein
hoffstein / gist:1089871
Created July 18, 2011 15:33
C# Extension Method To Add ForEach To Any IEnumerable
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T item in source)
action(item);
}
@hoffstein
hoffstein / gist:1089878
Created July 18, 2011 15:34
C# Get Enum Members
string[] names = Enum.GetNames(typeof(MyEnumName));
@hoffstein
hoffstein / gist:1089880
Created July 18, 2011 15:36
Vim Delete All Trailing Whitespace
:%s/\s\+$//
@hoffstein
hoffstein / gist:1089884
Created July 18, 2011 15:37
Regex for matching floating point number
[-+]?[0-9]*\.?[0-9]+
@hoffstein
hoffstein / gist:1089890
Created July 18, 2011 15:38
TSQL last second of day
DATEADD(s, -1, DATEADD(d, 1, DATEADD(d, DATEDIFF(d, 0, @date), 0)))
@hoffstein
hoffstein / gist:1089894
Created July 18, 2011 15:39
TSQL truncate time (returns just the date at 12:00:00AM)
DATEADD(d, DATEDIFF(d, 0, @date), 0)
@hoffstein
hoffstein / gist:1089896
Created July 18, 2011 15:40
Vim keep only the first word in each line
:s/\(\s*\w\+\).*/\1
@hoffstein
hoffstein / .gvimrc
Created July 18, 2011 15:42
My gvimrc
set nocompatible
set backspace=indent,eol,start
set nobackup
set mouse=a
set confirm
" Windows settings
source $VIMRUNTIME/mswin.vim
behave mswin
@hoffstein
hoffstein / gist:1109374
Created July 27, 2011 13:41
Excel find last row
Function FindLastRow(Optional sheetToSearch As Worksheet) As Long
If sheetToSearch Is Nothing Then Set sheetToSearch = ActiveSheet
On Error GoTo handler
FindLastRow = sheetToSearch.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Exit Function
handler:
FindLastRow = 1 ' No data on sheet
End Function