Skip to content

Instantly share code, notes, and snippets.

# solver for https://hard.mathler.com
# copyright@gooooloo
import random
def answer_to_score(answer):
ret = 0
for ch in answer:
ret <<= 2
if ch == 'g':
@gooooloo
gooooloo / groupThenUnGroupSimple.EXCEL.yaml
Created June 24, 2021 01:51
Clicking the button, then ungroup the PT,
name: groupThenUnGroupSimple
description: 'Clicking the button, then ungroup the PT,'
host: EXCEL
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
async function setup() {
await Excel.run(async (context) => {
@gooooloo
gooooloo / groupThenUnGroup.EXCEL.yaml
Created June 21, 2021 09:01
Clicking the button, then ungroup the PT, check the content
name: groupThenUnGroup
description: 'Clicking the button, then ungroup the PT, check the content'
host: EXCEL
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
async function setup() {
await Excel.run(async (context) => {
@gooooloo
gooooloo / Create and modify (1).EXCEL.yaml
Last active May 18, 2021 09:26
Creates and modifies a PivotTable.
name: Create and modify (1)
description: Creates and modifies a PivotTable.
host: EXCEL
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
async function setup() {
await Excel.run(async (context) => {
@gooooloo
gooooloo / pdf_to_txt.py
Created February 13, 2021 06:31
script extract text in pdf to text file
#!/usr/bin/python3
import sys
from PDFNetPython3 import *
def main():
if len(sys.argv) < 3:
print("Usage: python3 pdf_to_txt.py path_to_pdf path_to_txt")
return
@gooooloo
gooooloo / utf8_to_unicode.py
Created November 9, 2020 17:06
convert hex utf-8 bytes to hex Unicode number
import sys
def ch2int(ch):
if '0' <= ch <= '9':
return ord(ch) - ord('0')
if 'a' <= ch <= 'f':
return ord(ch) - ord('a') + 10
if 'A' <= ch <= 'F':
return ord(ch) - ord('A') + 10
@gooooloo
gooooloo / visual_studio_projects_dependency.py
Last active July 27, 2020 16:15
In some of visual studio solution I met, there are very much more projects inside. This is a simple script to extract and simplify the dependencies and generate VBA of Visio to draw the diagram better visualization.
import re
import os
import sys
def vba_vso_name(text):
ans = text.replace(' ', '_').replace('.', '_')
assert re.compile(r'^\w*$').match(ans)
return ans
def generate_VBA(d_dir_dep):
@gooooloo
gooooloo / simple_tklb.py
Last active July 14, 2020 11:26
my simple tkinter Listbox GUI
def simple_tklb(fn_get_list, fn_double_click_item):
from tkinter import Tk, Listbox
tk = Tk()
lb = Listbox(tk)
for idx, item in enumerate(fn_get_list()):
lb.insert(idx, item)
def onselect(event):
@gooooloo
gooooloo / var_arg_func_ptr_demo.cpp
Created November 12, 2019 02:33
可变长函数指针
#include <stdio.h>
#include <stdarg.h>
typedef void (*f_type)(int, ...);
void foo1(int n1) { printf("%d\n", n1); }
void foo2(int n1, int n2) { printf("%d %d\n", n1, n2); }
void foo3(int n1, int n2, int n3) { printf("%d %d %d\n", n1, n2, n3); }
void bar(f_type pf, ...) {
if ((void *)pf == (void *)foo1) {
@gooooloo
gooooloo / memleak.cpp
Last active July 24, 2019 11:43
a memory leak example in practice
/**
* Here is an example of mem leak I met today. I didn't write the codes, I just help finding the memleak.
* Of course the real code is much more complicated, I simplify it here.
*
* To prove there is memleak, just compile and run:
* $ gcc a.cpp --std=c++11 -lstdc++ && ./a.out
*
* And you will see below:
* 4 bytes leaked.
*