Skip to content

Instantly share code, notes, and snippets.

View KeesCBakker's full-sized avatar
😎
Out huntin' bugz!

Kees C. Bakker KeesCBakker

😎
Out huntin' bugz!
View GitHub Profile
@KeesCBakker
KeesCBakker / test.ts
Last active August 3, 2016 13:46
QUnit to Mocha conversion
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../StronglyTypedEvents.d.ts" />
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
'use strict';
var r = typeof require !== 'undefined', w = window as any;
var expect: Chai.ExpectStatic = r ? require('chai').expect : w.chai.expect;
@KeesCBakker
KeesCBakker / Settings for MQTT.cs
Last active February 15, 2024 12:10
Settings to connect to MQTT using M2Mqtt (can be used with CloudMqtt)
using System.ComponentModel.DataAnnotations;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
var settings = AppSettingsProvider.Create<MqttSettings>();
var port = Convert.ToInt32(settings.Port);
MqttClient client = null;
if (settings.UseSecureConnection)
{
@KeesCBakker
KeesCBakker / custom-event-polyfill.js
Last active December 2, 2021 03:51
Custom Event Polyfill From MDN
// custom event polyfill for IE9 - IE11
(function () {
if (typeof window.CustomEvent !== 'function') {
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
{
"pomegranate": {
"50": "#f9ebea",
"100": "#f2d7d5",
"200": "#e6b0aa",
"300": "#d98880",
"400": "#cd6155",
"500": "#c0392b",
"600": "#a93226",
"700": "#922b21",
@KeesCBakker
KeesCBakker / knockout.conditioned-observable.js
Created September 7, 2017 16:02
Knockout JS Conditioned Observable
"use strict";
ko.conditionedObservable = function (initialValue, condition) {
var obi = ko.observable(initialValue);
var computer = ko.computed({
read: function () { return obi(); },
write: function (newValue) {
//unwrap value - just to be sure
var v = ko.unwrap(newValue);
//check condition
if (condition(v)) {
const
norrisUrl = 'https://api.icndb.com/jokes/random',
decode = require('decode-html');
//the export is used to init the bot
module.exports = (robot) => {
//listen to phrases that contain "Norris"
robot.hear(/Norris/ig, (res) => {
class Parameter
{
[FromRoute]
public string CategoryCode { get; set; }
[FromRoute]
public string ShopCode { get; set; }
[FromRoute]
public string SegmentCode { get; set; }
[FromRoute]
public string ProductId { get; set; }
public class RegexNamedGroupRoutingConstraint : IRouteConstraint
{
private readonly List<Regex> regexes = new List<Regex>();
public RegexNamedGroupRoutingConstraint(params string[] regexes)
{
foreach (var regex in regexes)
{
this.regexes.Add(new Regex(regex));
}
app.UseMvc(routes =>
{
var shopRoutingConstraint = new RegexNamedGroupRoutingConstraint(
"/(?<CategoryCode>[A-Z0-9]{3})_(?<ShopCode>[A-Z0-9]{3})_(?<SegmentCode>[A-Z0-9]{3})_(?<ProductId>\d+)/?$",
"/(?<CategoryCode>[A-Z0-9]{3})_(?<ShopCode>[A-Z0-9]{3})_(?<SegmentCode>[A-Z0-9]{3})/?$",
"/(?<CategoryCode>[A-Z0-9]{3})_(?<ShopCode>[A-Z0-9]{3})/?$",
"/(?<CategoryCode>[A-Z0-9]{3})/?$"
);
routes.MapRoute
@KeesCBakker
KeesCBakker / hubot-command-mapper-todo-add.js
Created August 10, 2018 11:44
Todo Add - Hubot Command Mapper
const { mapper, RestParameter } = require('hubot-command-mapper')
module.exports = robot => {
let todos = []
mapper(robot, {
name: 'todo',
commands: [{
name: 'add',
alias: [''],