This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<time.h> | |
#include<unistd.h> | |
/* | |
* snowflake.c | |
* | |
* a simple implementation of twitter snowflake in C | |
* | |
* [email protected] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local signal = require("posix.signal") | |
local socket = require("socket") | |
local string = require("string") | |
-- create a TCP socket and bind it to the local host, at any port | |
local server = assert(socket.bind("127.0.0.1", 0)) | |
local ip, port = server:getsockname() | |
print(string.format("telnet %s %s", ip, port)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import random | |
__author__ = "[email protected]" | |
def sample(population, k, odds=lambda item: 1.0): | |
""" | |
Chooses k unique random elements from a population sequence with odds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
import bisect | |
class AStarPathfinding(object): | |
class Node(object): | |
# item must be hashable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
class BaseBinaryHeap(object): | |
def __init__(self, key=lambda x: x, value=lambda x: x): | |
self.queue = list() | |
self.index = dict() | |
self.key = key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function BinaryHeap(keyFunction, scoreFunction) { | |
this.content = []; | |
this.map = {}; | |
this.keyFunction = keyFunction || function (e) { | |
return e; | |
}; | |
this.scoreFunction = scoreFunction || function (e) { | |
return e; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iptables --table filter --append INPUT --match conntrack --ctstate ESTABLISHED,RELATED --match comment --comment "Allow established and related connections" --jump ACCEPT | |
iptables --table filter --append INPUT --protocol icmp --icmp-type echo-request --match length --length 84 --match recent --set --name openSSH --rsource --match comment --comment "ping before ssh" --jump LOG --log-prefix "OpenDoor SSH: " --log-level 7 | |
iptables --table filter --append INPUT --protocol tcp --dport ssh --syn --match recent ! --rcheck --seconds 30 --name openSSH --rsource --match comment --comment "Drop SSH connection not pinged recently" --jump DROP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
import collections | |
import re | |
Token = collections.namedtuple('Token', ['tpe', 'value']) | |
Scanner = re.Scanner(( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Ref. https://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm#answer-668327 | |
import time | |
def limit(rate, burst=0.0): | |
unit = 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# | |
import random | |
import socket | |
import time | |
def traceroute(dest, hops=64, timeout=0.7): | |
empty = bytes() |
OlderNewer