Skip to content

Instantly share code, notes, and snippets.

@OmarElawady
OmarElawady / murder.py
Created December 6, 2020 18:23
Murder puzzle using or tools
from ortools.sat.python import cp_model
persons = ['robert', 'john', 'george', 'yolando', 'christine', 'barbara']
rooms = ['kitchen', 'bathroom', 'dining', 'living', 'pantry', 'study']
weapons = ['bag', 'firearm', 'gas', 'knife', 'poison', 'rope']
robert, john, george, yolando, christine, barbara = 0, 1, 2, 3, 4, 5
kitchen, bathroom, dining, living, pantry, study = 0, 1, 2, 3, 4, 5
bag, firearm, gas, knife, poison, rope = 0, 1, 2, 3, 4, 5
@OmarElawady
OmarElawady / minio-log.txt
Created September 15, 2020 11:19
MinIO log
# HELP disk_storage_available Total available space left on the disk
# TYPE disk_storage_available gauge
disk_storage_available{disk=""} 3.221216e+09
# HELP disk_storage_total Total space on the disk
# TYPE disk_storage_total gauge
disk_storage_total{disk=""} 3.221225472e+09
# HELP disk_storage_used Total disk storage used on the disk
# TYPE disk_storage_used gauge
disk_storage_used{disk=""} 9472
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
from jumpscale.loader import j
from time import sleep
import random
import uuid
import os
zos = j.sals.zos
FREEFARM_ID = 71
MAZR3A_ID = 13619
from jumpscale.loader import j
from time import sleep
import random
import uuid
zos = j.sals.zos
FREEFARM_ID = 71
MAZR3A_ID = 13619
@OmarElawady
OmarElawady / smart_pickler.py
Created July 15, 2020 14:46
Epic fails: Smart pickling to preserve references and allow partial random access decoding/
import pickle
from pprint import pprint
import os
import io
class SmartUnpickler(pickle.Unpickler):
def __init__(self):
self.session_reader = SessionReader()
super().__init__(self.session_reader)
@OmarElawady
OmarElawady / time_machine.cpp
Created June 3, 2020 02:34
A design pattern (?) to simplifit checkpointing and rollbacking assignments. Can be useful when implementing backtracking.
#include <bits/stdc++.h>
using namespace std;
template <class T>
class TimeMachine{
private:
class Wrapper{
private:
TimeMachine& tm;
@OmarElawady
OmarElawady / fft.cpp
Created March 28, 2020 12:37
The mysterious minus
#include <bits/stdc++.h>
#include <complex>
using namespace std;
typedef long long ll;
typedef complex<double> Complex;
const Complex J(0, 1);
int logint(int n){
int lg = 0;
while((1 << lg) < n)
from scipy.io.wavfile import read
from scipy.signal import resample
import numpy as np
import math
import sys
if len(sys.argv) < 3:
print("Usage: script <clear.wav> <noisy.wav>")
exit(0)
def unit_vector(vector):
@OmarElawady
OmarElawady / attrdict.py
Last active July 7, 2019 09:14
python implementation of attribute dictionary
class AttrDict:
def __init__(self, normal_dict):
for el in normal_dict:
if type(normal_dict[el]) == dict:
self.__dict__[el] = AttrDict(normal_dict[el])
else:
self.__dict__[el] = normal_dict[el]
def __setitem__(self, key, val):
if type(val) == dict:
#include <bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
struct Node{
int key, pr;
int sz, mx, mn, mnans;
Node* p;
Node* l, *r;