Skip to content

Instantly share code, notes, and snippets.

@webcoyote
webcoyote / dirglob.rb
Created February 5, 2013 21:13
Ruby directory globbing
Dir.glob(
'**/*', File::FNM_DOTMATCH
).reject { |a| a =~ /\.{1,2}$/ }.each do |f|
puts f
end
@webcoyote
webcoyote / create-or-update.sql
Created December 11, 2012 19:15
Update SQL stored procedure
-- if the stored procedure does not exist then create a placeholder
if not exists (
select * from sys.objects where object_id = OBJECT_ID(N' p_MyProc')
and type = N'P'
) then
create procedure p_MyProc as RAISERROR ('MyProc not defined', 16, 1);
grant execute on p_MyProc to SomeRole
end
-- update stored proc
@webcoyote
webcoyote / PlatformTime.cpp
Created December 11, 2012 19:06
Transaction rate-limiting
unsigned PlatformTimeMs () {
#if defined(_WINDOWS_)
return GetTickCount();
#else
#error Your implementation here
// something like clock_gettime(CLOCK_MONOTONIC, ...) for Unix/Linux
#endif
}
@webcoyote
webcoyote / configure-firewall-example.bat
Created December 11, 2012 18:45
Windows Firewall configuration script
@echo off
::configure-firewall-example.bat
::by Patrick Wyatt 12/22/2011
::MIT License - do with as you will; no warranty
SETLOCAL EnableExtensions
if "%1" == "" (
echo Usage:
echo %0 display
echo %0 install
@webcoyote
webcoyote / WalkDir.rb
Created September 13, 2011 22:21
Log file iterator pattern
require 'pathname'
require 'date'
class WalkDir
def initialize (opts = {})
# Set default handlers
@file_pattern = opts[:file_pattern] || /^[^.]/ # no hidden files
@dir_pattern = opts[:dir_pattern] || /^[^.]/ # no hidden directories
@result = opts[:result] || lambda { |pathname, match| return pathname, match }