Skip to content

Instantly share code, notes, and snippets.

View aaronhoffman's full-sized avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / PrettyPrintArrayOfArrays.cs
Last active July 26, 2016 14:52
Pretty Print Array of Arrays
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 November 4, 2018 18:58
Clean up source code directory. Delete all bin, obj, node_modules, bower_components, and packages directories.
# 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 August 5, 2016 17:16
Get size of each table in SQL Server Database
-- 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 August 8, 2016 18:19
asp.net web.config redirect to https
<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 August 9, 2016 19:49
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
// 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 February 1, 2018 20:04
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
-- 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 September 8, 2016 19:32
SQL Script to Create OpmFedScope Database
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 September 14, 2016 17:39
Spotify Web API Auth Example C#
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();
@aaronhoffman
aaronhoffman / RedditOAuthApiController.cs
Last active December 23, 2020 23:25
Reddit OAuth API C# .NET
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...
@aaronhoffman
aaronhoffman / largest-us-cities.csv
Last active October 19, 2016 14:17
Largest U.S. Cities By Population 2015. source: https://www.biggestuscities.com, http://www.geonames.org/
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