Skip to content

Instantly share code, notes, and snippets.

View jbubriski's full-sized avatar

John Bubriski jbubriski

View GitHub Profile
@jbubriski
jbubriski / NonQuery.cs
Last active December 18, 2015 07:59
Executing queries with SqlConnection and SqlCommand.
public void NonQuery()
{
var connectionString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
var sqlCommandText = "UPDATE People SET Name = 'John'";
using (var sqlConnection = new SqlConnection(connectionString))
using (var sqlCommand = new SqlCommand(sqlCommandText, sqlConnection))
{
sqlCommand.Connection.Open();
@jbubriski
jbubriski / transfer_objects_to_dbo_schema.sql
Last active December 18, 2015 15:58
Transfer SQL Server Objects to another schema.
SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + o.Name
FROM sys.Objects o
INNER JOIN sys.Schemas s on o.schema_id = s.schema_id
WHERE s.Name = 'your_schema_name'
And (o.Type = 'U' Or o.Type = 'P' Or o.Type = 'V')
@jbubriski
jbubriski / AccountController.cs
Created July 9, 2013 20:49
An HTTP module that will strip the password from the POST parameters and replace it with the verification result.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using Recaptcha;
namespace Controllers
@jbubriski
jbubriski / HandleFormSubmit.js
Created July 15, 2013 14:59
Injecting AJAX result into a form before submitting. This is just a sample, it's not complete.
(function() {
$(function() {
var dataRequested = false;
var $form = $('#form');
$form.on('submit', function() {
if (!dataRequested) {
callMethodToGetAjaxData();
return false;
@jbubriski
jbubriski / CustomTableItems.tt
Last active December 20, 2015 05:59
Auto generate Kentico custom table classes for each one in the database. Yes, I know the formatting is awful. For using this with a project, change the Host.Resolve() path, and change it to app.config instead of the web.config.
<#@ template debug="True" hostspecific="True" language="C#" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Configuration" #>
<#@ assembly name="System.Core" #>
<#@ Assembly Name="System.Collections" #>
<#@ Assembly Name="System.Data" #>
<#@ Assembly Name="System.Linq" #>
<#@ Assembly Name="System.Xml" #>
<#@ Assembly Name="System.Xml.Linq" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
@jbubriski
jbubriski / LoadCsvDataIntoSqlServer.cs
Last active December 20, 2015 19:48
Loads data from a CSV file using the Microsoft.VisualBasic.FileIO.TextFieldParser, then uses the SqlBulkCopy to put the data into a temp table in SQL Server, then copies the data to the live table.
public class LoadCsvDataIntoSqlServer
{
// Queries for truncating the tables and copying data
protected string _truncateTempTableCommandText = @"TempTable";
protected string _truncateLiveTableCommandText = @"LiveTable";
protected string _copyDataCommandText = @"
INSERT INTO LiveTable (FirstName, LastName)
SELECT FirstName, LastName
FROM TempTable";
@jbubriski
jbubriski / CrngExample.cs
Created August 23, 2013 19:29
Cryptographic Random Number Generation example.
public class Example
{
private static int GetRandomNumber(int max)
{
var bytes = new byte[3];
var cr = new System.Security.Cryptography.RNGCryptoServiceProvider();
cr.GetBytes(bytes);
// Get 3 random digits as a string, and parse it as an int, then keep it between 0 and the max

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.

@jbubriski
jbubriski / shrink.sql
Created August 29, 2013 14:22
SQL Server command to shrink the logs of a database.
ALTER DATABASE mydatabase SET RECOVERY SIMPLE
DBCC SHRINKFILE (mydatabase_Log, 1)
@jbubriski
jbubriski / generate_shrink_commands.sql
Last active December 21, 2015 22:58
A SQL Server script to generate the Shrink commands for all the databases in an instance.
DROP TABLE #f
GO
CREATE TABLE #f (name sysname, fileid int, filename sysname, filegroup sysname null,
size sysname, maxsize sysname, growth sysname, usage sysname)
GO
EXEC sp_MSforeachdb 'DECLARE @s VARCHAR(8000);
USE [?];
TRUNCATE TABLE #f;
INSERT #f (name, fileid, filename, filegroup, size, maxsize, growth, usage )
EXEC sp_helpfile