├── .github └── workflows │ └── lock.yml ├── README.md ├── comfy_ui_delay_start.py ├── filters.txt ├── jit_calc.cpp ├── merge_pdfs.js ├── onbeforescriptexecute.html ├── renovate.json ├── rrefs.m └── rrefsym.m /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | # Licensed under CC0-1.0 2 | 3 | name: 'Lock Threads' 4 | 5 | on: 6 | schedule: 7 | - cron: '0 */8 * * *' 8 | workflow_dispatch: 9 | 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | discussions: write 14 | 15 | concurrency: 16 | group: lock-threads 17 | 18 | jobs: 19 | action: 20 | runs-on: ubuntu-latest 21 | timeout-minutes: 120 22 | steps: 23 | - uses: dessant/lock-threads@v5 24 | with: 25 | github-token: ${{ github.token }} 26 | issue-inactive-days: '7' 27 | issue-lock-reason: '' 28 | pr-inactive-days: '14' 29 | pr-lock-reason: '' 30 | discussion-inactive-days: '28' 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snippets 2 | 3 | Random code snippets 4 | 5 | Licenses are inside each snippet. License of this README is CC0-1.0. 6 | 7 | Please open an issue if there is something you want me to know. 8 | -------------------------------------------------------------------------------- /comfy_ui_delay_start.py: -------------------------------------------------------------------------------- 1 | # Licensed under CC0-1.0 2 | 3 | import os 4 | import time 5 | 6 | class DelayStart: 7 | def __init__(self): 8 | self.lockfile = f"{os.environ['HOME']}/ComfyUIStartLock" 9 | print(f"DelayStart: Put this node between Latent Image and KSampler, and create {self.lockfile} to delay start") 10 | 11 | @classmethod 12 | def INPUT_TYPES(s): 13 | return { 14 | "required": { 15 | "latent": ("LATENT",), 16 | }, 17 | } 18 | 19 | RETURN_TYPES = ("LATENT",) 20 | FUNCTION = "execute" 21 | CATEGORY = "utils" 22 | 23 | def execute(self, latent): 24 | while os.path.isfile(self.lockfile): 25 | print(f"DelayStart: Remove {self.lockfile} to start") 26 | time.sleep(5) 27 | print(f"DelayStart: Lockfile {self.lockfile} does not exist, starting") 28 | return (latent,) 29 | 30 | NODE_CLASS_MAPPINGS = { 31 | "DelayStart": DelayStart 32 | } 33 | 34 | NODE_DISPLAY_NAME_MAPPINGS = { 35 | "DelayStart": "Delay Start" 36 | } 37 | -------------------------------------------------------------------------------- /filters.txt: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------------------------------------------------- # 2 | 3 | # Title: Personal filters 4 | # Expires: 1 days 5 | # License: GPL-3.0 6 | 7 | # My personal filter list 8 | # https://raw.githubusercontent.com/jspenguin2017/Snippets/master/filters.txt 9 | 10 | # -------------------------------------------------------------------------------------------------------------------- # 11 | 12 | # Annoyances 13 | 14 | # Chat Widgets 15 | ||az.jusbr.com/libs/chatlib/$3p 16 | ||optinchat.com^$3p 17 | 18 | # Overlays 19 | pixiv.net##a[href^="/premium/lead/lp"] 20 | pixiv.net##iframe[src^="https://imp.pixiv.net/premium_lp"] + ul::after 21 | 22 | # Overrides 23 | ||cdnjs.cloudflare.com/ajax/libs/Snowstorm/$script,important,badfilter 24 | pixiv.net#@#section[class] aside[class*="-0 "] > iframe[src^="https://imp.pixiv.net/premium_"][class^="sc-"]:upward(1) 25 | @@||service.force.com/embeddedservice/*/esw.min.js$script,domain=cyberpowersystems.com 26 | @@||zopim.com^$domain=uphold.com 27 | 28 | # -------------------------------------------------------------------------------------------------------------------- # 29 | 30 | # Ads 31 | 32 | # Placeholders 33 | pixiv.net##a[target="premium_noads"] 34 | pixiv.net##iframe[name="expandedFooter"]:upward(1) 35 | linkedin.com###voyager-feed > #voyager-feed:style(padding: 0px !important;) 36 | linkedin.com###voyager-feed:style(padding: 16px !important;) 37 | researchgate.net##.lite-page__header-navigation--with-ad:style(top: 0px !important;) 38 | 39 | # -------------------------------------------------------------------------------------------------------------------- # 40 | 41 | # Security 42 | 43 | # Bad websites 44 | ||dcdirtylaundry.com^$doc 45 | ||udemy.com^$doc 46 | 47 | # NSFW bad websites 48 | ||erogazopple.com^$doc 49 | ||erogazoufactory.com^$doc 50 | 51 | # -------------------------------------------------------------------------------------------------------------------- # 52 | 53 | # Other 54 | 55 | # Incorrect touch input detection 56 | pixiv.net##button:has(> div > svg):style(display: initial !important;) 57 | pixiv.net##div:has(> button > div > svg):style(display: initial !important;) 58 | 59 | # Unbreak 60 | outlook.live.com#@##app div[class] > div[role="region"] ~ div[class]:not([data-max-width]):not([role]):has(div[class] > img[aria-label][src*="adbar"]) 61 | 62 | # -------------------------------------------------------------------------------------------------------------------- # 63 | -------------------------------------------------------------------------------- /jit_calc.cpp: -------------------------------------------------------------------------------- 1 | // Licensed under CC0-1.0 2 | 3 | #pragma warning(disable : 4996) 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #define MAX_OPERAND_LENGTH 4 12 | 13 | typedef unsigned char byte; 14 | typedef void(*pFunc)(void); 15 | union Function 16 | { 17 | pFunc execute; 18 | byte* payload; 19 | }; 20 | 21 | void pause() 22 | { 23 | std::cout << "Press any key to exit..."; 24 | getch(); 25 | } 26 | 27 | bool fetchInt(std::string& str, size_t& strLen, size_t& iterator, int& out) 28 | { 29 | char buffer[MAX_OPERAND_LENGTH]; 30 | int i; 31 | for (i = 0; i < MAX_OPERAND_LENGTH; i++) 32 | { 33 | while (str[iterator] == ' ' && iterator < strLen) 34 | { 35 | iterator++; 36 | } 37 | if (iterator >= strLen) 38 | { 39 | break; 40 | } 41 | char temp = str[iterator]; 42 | if (temp < 48 || temp > 57) 43 | { 44 | break; 45 | } 46 | buffer[i] = temp - 48; 47 | iterator++; 48 | } 49 | if (i == 0) 50 | { 51 | std::cout << "Unexpected character or end of input at position " << iterator << std::endl; 52 | return false; 53 | } 54 | out = 0; 55 | for (int j = 0; j < i; j++) 56 | { 57 | out *= 10; 58 | out += (int)buffer[j]; 59 | } 60 | return true; 61 | } 62 | 63 | int main() 64 | { 65 | // Startup 66 | SetConsoleTitle(TEXT("JIT Compiling Calculator")); 67 | std::cout << "This is probably the most useless tool ever" << std::endl; 68 | std::cout << "It can only do 1 to 4 digits multiplication, enter something like \"125 * 20\" and see if it works" << std::endl; 69 | 70 | // Get user input 71 | std::string str; 72 | std::getline(std::cin, str); 73 | 74 | // Prepare variables 75 | size_t iterator = 0; 76 | size_t strLen = str.length(); 77 | int op1, op2; 78 | int JITReturn; 79 | 80 | // Prepare JIT payload buffer 81 | // http://ref.x86asm.net/coder32.html 82 | byte* payload = (byte*)VirtualAllocEx(GetCurrentProcess(), 0, 512, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 83 | 84 | // Check if memory allocation succeeded 85 | if (payload == NULL) 86 | { 87 | // Failed, cannot even get 512 bytes of memory... 88 | std::cout << "Could not allocate JIT memory" << std::endl; 89 | pause(); 90 | return 1; 91 | } 92 | else 93 | { 94 | byte* p = payload; 95 | 96 | // Prepare 97 | *p++ = 0x50; // Push EAX 98 | *p++ = 0x52; // Push EDX 99 | 100 | // Put in first operand 101 | *p++ = 0xA1; // Mov EAX, (operand1) 102 | if (!fetchInt(str, strLen, iterator, op1)) 103 | { 104 | pause(); 105 | return 1; 106 | } 107 | (int*&)p[0] = &op1; p += sizeof(int*); 108 | 109 | // Move it over 110 | *p++ = 0x92; // Xchg EDX, EAX 111 | 112 | // Get operator 113 | while (str[iterator] == ' ' && iterator < strLen) 114 | { 115 | iterator++; 116 | } 117 | if (iterator >= strLen || str[iterator] != '*') 118 | { 119 | // Only multiplication is supported 120 | std::cout << "Unexpected character or end of input at position " << iterator << std::endl; 121 | pause(); 122 | return 1; 123 | } 124 | iterator++; 125 | 126 | // Put in second operand 127 | *p++ = 0xA1; // Mov EAX, (operand2) 128 | if (!fetchInt(str, strLen, iterator, op2)) 129 | { 130 | pause(); 131 | return 1; 132 | } 133 | (int*&)p[0] = &op2; p += sizeof(int*); 134 | 135 | // Do multiplication 136 | *p++ = 0xF7; *p++ = 0xEA; // Imul EDX 137 | 138 | // Return result 139 | *p++ = 0xA3; // Mov (JITReturn), EAX 140 | (int*&)p[0] = &JITReturn; p += sizeof(int*); 141 | 142 | // Clean up 143 | *p++ = 0x5A; // Pop EDX 144 | *p++ = 0x58; // Pop EAX 145 | *p++ = 0xC3; // Ret 146 | 147 | // Execute payload 148 | Function f; 149 | f.payload = payload; 150 | f.execute(); 151 | 152 | // Print result 153 | std::cout << JITReturn << std::endl; 154 | pause(); 155 | return 0; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /merge_pdfs.js: -------------------------------------------------------------------------------- 1 | // Licensed under CC0-1.0 2 | // 3 | // Merge all PDF files in a directory into one file, sorted by file name 4 | 5 | "use strict"; 6 | 7 | const cp = require("child_process"); 8 | const fs = require("fs"); 9 | 10 | let input = process.argv[2]; 11 | let output = process.argv[3]; 12 | 13 | if (!input || !output) { 14 | console.log("Usage:"); 15 | console.log(" node merge_pdfs.js input_dir output_file"); 16 | process.exit(1); 17 | } 18 | 19 | input = input.trim(); 20 | output = output.trim(); 21 | 22 | let list = fs.readdirSync(input); 23 | list = list.sort().filter(elem => { 24 | if (elem === output) { 25 | console.log("Input files list contains the output file. Aborting."); 26 | process.exit(1); 27 | } 28 | 29 | if (elem.endsWith(".pdf")) { 30 | return true; 31 | } else { 32 | console.log("Ignoring non-pdf entry: " + elem); 33 | return false; 34 | } 35 | }); 36 | 37 | console.log("Merging these PDF files:"); 38 | console.log(list); 39 | 40 | list.push(output); 41 | 42 | console.log("Starting to execute command."); 43 | const result = cp.spawnSync("pdfunite", list); 44 | console.log("Finished, result:"); 45 | console.log(result); 46 | 47 | console.log("If it did not work, try to install pdfunite:"); 48 | console.log(" sudo apt install poppler-utils"); 49 | console.log("Also, some PDF files (such as encrypted ones) are not supported by pdfunite."); 50 | -------------------------------------------------------------------------------- /onbeforescriptexecute.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "hugoxu" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /rrefs.m: -------------------------------------------------------------------------------- 1 | function out = rrefs (mat, reduce) 2 | % RREFS Reduced Row Echelon Form with Steps 3 | % License: GPL-3.0 4 | % out = rrefs(mat, reduce) show step by step procedure to get to (reduced) 5 | % row echelon form of matrix mat, then return manipulated matrix. 6 | % WARNING: This function may not be reliable for some matrices. 7 | 8 | % The user would usually benefit from rational formatting 9 | format rat; 10 | 11 | % Save a copy of old matrix for comparizion 12 | oldmat = mat; 13 | % Cache size 14 | [row, col] = size(mat); 15 | % Leading entry row counter 16 | leading = 1; 17 | % Loop through each colomn 18 | if (reduce) 19 | a = col; 20 | else 21 | a = col - 1; 22 | end % if 23 | for c = 1:a 24 | % Find the first non-zero entry and put to top 25 | if (mat(leading, c) == 0) 26 | % Skip if all zeros 27 | if (mat(leading:row, c) == zeros(size(leading:row))') 28 | continue; 29 | end % if 30 | % Get leading entry to 1 31 | for r = leading:row 32 | if (mat(r, c) ~= 0) 33 | mat = ro_swap(mat, leading, r); 34 | break; 35 | end % if 36 | end % for 37 | end % if 38 | % Check if the leading entry is here 39 | if (mat(leading, c) ~= 0) 40 | % Scale the leading entry 41 | if (mat(leading, c) ~= 1) 42 | mat = ro_scale(mat, leading, 1/mat(leading, c)); 43 | end % if 44 | % Zero out other rows 45 | if (reduce) 46 | a = 1; 47 | else 48 | a = leading + 1; 49 | end % if 50 | for r = a:row 51 | % Don't remove leading entry, ignore if it's zero already 52 | if (r == leading || mat(r, c) == 0) 53 | continue; 54 | end % if 55 | % Zero out the row 56 | mat = ro_add(mat, r, leading, -1 * mat(r, c)); 57 | end % for 58 | end % if 59 | % Change leading counter 60 | leading = leading + 1; 61 | if (leading > row) 62 | break; 63 | end % if 64 | end % if 65 | % Assign return matrix 66 | out = mat; 67 | % Show results from built in function 68 | disp('Done! Result of built in rref(): '); 69 | disp(rref(oldmat)); 70 | 71 | % Reset formatting 72 | format short; 73 | end % function 74 | 75 | function out = ro_add (mat, r_target, r_source, factor) 76 | % Add row r_source times factor to row r_target 77 | out = mat; 78 | out(r_target, :) = out(r_target, :) + factor * out(r_source, :); 79 | % Log 80 | fprintf('R%d + (%s)R%d -> R%d\n', r_target, strtrim(rats(factor)), ... 81 | r_source, r_target); 82 | disp(out); 83 | end % function 84 | 85 | function out = ro_scale (mat, r, factor) 86 | % Multiply row r by factor 87 | out = mat; 88 | out(r, :) = out(r, :) * factor; 89 | % Log 90 | fprintf('(%s)R%d -> R%d\n', strtrim(rats(factor)), r, r); 91 | disp(out); 92 | end % function 93 | 94 | function out = ro_swap (mat, r1, r2) 95 | % Swap row r1 with row r2 96 | out = mat; 97 | out(r1, :) = mat(r2, :); 98 | out(r2, :) = mat(r1, :); 99 | % Log 100 | fprintf('R%d <-> R%d\n', r1, r2); 101 | disp(out); 102 | end % function 103 | -------------------------------------------------------------------------------- /rrefsym.m: -------------------------------------------------------------------------------- 1 | function out = rrefsym (mat, reduce) 2 | % RREFSYM Reduced Row Echelon Form with Symbolic Steps 3 | % License: GPL-3.0 4 | % out = rrefs(mat, reduce) show step by step procedure to get to (reduced) 5 | % row echelon form of symbolic matrix mat, then return manipulated matrix. 6 | % Please load and initialize symbolic package before calling this function, 7 | % matrix that is passed in needs to be already symbolic. 8 | % WARNING: This function may not be reliable for some matrices. 9 | 10 | % Save a copy of old matrix for comparizion 11 | oldmat = mat; 12 | % Cache size 13 | [row, col] = size(mat); 14 | % Leading entry row counter 15 | leading = 1; 16 | % Loop through each colomn 17 | if (reduce) 18 | a = col; 19 | else 20 | a = col - 1; 21 | end % if 22 | for c = 1:a 23 | % Find the first non-zero entry and put to top 24 | if (mat(leading, c) == 0) 25 | % Skip if all zeros 26 | if (mat(leading:row, c) == zeros(size(leading:row))') 27 | continue; 28 | end % if 29 | % Get leading entry to 1 30 | for r = leading:row 31 | if (mat(r, c) ~= 0) 32 | mat = ro_swap(mat, leading, r); 33 | break; 34 | end % if 35 | end % for 36 | end % if 37 | % Check if the leading entry is here 38 | if (mat(leading, c) ~= 0) 39 | % Scale the leading entry 40 | if (mat(leading, c) ~= 1) 41 | mat = ro_scale(mat, leading, 1/mat(leading, c)); 42 | end % if 43 | % Zero out other rows 44 | if (reduce) 45 | a = 1; 46 | else 47 | a = leading + 1; 48 | end % if 49 | for r = a:row 50 | % Don't remove leading entry, ignore if it's zero already 51 | if (r == leading || mat(r, c) == 0) 52 | continue; 53 | end % if 54 | % Zero out the row 55 | mat = ro_add(mat, r, leading, -1 * mat(r, c)); 56 | end % for 57 | end % if 58 | % Change leading counter 59 | leading = leading + 1; 60 | if (leading > row) 61 | break; 62 | end % if 63 | end % if 64 | % Assign return matrix 65 | out = mat; 66 | % Show results from built in function 67 | disp('Done! Result of built in rref(): '); 68 | disp(rref(oldmat)); 69 | 70 | % Reset formatting 71 | format short; 72 | end % function 73 | 74 | function out = ro_add (mat, r_target, r_source, factor) 75 | % Add row r_source times factor to row r_target 76 | out = mat; 77 | out(r_target, :) = out(r_target, :) + factor * out(r_source, :); 78 | % Log 79 | fprintf('R%d + (a)R%d -> R%d, where a =\n', r_target, r_source, r_target); 80 | disp(factor); 81 | disp(''); 82 | disp(out); 83 | disp(''); 84 | end % function 85 | 86 | function out = ro_scale (mat, r, factor) 87 | % Multiply row r by factor 88 | out = mat; 89 | out(r, :) = out(r, :) * factor; 90 | % Log 91 | fprintf('(a)R%d -> R%d, where a =\n', r, r); 92 | disp(factor); 93 | disp(''); 94 | disp(out); 95 | disp(''); 96 | end % function 97 | 98 | function out = ro_swap (mat, r1, r2) 99 | % Swap row r1 with row r2 100 | out = mat; 101 | out(r1, :) = mat(r2, :); 102 | out(r2, :) = mat(r1, :); 103 | % Log 104 | fprintf('R%d <-> R%d\n', r1, r2); 105 | disp(''); 106 | disp(out); 107 | disp(''); 108 | end % function 109 | --------------------------------------------------------------------------------