Skip to content

Instantly share code, notes, and snippets.

View silashansen's full-sized avatar

Silas Hansen silashansen

View GitHub Profile
@silashansen
silashansen / gist:08bb935c0d165a35cf69cf5cbeb02cc5
Last active July 15, 2022 08:00 — forked from luckydev/gist:b2a6ebe793aeacf50ff15331fb3b519d
Nginx Increase max no of open files limit - Ubuntu 16.04
# maximum capability of system
user@ubuntu:~$ cat /proc/sys/fs/file-max
708444
# available limit
user@ubuntu:~$ ulimit -n
1024
# To increase the available limit to say 200000
user@ubuntu:~$ sudo vim /etc/sysctl.conf
@silashansen
silashansen / 1-docker-compose.yml
Last active March 23, 2021 16:01
Clickhouse cluster with Zookeeper
version: '3.9'
services:
clickhouse-server1:
image: yandex/clickhouse-server
ports:
- "8123:8123"
volumes:
- ./config.xml:/etc/clickhouse-server/config.xml
ulimits:
@silashansen
silashansen / 1-Example.cs
Last active July 15, 2022 07:59
ES Scroll Query Helper
public static void Main()
{
var esClient = new ElasticClient(new Uri("http://localhost:9200"));
var response = esClient
.Search<object>(s => s
.Index("sample_index")
.AllTypes()
.Scroll("1m"));
@silashansen
silashansen / Program.cs
Created June 7, 2021 13:02
Benchmark IsEmptyString function
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MemoryTestSandbox
{
@silashansen
silashansen / clickhouse-server.log
Last active June 24, 2021 11:24
Clickhouse log
2021.06.24 08:39:52.882235 [ 49925 ] {} <Debug> MergeTreeSequentialSource: Reading 2 marks from part 202106_330750_330750_0, total 54 rows starting from the beginning of the part
2021.06.24 08:39:52.893411 [ 49925 ] {} <Debug> analytics.events_local (8fcee572-2b74-42f2-8fce-e5722b74c2f2) (MergerMutator): Merge sorted 2913 rows, containing 46 columns (46 merged, 0 gathered) in 0.012852513 sec., 226648.28271327174 rows/sec., 94.10 MiB/sec.
2021.06.24 08:39:52.914845 [ 49925 ] {} <Trace> analytics.events_local (8fcee572-2b74-42f2-8fce-e5722b74c2f2): Renaming temporary part tmp_merge_202106_330565_330750_17 to 202106_330565_330750_17.
2021.06.24 08:39:52.914934 [ 49925 ] {} <Trace> analytics.events_local (8fcee572-2b74-42f2-8fce-e5722b74c2f2) (MergerMutator): Merged 5 parts: from 202106_330565_330743_16 to 202106_330750_330750_0
2021.06.24 08:39:52.918118 [ 49925 ] {} <Debug> MemoryTracker: Peak memory usage: 12.40 MiB.
2021.06.24 08:39:53.272905 [ 49929 ] {} <Trace> system.metric_log (22746af7-8e26-4b0f-a274-6af
@silashansen
silashansen / Jira To Sheet Pivot Formlas
Last active October 10, 2022 07:54
Added days until done
//Name
=IFNA(QUERY('Jira sync'!A:O, "select O where B = '"& parent & "' AND A = 'Epic' LIMIT 1",0), "")
//Project
=IFNA(QUERY('Jira sync'!A:C, "select C where B = '"& parent & "' AND A = 'Epic' LIMIT 1",0), 0)
//Risk
=IFNA(QUERY('Jira sync'!A:M, "select M where B = '"& parent & "' AND A = 'Epic' LIMIT 1",0), 0)
//Risk Reasoning
@silashansen
silashansen / app.py
Last active August 11, 2023 12:03
mDNS local network discovery
from zeroconf import ServiceBrowser, ServiceListener, Zeroconf, ZeroconfServiceTypes
class MyListener(ServiceListener):
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
info = zc.get_service_info(type_, name)
print("Updated: \t", format_info(info))
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
@silashansen
silashansen / api_tests.py
Created August 18, 2023 08:13
Webshop tests
# BEGIN: 8f7d6h3j4k5l
import unittest
import requests
import jwt
import time
class TestAPI(unittest.TestCase):
token = None
api_basepath = "https://api-test.xl-byg.dk"
@silashansen
silashansen / device_tracker_agg.sql
Created August 25, 2023 23:50
Home Assistant Device tracker state duration aggregation for SQLite
WITH p AS (
WITH q AS (
WITH y AS (
WITH x as (
SELECT
sm.entity_id,
s.state,
s.last_updated_ts,
COALESCE(LAG(s.state) OVER (partition by sm.entity_id ORDER BY last_updated_ts ASC), s.state) as last_state
FROM states s
@silashansen
silashansen / elevator.js
Created August 25, 2023 23:57
Elevator Saga
{
init: function(elevators, floors) {
// helper function to check if a floor is already queued
function isFloorQueued(elevator, floorNum) {
return elevator.destinationQueue.indexOf(floorNum) > -1;
}
function isFloorQueuedForAnyElevator(floorNum) {
for (let e = 0; e < elevators.length; e++) {