Navigation Menu

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;
{
"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: [''],
@KeesCBakker
KeesCBakker / hubot-command-mapper-todo-list.js
Last active August 10, 2018 11:57
Todo List - Hubot Command Mapper
{
name: "list",
alias: ["", "lst", "ls"],
invoke: (tool, robot, res, match, values) => {
if (todos.length === 0) {
res.reply("The list is empty.");
return;
}
let i = 0;
@KeesCBakker
KeesCBakker / hubot-command-mapper-todo-remove.js
Created August 10, 2018 12:00
Todo Remove - Hubot Command Mapper
{
name: "remove",
alias: ["rm", "del"],
parameters: [new RestParameter("item")],
invoke: (tool, robot, res, match, values) => {
let item = values.item.toLowerCase();
let length = todos.length;
todos = todos.filter(f => f.toLowerCase().indexOf(item) === -1);
let i = length - todos.length;
if (i === 1) {