Skip to content

Instantly share code, notes, and snippets.

View jbnv's full-sized avatar
🙂
Life is good.

Jay Bienvenu jbnv

🙂
Life is good.
View GitHub Profile
@jbnv
jbnv / FilenameExtensions.tsv
Created June 23, 2015 13:50
Extensions correlated to their respective MIME types.
acx application/internet-property-stream
ai application/postscript
aif audio/x-aiff
aifc audio/x-aiff
aiff audio/x-aiff
asf video/x-ms-asf
asr video/x-ms-asf
asx video/x-ms-asf
au audio/basic
avi video/x-msvideo
@jbnv
jbnv / SqlServerQueryCursorPattern
Created July 8, 2015 15:21
SQL Server Query Cursor Pattern
DECLARE @tblName sysname
DECLARE @tblId INT
DECLARE @sql VARCHAR(MAX)
DECLARE cTable CURSOR FOR
SELECT [sql]
OPEN cTable
FETCH NEXT FROM cTable
INTO @sql
@jbnv
jbnv / CallWebService
Created July 8, 2015 15:23
Calling a Web service from T-SQL
DECLARE @Object AS INT;
DECLARE @ResponseText AS VARCHAR(8000);
EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
EXEC sp_OAMethod @Object, 'open', NULL, 'get',
'http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT', --Your Web Service Url (invoked)
'false'
EXEC sp_OAMethod @Object, 'send'
EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
@jbnv
jbnv / ContainsString
Created July 8, 2015 15:25
Return all objects that contain a particular string. (SQL Server)
SELECT OBJECT_NAME(object_id) AS [Name],
CASE
WHEN OBJECTPROPERTY(object_id, 'IsProcedure') = 1 THEN 'procedure'
WHEN OBJECTPROPERTY(object_id, 'IsView') = 1 THEN 'view'
WHEN OBJECTPROPERTY(object_id, 'IsTable') = 1 THEN 'table'
WHEN OBJECTPROPERTY(object_id, 'IsScalarFunction') = 1 THEN 'function'
WHEN OBJECTPROPERTY(object_id, 'IsTableFunction') = 1 THEN 'function'
WHEN OBJECTPROPERTY(object_id, 'IsTrigger') = 1 THEN 'trigger'
ELSE 'other'
END AS [Type]
@jbnv
jbnv / TablePrimaryKey
Created July 8, 2015 15:35
Return the primary key for a particular table. (SQL Server)
SELECT column_name
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
AND table_name = '<tableName>'
@jbnv
jbnv / MaxPK
Last active August 29, 2015 14:24
Get the maximum value of the primary key of each table in a database. (SQL Server)
-- This query generates another query which you will then run to get the maximum IDs.
SELECT STUFF((
SELECT 'UNION SELECT '''+TABLE_SCHEMA+''' AS TABLE_SCHEMA,'''+TABLE_NAME+''' AS TABLE_NAME,'''+COLUMN_NAME+''' AS COLUMN_NAME,'
+'CAST(MAX(['+COLUMN_NAME+']) AS VARCHAR) FROM ['+TABLE_SCHEMA+'].['+TABLE_NAME+'] AS [MaxPrimaryKeyValue] '
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
ORDER BY TABLE_SCHEMA,TABLE_NAME
FOR XML PATH('')
),1,6,'') + 'ORDER BY TABLE_SCHEMA,TABLE_NAME'
@jbnv
jbnv / YearsView
Created July 8, 2015 23:26
Years view (SQL)
select n1000.n+n10.n*10+n1.n
from (select n=1900 union select 2000) n1000
cross join dbo.Numbers n10
cross join dbo.Numbers n1
--where n1000.n+n10.n*10+n1.n between 1900 and 2099
@jbnv
jbnv / Revertable
Created July 8, 2015 23:36
Revertable class (VB)
Public Class Revertable(Of T)
private _value as T
private _oldValue as T
private _hasChanged as Boolean = false
public property Value as T
get
return _value
end get
@jbnv
jbnv / business-plan-template.md
Created August 15, 2015 13:41
Template for a business plan.

Executive Summary

This is a snapshot of your business plan as a whole and touches on your company profile and goals.

Company Description

Provides information on what you do, what differentiates your business from others, and the markets your business serves.

Market Analysis

@jbnv
jbnv / JSDecoratorPattern.js
Created August 18, 2015 15:44
JavaScript Decorator Pattern
var Thing = function() {
console.log('Assemble this thing.');
}
// The decorators will also need to implement these functions to comply with Thing's interface.
Thing.prototype = {
actionFunction: function() {
console.log('actionFunction');
},
valueFunction: function() {