Skip to content

Instantly share code, notes, and snippets.

View pjsvis's full-sized avatar

Peter John Smith pjsvis

  • Virtual Information Systems
  • Edinburgh
View GitHub Profile
{
"env": {
"browser": true
},
"globals": {
"angular": false, // IE Cannot overwrite angular
"agGrid": false,
"$": false,
"_": false,
"require" : false,
// Visual Studio has a binding of BeforeBuild: main
// This means that when you build the app the main task will run.
//
// References
// 1. [https://gist.github.com/spboyer/96339ce687b0c79b8258](https://gist.github.com/spboyer/96339ce687b0c79b8258)
// 1. [http://stackoverflow.com/questions/32824381/parse-main-bower-files-js-css-scss-images-to-distribution-via-gulp](http://stackoverflow.com/questions/32824381/parse-main-bower-files-js-css-scss-images-to-distribution-via-gulp)
'use strict';
// The following dependencies are installed by
// ```
@pjsvis
pjsvis / cloudSettings
Last active April 29, 2017 11:44
Visual Studio code settings
{"lastUpload":"2017-04-26T10:10:35.981Z","extensionVersion":"v2.6.2"}
@pjsvis
pjsvis / gist:3443800779c446d4bd791e5f9b9e3e2d
Created April 7, 2016 14:14
Create an MD5 hash and get a gravatar image
function get_gravatar(email, size) {
// MD5 (Message-Digest Algorithm) by WebToolkit
//
var MD5 = function(s) { function L(k, d) { return (k << d) | (k >>> (32 - d)); } function K(G, k) { var I, d, F, H, x; F = (G & 2147483648); H = (k & 2147483648); I = (G & 1073741824); d = (k & 1073741824); x = (G & 1073741823) + (k & 1073741823); if (I & d) { return (x ^ 2147483648 ^ F ^ H); } if (I | d) { if (x & 1073741824) { return (x ^ 3221225472 ^ F ^ H); } else { return (x ^ 1073741824 ^ F ^ H); } } else { return (x ^ F ^ H); } } function r(d, F, k) { return (d & F) | ((~d) & k); } function q(d, F, k) { return (d & k) | (F & (~k)); } function p(d, F, k) { return (d ^ F ^ k); } function n(d, F, k) { return (F ^ (d | (~k))); } function u(G, F, aa, Z, k, H, I) { G = K(G, K(K(r(F, aa, Z), k), I)); return K(L(G, H), F); } function f(G, F, aa, Z, k, H, I) { G = K(G, K(K(q(F, aa, Z), k), I)); return K(L(G, H), F); } function D(G, F, aa, Z, k, H, I) { G = K(G, K(K(p(F, aa, Z), k), I)); return K
using System;
using System.Data;
using Dapper;
using Dapper.Contrib.Extensions;
using NUnit.Framework;
using ServiceStack.Text;
//using Dommel;
namespace DataAccess
@pjsvis
pjsvis / gist:65e0e5efd16eb1d4e100
Last active August 29, 2015 14:27
Lazy instantiation of SqlConnection
// Ref: [mythz](https://groups.google.com/forum/#!topic/servicestack/bb95kGpDcEo)
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
namespace Clear2Pay.OTS.UTP.Data.Tests
{
public class Database : IDisposable
{
// Format as per flot requirements
var flotData = new[]
{
new {label = "Quantity Required", data = partAvailability.Select(x => new[] {x.TimeStamp, x.QuantityRequired})},
new {label = "Quantity Available", data = partAvailability.Select(x => new[] {x.TimeStamp, x.QuantityAvailable})}
};
// Timestamp created as follows
private static long GetJavascriptTimestamp(DateTime date)
{
// Ref: http://stackoverflow.com/questions/3738748/create-an-array-or-list-of-all-dates-between-two-dates
void Main()
{
var requirements = GetRequirements();
// TODO: Add a margin at the start and end
// Get a range of dates
var start = requirements.Select (x =>x.DtFm).Min();
var end =requirements.Select (x =>x.DtTo).Max();
var dateRange = Enumerable.Range(0, 1 + end.Subtract(start).Days)
@pjsvis
pjsvis / UrlBuilder
Last active August 29, 2015 14:15
Angular Service to Build a URL with Query Params
// NOTE: Build a url with query params
angular.module('app').factory('UrlBuilder', function () {
function sortedKeys(obj) {
var keys = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
keys.push(key);
}
}
@pjsvis
pjsvis / gist:780d930b87ce8ea5cc48
Created December 11, 2014 13:23
Using LINQ to simplify business rules
// Ref: http://odetocode.com/Articles/739.aspx
// Using LINQ to simplify business rules
Employee employee =
new Employee { ID = 1, Name =
"Poonam", DepartmentID = 1 };
Func<Employee, bool>[] validEmployeeRules =
{
e => e.DepartmentID > 0,