Skip to content

Instantly share code, notes, and snippets.

View casperlehmann's full-sized avatar

Casper Lehmann casperlehmann

View GitHub Profile
#!/usr/bin/env ruby
def mutate_hash_key_and_return_cache
key1 = { k: 1 }
key2 = { k: 2 }
puts "key hash: #{key1.hash} obj_id: #{key1.object_id}" # key hash: 2866644869520814412 obj_id: 60
puts "val hash: #{key2.hash} obj_id: #{key2.object_id}" # val hash: -3505864355511529673 obj_id: 80
cache = { key1 => "x", key2 => "y" }
key2[:k] = 1 # The two keys in the cache now have the same value.
@casperlehmann
casperlehmann / word_filters.py
Created April 21, 2025 16:14
Playing with word filters
#!/usr/bin/env python
# Playing with word filters
# pip install english-words
from english_words import get_english_words_set
web2 = get_english_words_set(['web2'], lower=True)
gcide = get_english_words_set(['gcide'], lower=True)
@casperlehmann
casperlehmann / auto_create_dirs.lua
Created September 22, 2024 15:58
Neovim: Prompt for directory creation when attempting to write to a non-existing path
-- Prompt for directory creation when attempting to save to non-existing location
-- Create an autocommand group, clearing it of any existing commands
vim.api.nvim_create_augroup('CreateMissingDir', { clear = true })
-- Setup an auto command that triggers prior to vim writing a buffer
vim.api.nvim_create_autocmd('BufWritePre', {
-- Specifies that the auto command belongs to the augroup we just created
-- and that it applies to all file types (*)
group = 'CreateMissingDir',
pattern = '*',
16:9
vs Dell P2715Q (Egmont) 27" 100% 16:9 (100:100) | 59x33cm 100x 100% | 2009cm2 100% | 3840x2160px 100x100% | 3600kr (100%) :: Display port | 100%
vs Macbook Dashou 13" 48% 16:9 (100:100) | 28x16cm 48x 48% | 465cm2 23% | 2560x1600px 66x 74% | 12000kr (333%) :: | 48%
vs Dell P2721Q (Mauro) 27" 100% 16:9 (100:100) | 59x33cm 100x 100% | 2009cm2 100% | 3840x2160px 100x100% | 3699kr (102%) :: usb-c | 100%
21:9
vs Samsung C34H890WG 34" 125% 21:9 (131:100) | 79x34cm 132x 101% | 2700cm2 134% | 3440x1440px 89x 66% | 4190kr (116%) :: usb-c | 132%
vs Samsung C34J791 34" 125% 21:9 (131:100) | 79x34cm 132x 101% | 2700cm2 134% | 3440x1440px 89x 66% | 5799kr (161%) :: DP/HDMI/USB-C | 132%
vs Samsung C34G55T 34" 125% 21:9 (131:100) | 79x34cm 132x 101% | 2700cm2 134% | 3440x1440px 89x 66% | 3999kr (111%) :: HDMI/DP | 132%
vs Samsung C34J791WTU 34" 125% 21:9 (131:1
@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
@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.

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 = '...............=='
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)])
@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'])
"""
@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: