Skip to content

Instantly share code, notes, and snippets.

@SCP002
SCP002 / write_to_stdin_posix.go
Last active January 11, 2025 09:02
Golang: Write a message to any console's input on POSIX.
//go:build !windows
// Used in https://github.com/SCP002/terminator.
// For Windows, see: https://gist.github.com/SCP002/1b7fd91a519a2dc60fc5b179f90472b6.
package main
import (
"fmt"
"os"
@SCP002
SCP002 / disable-windows-10-updates.reg
Last active June 19, 2021 18:58
Windows Registry: Disable Windows 10 updates.
Windows Registry Editor Version 5.00
; Disable Windows 10 updates.
; To enable it back, delete these values.
; Tested with Windows 10 Pro 20H2, build 19042.1052
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"DoNotConnectToWindowsUpdateInternetLocations"=dword:00000001
@SCP002
SCP002 / get_process_tree.go
Last active January 11, 2025 09:05
Golang: Get all descendants of the specified process.
// Used in https://github.com/SCP002/terminator.
package main
import (
"errors"
"fmt"
"github.com/shirou/gopsutil/v4/process"
)
@SCP002
SCP002 / init_console_handlers_windows.go
Last active January 11, 2025 09:26
Golang: Initialize console handlers after AttachConsole or AllocConsole on Windows.
// Used in https://github.com/SCP002/terminator.
package main
import (
"errors"
"os"
"golang.org/x/sys/windows"
)
@SCP002
SCP002 / write_to_stdin_windows.go
Last active January 11, 2025 09:28
Golang: Write a message to the current (see comments for a method for any console) console's input on Windows.
//go:build windows
// Used in https://github.com/SCP002/terminator.
// For POSIX, see: https://gist.github.com/SCP002/c7c3bf4aafd3e32e0dc0aa65dda2bf14.
package main
import (
"errors"
"os"
@SCP002
SCP002 / send_wm_close_windows.go
Last active January 11, 2025 09:20
Golang: Close main window of the process with the specified PID for graceful termination of processes on Windows.
//go:build windows
// Used in https://github.com/SCP002/terminator.
package main
import (
"fmt"
"unsafe"
@SCP002
SCP002 / filter.py
Last active April 26, 2021 13:19
Python: concurrent Filter funtion example. Using Worker Pool.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import concurrent.futures
import datetime
import os
import sys
import time
import traceback
@SCP002
SCP002 / start_process.py
Last active March 12, 2025 07:48
Python: Start process. Keep StdOut and StdErr in the original order. Display output real time character by character. Capture combined output.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import dataclasses
import io
import subprocess
import sys
from collections.abc import Callable
from typing import IO
@SCP002
SCP002 / FilterExample.java
Last active April 22, 2021 09:14
Java 8: concurrent Filter funtion example. Using Worker Pool.
package org.example;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
abstract class ConcurrentFilter {
@SCP002
SCP002 / JSONExample.java
Last active April 11, 2021 03:47
Java 13 (optionally 8): Decode & Encode partially known / dynamic JSON into classes. Require Jackson.
/*
* Java 13+ (Uses multi-line string).
* Java 8+ without multi-line string (line 87).
* Require Jackson dependency (Maven example; Add to <dependencies> in your pom.xml):
* <dependency>
* <groupId>com.fasterxml.jackson.core</groupId>
* <artifactId>jackson-databind</artifactId>
* <version>2.12.2</version>
* </dependency>
*/