Skip to content

Instantly share code, notes, and snippets.

View danield137's full-sized avatar

Daniel Dror (Dubovski) danield137

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / ResultsToMarkdown.kql
Last active September 20, 2022 10:25
Azure Data Explorer - Useful utility functions
.create-or-alter function with (folder = "formatting", docstring = "Table to Markdown", skipvalidation = "true") TableToMarkdown(t:(*)) {
let schema = t | getschema;
let headers = schema | project ColumnName | summarize make_list(ColumnName) | extend String = strcat('| ', strcat_array(list_ColumnName, ' | '), ' |') | project String, Order=1;
let upperDivider = schema | project ColumnName, Sep = '---' | summarize Cols=make_list(Sep) | extend String = strcat('| ', strcat_array(Cols, ' | '), ' |') | project String, Order=2;
let data = t | extend Cols=pack_array(*) | extend String = strcat('| ', strcat_array(Cols, ' | '), ' |') | project String, Order=3;
headers
| union upperDivider
| union data
| order by Order asc
| summarize Rows=make_list(String)
@danield137
danield137 / LockAndWait.cs
Created December 28, 2022 00:17
Example of locking a write to resource, and providing an awaitable for readers
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace ProperLockingTester
{
public class WellLockedResource
{
private readonly object m_lock;
private bool lockedState = false;
private TaskCompletionSource<bool> m_taskCompletionSource;
@danield137
danield137 / Program.cs
Created January 4, 2023 22:13
Interprocess signaling with C#
using System.Diagnostics;
namespace TestinManuelResetEventHandler
{
internal class Program
{
private enum RunMode
{
cluster,
listen,
@danield137
danield137 / Gzip.csproj
Created January 20, 2023 01:16
Compression Benchmark
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />