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
def str_to_bool(value):
FALSE_VALUES = ['false', 'no', '0']
TRUE_VALUES = ['true', 'yes', '1']
lvalue = str(value).lower()
if lvalue in (FALSE_VALUES): return False
if lvalue in (TRUE_VALUES): return True
raise Exception("String value should be one of {}, but got '{}'.".format(
FALSE_VALUES + TRUE_VALUES, value))
true_false = ["True", "False"]
dbutils.widgets.removeAll()
dbutils.widgets.text("topic", "", "Topic")
dbutils.widgets.dropdown("debug", "True", true_false, "Debug")
dbutils.widgets.dropdown("streaming", "False", true_false, "Streaming")
dbutils.widgets.dropdown("update_kafka_schema", "False", true_false, "Update Kafka Schema")
kafka_broker = "my.kafka.queue:9092"
bucket_prefix = "my-company-bucket-prefix-"
public static class SortingExtensions
{
public static IDictionary<TKey, TValue> SortBy<TKey, TValue>(
this IDictionary<TKey, TValue> dictionary,
IEnumerable<TKey> keys
)
{
var sorter = new KeyComparer<TKey>(keys);
return new SortedDictionary<TKey, TValue>(dictionary, sorter);
}
public class KeyComparer<T> : IComparer<T>
{
private const int TOP = -1;
private const int BOTTOM = 1;
private const int EQUAL = 0;
private readonly Dictionary<T, int> _keys = new Dictionary<T, int>();
public KeyComparer(IEnumerable<T> keys)
{
public class KeyComparer<T> : IComparer<T>
{
private const int TOP = -1;
private const int BOTTOM = 1;
private const int EQUAL = 0;
private readonly Dictionary<T, int> _keys = new Dictionary<T, int>();
public KeyComparer(IEnumerable<T> keys)
{
const UpdatableMessage = class {
constructor(token, channel) {
this.token = token;
this.channel = channel;
this.ts = null;
this.message = null;
this.nextMessage = null;
this.sending = false;
}
const axios = require("axios");
function sendMessage(token, channel, ts, msg) {
token = encodeURIComponent(token);
channel = encodeURIComponent(channel);
msg = encodeURIComponent(msg);
const action = ts ? "update" : "postMessage";
const url = `https://slack.com/api/chat.${action}?token=${token}&channel=${channel}&text=${msg}&as_user=true&ts=${ts}`;
@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) {
@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;