Skip to content

Instantly share code, notes, and snippets.

View Hallmanac's full-sized avatar

Brian Hall Hallmanac

View GitHub Profile
@Hallmanac
Hallmanac / mulitply-numbers.ts
Created August 11, 2022 13:13
A sample function showing how to multiply two numbers in Javascript. Used as a reference when teaching someone how to code.
function multiplyTwoNumbers(num: number, multiplier: number) {
let result = 0;
for (let index = 0; index < multiplier; index++) {
result += num;
}
return result;
}
function multiplyNumbers(...nums: number[]) {
let result = 0;
@Hallmanac
Hallmanac / ListExtensions.cs
Created November 7, 2017 11:15
Extension methods for the List<T> class in C#
using System.Linq;
using System.Linq.Expressions;
namespace System.Collections.Generic
{
public static class ListExtensions
{
/// <summary>
/// Takes the current list and returns a List of Lists. A.K.A. a batch of lists where each list is no larger than the
@Hallmanac
Hallmanac / FileChangesForRelease.ps1
Created May 19, 2017 11:33
A PowerShell script that can be used in a VSTS Build to get a filtered list of file changes and have those files copied to the Staging directory.
#
# FileChangesForRelease.ps1
#
# Gets the list of .rdl files that were added or modified since the previous commit (based on the PR) and copies them to the staging directory
#
$urlBase = $env:SYSTEM_TEAMFOUNDATIONSERVERURI + $env:SYSTEM_TEAMPROJECT + "/_apis/";
$accessToken = $env:SYSTEM_ACCESSTOKEN;
$auth = "Bearer $accessToken";
$accept = "application/json";
@Hallmanac
Hallmanac / LocalVstsDevelopment.ps1
Last active May 19, 2017 11:33
A PowerShell file for local development against the VSTS API. This specifically works with a Git commit and filters out certain files. Replace the place holder values with what's appropriate for you.
# Place for local script to be developed
# Please note that all place holders are in all caps
$urlBase = "https://{YOUR_VSTS_ACCOUNT}.visualstudio.com/DefaultCollection/{PROJECT_NAME}/_apis/";
# You can leave the username blank
$username = "";
$password = "YOUR_PERSONAL_ACCESS_TOKEN";
@Hallmanac
Hallmanac / StringExtensions.cs
Last active August 19, 2017 22:34
C# String Extensions
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
namespace System
{
public static class StringExtensions
@Hallmanac
Hallmanac / BundleSqlScripts.cs
Last active April 21, 2017 10:36
Concat SQL script files into one bundled SQL script file. Then parse out the bundled file by splitting on the "Go" statements and execute each script line one at a time.
using System.IO;
using System.Text;
using Funqy.CSharp;
namespace Hallmanac.SqlScriptConcat
{
public class BundleSqlScripts
{
@Hallmanac
Hallmanac / DatabaseUtils.cs
Created April 19, 2017 23:14
Ado.Net utility methods
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
namespace Hallmanac
{
public class DatabaseUtils
{
public DataTable ConvertToDataTable<T>(IList<T> list)
@Hallmanac
Hallmanac / UsCounties.cs
Last active February 18, 2017 20:36
A C# class holding constants for US Counties (a.k.a. parishes or boroughs) that are surfaced as an object called UsCountyDetails. This also references a listing of US States that reside in the Gist here: https://gist.github.com/Hallmanac/00946bfa7e028cee3a313f1c445ba216
using System.Collections.Generic;
using System.Linq;
namespace Hallmanac
{
public class UsCounties
{
public static UsCountyDetails FlAlachua { get; } = new UsCountyDetails("74227e90-7205-4c22-aab0-590bb06b7057", "Alachua", AllUsStates.Florida, 1);
public static UsCountyDetails FlBaker { get; } = new UsCountyDetails("cb491b8d-481b-4970-a1d0-a92f1832511e", "Baker", AllUsStates.Florida, 2);
public static UsCountyDetails FlBay { get; } = new UsCountyDetails("5b3be6cb-3f04-49c3-a94b-1f260c2688b0", "Bay", AllUsStates.Florida, 3);
@Hallmanac
Hallmanac / AllUsStates.cs
Last active April 28, 2017 21:01
A C# class holding constants of all US States surfaced as an object named UsState
using System.Collections.Generic;
using System.Linq;
namespace Hallmanac
{
public class AllUsStates
{
public static UsState Alabama { get; } = new UsState("a1103958-42c9-4fda-ab46-a04d41a4783b", 1, "Alabama", "AL");
public static UsState Alaska { get; } = new UsState("afa95187-e5a6-44c6-baf2-0dbb3dcc93b1", 2, "Alaska", "AK");
public static UsState Arizona { get; } = new UsState("c090438e-5f7f-427f-a191-d6ea1be8185b", 3, "Arizona", "AZ");
@Hallmanac
Hallmanac / get-header-interceptor.ts
Last active February 18, 2017 19:35
Creating accept header interception for $http in Angular
/** @ngInject */
function _getHeaderInterceptor(utils: Nebbia.IUtils) {
const interceptor: ng.IHttpInterceptor = {
request: (config: ng.IRequestConfig) => {
const isGet = utils.stringContains("GET", config.method, false);
const hasJsonAcceptType = utils.stringContains("/json", config.headers["Accept"], false);
const isHtmlFileRequest = _isHtmlUrl();
if (isGet && isHtmlFileRequest && hasJsonAcceptType) {
config.headers["Accept"] = "application/html, text/html, */*";
}