Skip to content

Instantly share code, notes, and snippets.

@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 = []
"""
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:
@jpillora
jpillora / sshd.go
Last active November 17, 2024 21:43
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:
@petemoore
petemoore / main_windows.go
Last active August 8, 2024 15:32
Running process as interactive user from windows service with UAC process elevation
package main
import (
"context"
"errors"
"fmt"
"log"
"os"
"os/exec"
"syscall"
@hallazzang
hallazzang / main.go
Last active August 6, 2024 23:01
[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)