Skip to content

Instantly share code, notes, and snippets.

View danield137's full-sized avatar

Daniel Dror (Dubovski) danield137

View GitHub Profile
@danield137
danield137 / kusto_to_es.py
Created June 28, 2022 09:32
Index a sample of a kusto table into elasticsearch
from typing import List
import requests
import json
import time
from azure.kusto.data import KustoClient, KustoConnectionStringBuilder
from datetime import datetime, timedelta
def main():
def read_kusto_data(q):
results = kc.execute_query(KUSTO_DB ,q)
@danield137
danield137 / sql_to_kql.py
Created March 15, 2022 21:01
SQL DDL to Kusto KQL
from typing import Tuple, List
# pip install sqlparse
import sqlparse
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/
SQL_TYPE_TO_KQL_TYPE = {
'int': 'int',
'varchar': 'string',
'datetime': 'datetime',
'bool': 'bool'
@danield137
danield137 / storage_account_creator.py
Last active August 24, 2021 15:47
Create multiple storage accounts
from typing import List, Tuple
from azure.cli.core import get_default_cli # requires `pip install azure-cli-core`
from tqdm import trange # requires `pip install tqdm`, can be removed
DEFAULT_RG = "resource_group"
NAME_FORMAT = "app0storage{0}"
SA_PREFIX_ARGS = ["storage", "account"]
GENERATE_SAS_DEFAULT_ARGS = ["--expiry", "2023-01-01", "--services", "ftqb", "--resource-types", "sco" ,"--permissions" ,"cdlruwap"]
class StorageAccountCreator:
@danield137
danield137 / pytorch_bundle_artifact.py
Last active October 28, 2020 14:34
Bento bundle wrapper
import importlib
import logging
import os
import shutil
from bentoml.exceptions import InvalidArgument, MissingDependencyException
from bentoml.service.artifacts import BentoServiceArtifact
from bentoml.service.env import BentoServiceEnv
logger = logging.getLogger(__name__)
@danield137
danield137 / stats.sh
Created December 4, 2019 08:41
List git stats
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
@danield137
danield137 / ListBenchmarks.cs
Last active November 24, 2019 09:18
Benchmark ToList vs IEnumerable
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace DanielDoesBenchmarks
{
[SimpleJob(RuntimeMoniker.Net472, baseline: true)]
public class ListBenchmarks
{
@danield137
danield137 / partialJson.ts
Created July 9, 2019 06:58
Javascript partial json parsing
import Clarinet from 'clarinet';
class TrackingObject {
data: { [key: string]: any } | null = null;
path: string = '';
depth: number = 0;
stack: StackItem[] = [];
expandArray(key: string) {
this.stack.push({ type: 'Array', key, value: null });
@danield137
danield137 / head_folder.py
Last active May 6, 2019 10:07
Copy first lines of every file in folder
import os
extension = '.csv'
files = [f for f in os.listdir() if f.endswith(extension)]
target_dir = 'samples'
lines_to_copy = 1000
os.mkdir(target_dir)
@danield137
danield137 / EventGridProgram.cs
Created April 16, 2019 13:04
Log Azure Storage Event Via Event Grid Subscription
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventGrid;
using Microsoft.Azure.EventHubs.Processor;
using Newtonsoft.Json;
using CloseReason = Microsoft.Azure.EventHubs.Processor.CloseReason;
@danield137
danield137 / crawl_send_eventhub.py
Last active January 20, 2023 05:35
Kusto Github Demo
from pprint import pprint
import requests
import json
import os
import sys
import time
import datetime
import traceback
from azure.eventhub import EventHubClient, Sender, EventData, EventHubError
import logging