Skip to content

Instantly share code, notes, and snippets.

@hallazzang
hallazzang / main.go
Last active July 4, 2024 18:19
[go] (Windows) ensure all child processes are killed when main program exits
package main
import (
"os/exec"
"unsafe"
"golang.org/x/sys/windows"
)
// We use this struct to retreive process handle(which is unexported)
@petemoore
petemoore / main_windows.go
Last active November 3, 2023 06:40
Running process as interactive user from windows service with UAC process elevation
package main
import (
"context"
"errors"
"fmt"
"log"
"os"
"os/exec"
"syscall"
@jpillora
jpillora / sshd.go
Last active December 17, 2023 16:27
Go SSH server complete example - Read more here https://blog.gopheracademy.com/go-and-ssh/
// A small SSH daemon providing bash sessions
//
// Server:
// cd my/new/dir/
// #generate server keypair
// ssh-keygen -t rsa
// go get -v .
// go run sshd.go
//
// Client:
"""
This file contains code that, when run on Python 2.7.5 or earlier, creates
a string that should not exist: u'\Udeadbeef'. That's a single "character"
that's illegal in Python because it's outside the valid Unicode range.
It then uses it to crash various things in the Python standard library and
corrupt a database.
On Python 3... well, this file is full of syntax errors on Python 3. But
if you were to change the print statements and byte literals and stuff:
@snyh
snyh / distance_random.py
Created December 12, 2012 14:02
generate random element from an list with gurantee at least "n" element is not same. (n is default the length of the list)
import random
class DistanceRandom:
def __init__(self, v_range, v_distance=None):
if v_distance == None:
v_distance = len(v_range)
assert(len(v_range) >= v_distance >= 1)
self.freshed = v_range
self.dist = v_distance
self.used = []