Skip to content

Instantly share code, notes, and snippets.

@simrit1
simrit1 / image_grid.py
Created January 24, 2022 05:39 — forked from MaxvanHaastrecht/image_grid.py
Creating a grid of images
from PIL import Image
# Load created images; for example 4
amsterdam = Image.open('Amsterdam.png')
hague = Image.open('The_Hague.png')
rotterdam = Image.open('Rotterdam.png')
utrecht = Image.open('Utrecht.png')
# Retrieve width and height original images
width = amsterdam.size[0]
@simrit1
simrit1 / street_map.py
Created January 24, 2022 05:39 — forked from MaxvanHaastrecht/street_map.py
Importing roads and plotting as a city street map
import geopandas as gpd
import matplotlib.pyplot as plt
# Import all roads NL
map_df = gpd.read_file('roads.shp')
# Show data format
map_df.head()
# Set image properties
fig, ax = plt.subplots(1, figsize=(10,14))
@simrit1
simrit1 / expanding_nebula.py
Created February 9, 2022 22:10 — forked from lotabout/expanding_nebula.py
Solution for google foobar: Expanding Nebula
def generate(c1,c2,bitlen):
a = c1 & ~(1<<bitlen)
b = c2 & ~(1<<bitlen)
c = c1 >> 1
d = c2 >> 1
return (a&~b&~c&~d) | (~a&b&~c&~d) | (~a&~b&c&~d) | (~a&~b&~c&d)
from collections import defaultdict
def build_map(n, nums):
mapping = defaultdict(set)
@simrit1
simrit1 / fastSqrt.cpp
Created February 12, 2022 23:31 — forked from Biendeo/fastSqrt.cpp
Carmack Fast Inverse Square Root
#include <iostream>
#include <cmath>
#include <iomanip>
#include <atomic>
#include <mutex>
#include <thread>
#include <condition_variable>
#include <sstream>
#include <vector>
#include <fstream>
@simrit1
simrit1 / draw_cesaro_fractal.py
Created February 15, 2022 05:27 — forked from cbhyphen/draw_cesaro_fractal.py
cesaro-fractal-turtle
#!/usr/bin/python
import turtle
def draw_cesaro_line(turtle, level, length):
if level == 0:
turtle.forward(length)
@simrit1
simrit1 / Brute Force and Exhaustive Search.ipynb
Created February 22, 2022 20:36 — forked from sheikhhanif/Brute Force and Exhaustive Search.ipynb
Brute Force and Exhaustive Search in Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simrit1
simrit1 / stress_test.py
Created March 1, 2022 17:20 — forked from mda590/stress_test.py
Python script useful for stress testing systems
"""
Produces load on all available CPU cores.
Requires system environment var STRESS_MINS to be set.
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
import time
import os
@simrit1
simrit1 / 00_nandgame.com_answer.adoc
Created March 10, 2022 22:14 — forked from orumin/00_nandgame.com_answer.adoc
Optimal answer for Nandgame.com

Invert

01 inv

And

02 and

Or

import numpy as np
import matplotlib.pyplot as plt
def normalize(vector):
return vector / np.linalg.norm(vector)
def reflected(vector, axis):
return vector - 2 * np.dot(vector, axis) * axis
def sphere_intersect(center, radius, ray_origin, ray_direction):