Skip to content

Instantly share code, notes, and snippets.

View casperlehmann's full-sized avatar

Casper Lehmann casperlehmann

View GitHub Profile
@casperlehmann
casperlehmann / Kivy_stop_watch
Last active June 30, 2022 13:52
Stop watch implemented with kivy.clock.Clock
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import NumericProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
Builder.load_string('''
<MainWidget>:
BoxLayout:
orientation: 'vertical'
#! -*- coding:utf8 -*-
def generate_inverse_transformations(left,right):
return (
lambda left: {
'uuid': left.get('key'),
'first_name': left.get('name').get('first'),
'last_name': left.get('name').get('last'),
'triple_tuples': [x for x in left.get('triples').items()],
'opposites': [{'first': x, 'second': y} for x,y in left.get('opposites')]
@casperlehmann
casperlehmann / power_bi_report_change_dataset.py
Created January 25, 2019 11:31
Script to change dataset for a Power BI report
import requests
import adal
import json
# Parameters:
GROUP_ID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# AAD Client ID -- To get this, go here: https://dev.powerbi.com/apps
CLIENT_ID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTHENTICATION_URL = 'https://login.microsoftonline.com/egmont.onmicrosoft.com'
TOKEN = 'XXX'
REPORT_ID = 'YYY'
GROUP_ID = 'ZZZ'
delete_url = f'https://api.powerbi.com/v1.0/myorg/groups/{GROUP_ID}/reports/{REPORT_ID}'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + TOKEN
}
res = requests.post(delete_url, headers=headers)
@casperlehmann
casperlehmann / win-env-var-setter.py
Last active August 23, 2019 13:12
Class for setting, changing and deleting environment variables in Windows Registry
# python
# Borrowing heavily from: https://stackoverflow.com/a/35286642
import winreg
class RegHandler:
def __init__(self, reg_path: str):
self.reg_path = reg_path
def set_reg(self, name, value):
try:
@casperlehmann
casperlehmann / weirdness.py
Created October 17, 2019 20:41
I feel like this shouldn't be allowed
# weirdness.py
def loop_for(i, li=[]):
while len(li) <= i:
print(li)
li[len(li):len(li)+1] = [len(li)]
loop_for(9)
loop_for(9, ['x', 'y', 'z'])
"""
from time import sleep
def count_sheep():
for _ in range(100):
sleep(.01)
yield _
def load_screen(factor = 3):
for counter in count_sheep():
bar = ''.join(['#' if _ < counter/factor else ' ' for _ in range(100//factor)])
DROP EXTERNAL TABLE tests_external_table
DROP EXTERNAL FILE FORMAT file_format_name
DROP EXTERNAL DATA SOURCE extdatasource;
DROP DATABASE SCOPED CREDENTIAL ADLSCredential;
CREATE DATABASE SCOPED CREDENTIAL ADLSCredential
WITH IDENTITY = 'User Identity',
SECRET = '...............=='
@casperlehmann
casperlehmann / git-deployment.md
Created August 24, 2020 20:29 — forked from noelboss/git-deployment.md
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like deepl.io to act upon a Web-Hook that's triggered that service.

@casperlehmann
casperlehmann / bug_report.sql
Last active January 12, 2021 19:25
Synapse Studio throughput issue
-- Querying Delta Lake, 643715 rows
-- Created, optimized and vacuumed with Databricks
-- Partitioned by year and month (filepath 1 and 2)
-- Spark parquet repartition(1) means 1 file per partition
-- Runtime:
-- SSMS: 01:31
-- Synapse Workspace top 5000 rows: 03:15
-- Synapse Workspace all rows: 25:29
-- Hard-coding the partition names makes no discernible difference