Skip to content

Instantly share code, notes, and snippets.

@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"];
@IvanaGyro
IvanaGyro / Issue about selecting SVG.POWERPOINT.yaml
Created February 21, 2023 15:35
Demo the issue about selecting SVG.
name: Issue about selecting SVG
description: Demo the issue about selecting SVG.
host: POWERPOINT
api_set: {}
script:
content: >+
$("#run").click(() => tryCatch(run));
const run: Function = async () => {
@IvanaGyro
IvanaGyro / Formulas for Word.WORD.yaml
Last active February 26, 2023 10:56
Insert math equations into the online version of Word.
name: Formulas for Word
description: Insert math equations into the online version of Word.
host: WORD
api_set: {}
script:
content: >
var editor;
const MathJax = window["MathJax"];
@IvanaGyro
IvanaGyro / find_kobo_lowest_price.js
Created December 23, 2022 18:56
找 Kobo 上面最便宜的國家
/**
* 1. Get current rates from https://www.xe.com/api/protected/midmarket-converter/
* 2. Replace "rates" object with the correct currency rates.
* 3. Select a book on Kobo.
* 4. Click the country flag at the top right corner.
* 5. Execute this script.
*/
rates = {
ADA: 3.8456167243,