Skip to content

Instantly share code, notes, and snippets.

class Timer {
readonly start = performance.now();
constructor(private readonly name: string) {}
stop() {
const time = performance.now() - this.start;
console.log('Timer:', this.name, 'finished in', Math.round(time), 'ms');
}
}
function getVersion()
{
$tag = iex "git describe --long --tags --always"
$a = [regex]"v\d+\.\d+\.\d+\-\d+"
$b = $a.Match($tag)
$b = $b.Captures[0].value
$b = $b -replace '-', '.'
$b = $b -replace 'v', ''
Write-Host "Version found: $b"
<md-input-container class="admin-form">
<input md-input placeholder="Block Title" nfNoSpaces [(ngModel)]="block.title" id="block-{{ block.id }}-input-name" name="title"
#title="ngModel">
<md-hint [ngStyle]="{'color': 'red'}" align="start" *ngIf="!title.valid && !title.pristine">Title is required.</md-hint>
</md-input-container>
Be sure to include ref to directive in module declarations array.
@jokecamp
jokecamp / package.json
Last active July 6, 2020 13:50
Demo for Passport.js authentication in a Node.js Express application
{
"name": "securehelloworld",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@jokecamp
jokecamp / gist:2c1a67b8f277797ecdb3
Last active July 31, 2024 07:41
Powershell HMAC SHA 256 Example
# Powershell HMAC SHA 256
$message = 'Message'
$secret = 'secret'
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($secret)
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($message))
$signature = [Convert]::ToBase64String($signature)
@jokecamp
jokecamp / client.html
Last active August 29, 2015 14:03
Working Socket.io 1.0 with path option
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
</head>
<body>
<form action="">
<input type="input" id="m" /><button>Send</button>
</form>
<pre id="output"></pre>
@jokecamp
jokecamp / AppHostBase
Created June 4, 2014 15:17
ServiceStack v3.9.55.0 - Dynamically add OPTIONS to all routes
/// Call this ad the end of your app host Configure(Funq.Container container) method
private void AddOptionsVerbToAllRoutes(IServiceRoutes routes)
{
var map = EndpointHost.ServiceManager.ServiceController.RestPathMap;
foreach (var key in map.Keys)
{
foreach (RestPath rp in map[key])
{
routes.Add(rp.RequestType, rp.Path, "OPTIONS");
}
@jokecamp
jokecamp / example.dart
Created January 17, 2014 17:24
Dart HMAC SHA 256 Example code
import 'dart:html';
import 'dart:convert';
import 'package:crypto/crypto.dart';
void main() {
String secret = 'secret';
String message = 'Message';
List<int> secretBytes = UTF8.encode('secret');
@jokecamp
jokecamp / RequestFilter
Created December 13, 2013 21:11
ServiceStack v3 Partial Updates
this.RequestFilters.Add((httpReq, httpResp, requestDto) =>
{
var hasFilter = requestDto as IAllowPartialUpdate;
if (hasFilter != null)
{
if (httpReq.QueryString["fields"] != null)
{
// store for later
httpReq.Items.Add("Patch_Fields", httpReq.QueryString["fields"].Split(new[] {','}));
}
@jokecamp
jokecamp / gist:7529013
Created November 18, 2013 14:50
Various ways of sanitizing XML input
/// http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/
/// http://stackoverflow.com/questions/157646/best-way-to-encode-text-data-for-xml/732135#732135
public string Clean(string text)
{
return new string(text.Where(XmlConvert.IsXmlChar).ToArray());
}
public static string CleanInvalidXmlChars(string text)
{