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
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 / 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
@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 / 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 / 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 / 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 / things-to-know.md
Created October 22, 2023 19:25
Things to Know for Web Development