Skip to content

Instantly share code, notes, and snippets.

View alikopasa's full-sized avatar

alikopasa

View GitHub Profile
@alikopasa
alikopasa / update-limit.sh
Created June 12, 2022 08:03 — forked from mustafaturan/update-limit.sh
Set max open files limit on mac
sudo sysctl -w kern.maxfiles=75000
sudo sysctl -w kern.maxfilesperproc=75000
ulimit -S -n 75000
@alikopasa
alikopasa / network-tweak.md
Created June 12, 2022 08:02 — forked from mustafaturan/network-tweak.md
Linux Network Tweak for 2 million web socket connections

Sample config for 2 million web socket connection

    sysctl -w fs.file-max=12000500
    sysctl -w fs.nr_open=20000500
    # Set the maximum number of open file descriptors
    ulimit -n 20000000

    # Set the memory size for TCP with minimum, default and maximum thresholds 
 sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
@alikopasa
alikopasa / imap-attachment.php
Created April 2, 2021 05:52 — forked from hakre/imap-attachment.php
Save attachments from imap messages to disk.
<?php
/**
* imap-attachment.php
*
* @author hakre <hakre.wordpress.com>
* @link http://stackoverflow.com/questions/9974334/how-to-download-mails-attachment-to-a-specific-folder-using-imap-and-php
*/
/**
* Utility Class
const puppeteer = require('puppeteer');
class Webpage {
static async generatePDF(url) {
const browser = await puppeteer.launch({ headless: true }); // Puppeteer can only generate pdf in headless mode.
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'load' }); // Adjust network idle as required.
const pdfConfig = {
path: 'url.pdf', // Saves pdf to disk.
format: 'A4',
@alikopasa
alikopasa / scanport.py
Created April 27, 2020 17:23 — forked from highfestiva/scanport.py
Check if TCP port ranges in a certain ip range is listening
#!/usr/bin/env python3
from argparse import ArgumentParser
from multiprocessing import Pool, freeze_support
import socket
def ip2num(ip):
a,b,c,d = [int(v) for v in ip.split('.')]
return ((a*256+b)*256+c)*256+d
@alikopasa
alikopasa / memoize.py
Created April 27, 2020 17:22 — forked from highfestiva/memoize.py
Minimal 19 LoC memoization with timeout
import time
class memoize(object):
def __init__(self, timeout=60):
self.cache = {}
self.timeout = timeout
def _flush(self):
now = time.time()
@alikopasa
alikopasa / bitmex-liquidation-calculator.py
Created April 27, 2020 17:21 — forked from highfestiva/bitmex-liquidation-calculator.py
cli bitmex liquidation calculation formula, minimal implementation
#!/usr/bin/env python3
import argparse
from math import ceil, floor
sign = lambda amt: -1 if amt<0 else (1 if amt>0 else 0)
class dobj:
@alikopasa
alikopasa / bitmex-cross-margin-liquidation-calc.py
Created April 27, 2020 17:21 — forked from highfestiva/bitmex-cross-margin-liquidation-calc.py
Optimized and simplified BitMEX's cross-margin calculation
def long_liq_price(wallet_balance_btc, qty, price):
usd = qty * int(-100000000 / price - 0.5)
a = wallet_balance_btc * 99925056.20784412 + 0.011498875843117663 * usd
a *= a>0
x = usd*1.004831 - a
return -100000000 / int(x / qty)
def short_liq_price(wallet_balance_btc, qty, price):
usd = qty * int(-100000000 / price - 0.5)
@alikopasa
alikopasa / binance-liquidation-calculator.py
Created April 27, 2020 17:20 — forked from highfestiva/binance-liquidation-calculator.py
CLI Binance liquidation calculation formula
#!/usr/bin/env python3
maint_lookup_table = [
( 50000, 0.4, 0),
( 250000, 0.5, 50),
( 1000000, 1.0, 1300),
( 5000000, 2.5, 16300),
(10000000, 5.0, 141300),
(20000000, 10.0, 641300),