Skip to content

Instantly share code, notes, and snippets.

@IvanaGyro
IvanaGyro / quantum_random_walk.py
Created March 15, 2025 08:20
Demo the discrete quantum random walk with a Hadamard coin.
import numpy as np
from collections import defaultdict
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def hadamard_walk(
state: dict[tuple[int, int], np.complex128]
) -> dict[tuple[int, int], np.complex128]:
new_state = defaultdict(lambda: np.complex128(0))
@IvanaGyro
IvanaGyro / crawler.js
Created February 26, 2025 14:19
Crawler for Microsoft Teams Channel Posts
/**
* Crawler for Microsoft Teams Channel Posts
*
* This script uses Puppeteer to automate a browser session, crawl a specified Microsoft Teams channel,
* extract posts along with their attachments and images, convert post content from HTML to Markdown, and
* then save the results as JSON, YAML, and Markdown files.
*
* Steps to use this script:
* 1. Install Node.js and all required modules.
* 2. Run the script using the command: `node crawler.js`.
@IvanaGyro
IvanaGyro / dynamic_type_traits.cpp
Last active November 25, 2024 17:15
Dynamically get type traits of the data type.
#include <iostream>
#include <tuple>
#include <array>
#include <complex>
using TypeList = std::tuple<void, double, std::complex<float>, int, bool>;
template <typename T>
@IvanaGyro
IvanaGyro / combine_a5.py
Created October 20, 2023 05:39
Combine two A5 PDF pages to one A4 PDF page.
from pathlib import Path
from pikepdf import *
a5_pdf_path = Path('A5_PDF_PATH')
a4_output_path = Path('A4_OUTPUT_PATH')
a4_pdf = Pdf.new()
a4_pdf.add_blank_page(page_size=(595, 842))
destination_page = a4_pdf.pages[0]
@IvanaGyro
IvanaGyro / matrix_product_state.py
Created August 16, 2023 01:29
Decompose states into matrix product states.
from functools import reduce
import numpy as np
s = np.random.randn(8).reshape(2,2,2)
u, e, v = np.linalg.svd(s.reshape(2, 4), full_matrices=False)
a1 = u
s2 = np.tensordot(np.diag(e), v, axes=(-1, 0))
@IvanaGyro
IvanaGyro / rate.py
Created July 12, 2023 15:09
Calculate how much money to deposit in a fixed deposit account in order to earn the maximum amount of interest after rounding up or down.
import math
def actual_final(month, rate, save):
current = save
for _ in range(month):
current = round(current * (1 + rate / 100 / 12))
return current
@IvanaGyro
IvanaGyro / toggle_igcc_hotkey.py
Created July 12, 2023 11:36
A pywinauto example for toggling the hotkey feature of Intel® Graphics Command Center
# This script is an workaround for the hotkey binding problem reported in 2020.09.
# See: https://community.intel.com/t5/Graphics/Keyboard-problem-with-quot-Intel-Graphics-Command-Center-quot/m-p/1212469
from pywinauto.application import Application
from pywinauto.timings import always_wait_until_passes
main_app = Application(backend='uia').start('explorer.exe shell:appsFolder\AppUp.IntelGraphicsExperience_8j3eq9eme6ctt!App')
@always_wait_until_passes(30, 1)
def toggle_hotkey():
@IvanaGyro
IvanaGyro / download.py
Last active June 28, 2023 20:56
Download video on NTU COOL
import os
import urllib.request
import threading
import sys
def filenames(type):
yield f'{type}-1080-init.m4s.mp4'
id = 1
while True:
@IvanaGyro
IvanaGyro / Formulas for PowerPoint.POWERPOINT.yaml
Last active February 26, 2023 10:57
Insert math equations into the online version of PowerPoint.
name: Formulas for PowerPoint
description: Insert math equations into the online version of PowerPoint.
host: POWERPOINT
api_set: {}
script:
content: |
var editor;
const MathJax = window["MathJax"];
const ace = window["ace"];
const toastr = window["toastr"];