Skip to content

Instantly share code, notes, and snippets.

View fagci's full-sized avatar
👁️
What's happening?

Mikhail fagci

👁️
What's happening?
View GitHub Profile
@fagci
fagci / net_http_socket_options.rb
Last active September 21, 2022 06:20 — forked from steveyen/gist:1201110
Using TCP_NODELAY with ruby Net HTTP (set socket options)
class MyHTTP < Net::HTTP
def on_connect()
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
end
n = 5
host = 'example.com'
port = 80
@fagci
fagci / 50-cloud-init.yaml
Created August 6, 2022 09:58
[NOTE] Install Ubuntu server on Raspberry Pi 4 using smartphone
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
@fagci
fagci / wait-for-head.js
Created July 11, 2022 14:23
Function to wait for head. Used for userscripts (greasemonkey) with document-start.
function waitForHead(cb) {
const waiter = setInterval(function() {
if(document.head) {
clearInterval(waiter);
cb();
}
}, 0);
}
@fagci
fagci / via_toolbar.js
Created July 4, 2022 13:56
Via browser toolbar
;(function(){
const d=document;
const css = d.createElement('style');
css.innerText = `
.ymb {
position: fixed;
bottom: 0;
left: 0;
right: 0;
@fagci
fagci / .ssh_rc
Last active December 11, 2021 17:55
Send notification to Telegram channel on SSH login
# ~/.ssh/rc
chat='<chat_id>'
token='<token>'
msg="*SSH $(uname -n)*
\`\`\`
User: ${USER}
Remote IP: ${SSH_CONNECTION%% *}
\`\`\`
@fagci
fagci / bigram_extractor.py
Created October 27, 2021 18:02
Extracts top of bigrams (ngrams) from text.
#!/usr/bin/env python3
from collections import Counter
from re import findall
from sys import argv
def main(text, top, n=2):
ngrams = []
for word in findall(r'\w+', text.lower()):
wlen = len(word)
@fagci
fagci / ttfb.py
Created September 22, 2021 18:02
Measure TTFB using python
#!/usr/bin/env python3
from socket import gethostbyname, socket
from ssl import wrap_socket
from sys import argv
from time import time
from urllib.parse import urlparse
def main(url):
pu = urlparse(url)
@fagci
fagci / icmp_ping.py
Created September 22, 2021 14:33
ICMP ping
#!/usr/bin/env python3
from socket import AF_INET, IPPROTO_ICMP, SOCK_DGRAM, gethostbyname, socket
from struct import pack
from time import sleep, time
def main():
seq = 1
with socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP) as s:
s.settimeout(1)
@fagci
fagci / global_ip_generator.py
Created September 11, 2021 16:25
Fastest global (WAN) random IP generator written in python
"""Global (WAN) IP generator"""
from random import randint
from socket import inet_ntoa
from struct import pack
__author__ = 'Mikhail Yudin aka fagci'
def global_ip_generator(count=10):
while count:
@fagci
fagci / random_ips_generator.py
Last active November 23, 2022 17:16
Random public (global) IP v4 addresses generator
from ipaddress import IPv4Address
from random import randrange
def generate_ips(count=20):
while count: # negative values makes infinite generator
ip_address = IPv4Address(randrange(0x01000000, 0xffffffff))
if ip_address.is_global and not ip_address.is_multicast:
count -= 1
yield str(ip_address)