Skip to content

Instantly share code, notes, and snippets.

View syxolk's full-sized avatar
🏠
Working from home

Hans syxolk

🏠
Working from home
  • Germany
View GitHub Profile
@syxolk
syxolk / things-to-know.md
Created October 22, 2023 19:25
Things to Know for Web Development
@syxolk
syxolk / MapOfComplexData.ts
Created June 2, 2022 23:33
Generic JS Map for complex key types
class MapOfComplexData<
Key,
Value,
HashFn extends (key: Key) => number = (key: Key) => number,
EqualsFn extends (objA: Key, objB: Key) => boolean = (objA: Key, objB: Key) => boolean
> {
private _data = new Map<number, {key: Key; value: Value}[]>();
private _size: number = 0;
private hashCode: HashFn;
private equals: EqualsFn;
@syxolk
syxolk / keyof-trick.ts
Created January 29, 2020 08:31
Typescript keyof and "valueof"
type Employee = {
canWalkVeryFast: boolean;
numberOfKeystrokes: number;
isNiceToTheBoss: "yes" | "no" | "sometimes";
};
function foobar<T extends keyof Employee>(key: T, value: Employee[T]) {
console.log(key, value);
}
@syxolk
syxolk / intersection.vba
Created November 7, 2019 16:53
VBA Set Intersections
Option Explicit
Sub IntersectionMacro()
Dim set1 As New Scripting.Dictionary
Dim set2 As New Scripting.Dictionary
Dim result As New Scripting.Dictionary
set1.Add "M AB 123", ""
set1.Add "M CD 456", ""
@syxolk
syxolk / cplex_logical_and.py
Created August 21, 2019 11:28
CPLEX logical_and does not work
from docplex.mp.model import Model
m = Model("test")
a = m.binary_var(name="a")
b = m.binary_var(name="b")
c = m.binary_var(name="c")
m.add_constraint(m.logical_and(a, b) == c)
m.add_constraint(a == 1)
@syxolk
syxolk / minimal_example.py
Last active April 4, 2019 18:29
OR-Tools Indeterministic solution_hint bug
from ortools.sat.python import cp_model
COUNTS = 10
MIN_VAL = 2
MAX_VAL = 4
class Slot:
def __init__(self,model):
self.model = model
self.start = model.NewIntVar(-1,COUNTS-1,name="")#inclusive
const arr = [1,1,0,0,1,1,1,0,1];
function sumConsecutiveOnes(arr) {
return [...arr, 0].reduce((acc, value) => {
if(value === 1) {
acc.counter += 1;
} else if(acc.counter > 0) {
acc.output.push(acc.counter);
acc.counter = 0;
}
@syxolk
syxolk / RemoveAllTest.java
Created December 17, 2018 09:56
removeAll on keySet (with hashCode)
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RemoveAllTest {
public static void main(String[] args) {
@syxolk
syxolk / upgrade-postgres.md
Last active July 18, 2022 11:32
Upgrade Postgresql 10 to 11 on Arch Linux

This guide is mainly based on Arch's wiki, with some additions:

  • I couldn't upgrade the database because the upgrade tool needs the postgis-2.4.so file
  • The created cluster could not be used to upgrade from the old data because the locale was set to 'C' (needed to add --locale=en_US.UTF-8)
  • The upgrade tool checks if the the new postgresql installation has a compatible postgis version. That means we need postgis 2.4 for postgresql 11. Unfortunately, we cannot install it over the package manager, instead we need to compile it from source.
# Stop currently running server
systemctl stop postgresql.service

# Install new packages
@syxolk
syxolk / install-linux.md
Last active October 16, 2022 19:56
Install Linux on Lenovo V330-14IKB

Here's what I've done to install Ubuntu 18.04. on a Lenovo V330-14IKB laptop. The problem was that the live Ubuntu could not find the NVMe drive.

How get in the BIOS settings:

  • In Windows: Open the Recovery page in the system settings
  • Click "Restart Now"
  • Go to "Troubleshoot" and restart to UEFI settings screen

This guide is not comprehensive and/or correct but may help you to get started:

  1. Go to the BIOS -> Security -> Secure Boot -> Set to Disable