Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / PrettyPrintArrayOfArrays.cs
Last active Jul 26, 2016
Pretty Print Array of Arrays
View PrettyPrintArrayOfArrays.cs
public string PrettyPrintArrayOfArrays(int[][] arrayOfArrays)
{
if (arrayOfArrays == null)
return "";
var prettyArrays = new string[arrayOfArrays.Length];
for (int i = 0; i < arrayOfArrays.Length; i++)
{
prettyArrays[i] = "[" + String.Join(",", arrayOfArrays[i]) + "]";
@aaronhoffman
aaronhoffman / delete-bin-obj-node-nuget-directories.ps1
Last active Nov 4, 2018
Clean up source code directory. Delete all bin, obj, node_modules, bower_components, and packages directories.
View delete-bin-obj-node-nuget-directories.ps1
# delete all bin,obj,node_modules,bower_components,packages,.vs, and *proj.user files and directories
Get-ChildItem . -include bin -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include node_modules -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include bower_components -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include packages -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include .vs -Hidden -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include *proj.user -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
@aaronhoffman
aaronhoffman / sp-space-used-each-table.sql
Created Aug 5, 2016
Get size of each table in SQL Server Database
View sp-space-used-each-table.sql
-- sp spaced used each table http://stackoverflow.com/a/7892361/47226
-- must be temp table, table var not referenceable by SP
create table #TableSize (
Name varchar(255),
[rows] int,
reserved varchar(255),
data varchar(255),
index_size varchar(255),
unused varchar(255))
@aaronhoffman
aaronhoffman / web.config
Created Aug 8, 2016
asp.net web.config redirect to https
View web.config
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_to_https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
@aaronhoffman
aaronhoffman / Global.asax.cs
Last active Aug 9, 2016
ASP.NET MVC 4 Membership, Users, Passwords, Roles, Profile, Authentication, Authorization http://aaron-hoffman.blogspot.com/2013/02/aspnet-mvc-4-membership-users-passwords.html
View Global.asax.cs
// The using below is needed for "UsersContext" - it will be relative to your project namespace
using MvcApplication1.Models;
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Threading;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
@aaronhoffman
aaronhoffman / table-column-metadata.sql
Last active Feb 1, 2018
Query to gather metadata about each column in a table based on its data type. More info: http://aaron-hoffman.blogspot.com/2016/08/gather-metadata-for-each-column-of-sql.html
View table-column-metadata.sql
-- query to generate a query for each column that gathers metadata about that column based on its data type
declare @table_name varchar(200) = 'dbo.tablename'
-- queries for individual rows
select
c.name [column_name]
,c.system_type_id
,c.max_length
,c.is_identity
,c.is_nullable
@aaronhoffman
aaronhoffman / OpmFedScope.sql
Last active Sep 8, 2016
SQL Script to Create OpmFedScope Database
View OpmFedScope.sql
CREATE DATABASE [OpmFedScope]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'OpmFedScope', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\OpmFedScope.mdf' , SIZE = 134144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'OpmFedScope_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\OpmFedScope_log.ldf' , SIZE = 15040KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [OpmFedScope] SET COMPATIBILITY_LEVEL = 120
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
@aaronhoffman
aaronhoffman / SpotifyApiController.cs
Created Sep 14, 2016
Spotify Web API Auth Example C#
View SpotifyApiController.cs
public class SpotifyApiController
{
//see https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow
public void GetClientCredentialsAuthToken()
{
var spotifyClient = "";
var spotifySecret = "";
var webClient = new WebClient();
View RedditOAuthApiController.cs
public ActionResult StartOAuth()
{
var redditOAuthAuthorizeUri = "https://www.reddit.com/api/v1/authorize";
var redditOAuthRedirectUri = "https://localhost:44399/RedditRedirectUri"; // your redirect uri
var redditOAuthScopes = ""; // ex: "identity,history" scope param https://github.com/reddit/reddit/wiki/OAuth2#authorization
var redditClientId = ""; // from app: https://www.reddit.com/prefs/apps
var oauthState = Guid.NewGuid(); // used to uniquely identify this request
// todo: store oauthState somewhere...
View largest-us-cities.csv
Rank CityName StateName StateCode Population Latitude Longitude GeonamePopulation GeonameId
1 New York New York NY 8550405 40.71427 -74.00597 8175133 5128581
2 Los Angeles California CA 3971883 34.05223 -118.24368 3792621 5368361
3 Chicago Illinois IL 2720546 41.85003 -87.65005 2695598 4887398
4 Houston Texas TX 2296224 29.76328 -95.36327 2099451 4699066
5 Philadelphia Pennsylvania PA 1567442 39.95233 -75.16379 1526006 4560349
6 Phoenix Arizona AZ 1563025 33.44838 -112.07404 1445632 5308655
7 San Antonio Texas TX 1469845 29.42412 -98.49363 1327407 4726206
8 San Diego California CA 1394928 32.71533 -117.15726 1307402 5391811
9 Dallas Texas TX 1300092 32.78306 -96.80667 1197816 4684888
You can’t perform that action at this time.