Skip to content

Instantly share code, notes, and snippets.

View josephhanson's full-sized avatar

Joseph Hanson josephhanson

  • Portland, OR
View GitHub Profile
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item title is-6" href="#" routerLink="/api">
OAUTH2 / Azure AD / Angular
</a>
</div>
<div class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" routerLink="/api" routerLinkActive="active">
api
@josephhanson
josephhanson / caesar-cipher.cs
Created September 26, 2018 16:56
HTDS: Wrapping at End of Fixed Character String
using System;
using System.Text;
namespace CesarCipher {
class Program {
static void Main(string[] args) {
// if upper or lower letter increment by N (rotate at end of alphabet)
// 97 - 122 lower, 65 - 90 upper
// % 26 allows us to work with #'s greater than 26 with same algorithm
@josephhanson
josephhanson / page-fragmentation.sql
Created June 3, 2017 11:18
SQL - Page Fragmentation
SELECT a.index_id, name, avg_fragmentation_in_percent, fragment_count,
avg_fragment_size_in_pages
FROM sys.dm_db_index_physical_stats(DB_ID('database'),
OBJECT_ID('table'), NULL, NULL, NULL) AS a
JOIN sys.indexes AS b ON a.OBJECT_ID = b.OBJECT_ID AND a.index_id = b.index_id;
@josephhanson
josephhanson / MockFile.js
Last active December 12, 2023 16:51
Mock file for JavaScript based file upload - with basic test harness
// mock file
function MockFile() { };
MockFile.prototype.create = function (name, size, mimeType) {
name = name || "mock.txt";
size = size || 1024;
mimeType = mimeType || 'plain/txt';
function range(count) {
var output = "";
@josephhanson
josephhanson / prepare-for-angular-1-testing.txt
Last active May 26, 2017 17:38
Prepare for Angular 1 Testing Using Karma/Jasmine/PhantomJS
Download and install NodeJs
Open a command/terminal and type npm to verify installation and path variable setup
Run npm install -g karma
Run npm install -g karma-cli
Run npm install karma-jasmine karma-phantom-launcher jasmine-core --save-dev
@josephhanson
josephhanson / MvcApiJsonRequest.cs
Last active December 26, 2016 16:58
Workaround to Use HTTP Status Codes When Working with a Partial SPA in ASP.NET MVC
public class MvcApiJsonRequest : JsonResult {
private readonly int _httpStatusCode;
private readonly string _invalidHttpStatusCodeMessage = "set httpStatusCode to an allowed http status code";
public MvcApiJsonRequest() {
_httpStatusCode = 200;
}
public MvcApiJsonRequest(object content) : this(200, content) {}
public MvcApiJsonRequest(int httpStatusCode) : this(httpStatusCode, null) {}