This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kafka_broker = "my.kafka.queue:9092" | |
bucket_prefix = "my-company-bucket-prefix-" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UpdatableMessage = class { | |
constructor(token, channel) { | |
this.token = token; | |
this.channel = channel; | |
this.ts = null; | |
this.message = null; | |
this.nextMessage = null; | |
this.sending = false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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; |