Skip to content

Instantly share code, notes, and snippets.

View fhferreira's full-sized avatar
🏠
Home-Office since 2005

Flávio H. Ferreira fhferreira

🏠
Home-Office since 2005
View GitHub Profile
@fhferreira
fhferreira / parser.py
Created January 17, 2022 06:17 — forked from hreeder/parser.py
Python nginx Log Parser
#!/usr/bin/env python
import gzip
import os
import sys
import re
INPUT_DIR = "nginx-logs"
lineformat = re.compile(r"""(?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - - \[(?P<dateandtime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\] ((\"(GET|POST) )(?P<url>.+)(http\/1\.1")) (?P<statuscode>\d{3}) (?P<bytessent>\d+) (["](?P<refferer>(\-)|(.+))["]) (["](?P<useragent>.+)["])""", re.IGNORECASE)
function telefone_validation(telefone) {
//retira todos os caracteres menos os numeros
telefone = telefone.replace(/\D/g, '');
//verifica se tem a qtde de numero correto
if (!(telefone.length >= 10 && telefone.length <= 11)) return false;
//Se tiver 11 caracteres, verificar se começa com 9 o celular
if (telefone.length == 11 && parseInt(telefone.substring(2, 3)) != 9) return false;
<?php
// php cluter-quick-check --host <host> --port <port> [--auth password]
function panicAbort($str_msg) {
fprintf(STDERR, "Error: $str_msg\n");
exit(-1);
}
function panicClusterSlotsError($arr_slots, $str_context) {
$str_slots = print_r($arr_slots, true);
@fhferreira
fhferreira / network-tweak.md
Created July 28, 2021 04:03 — 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'
@fhferreira
fhferreira / php-pools.md
Created June 19, 2021 09:37 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@fhferreira
fhferreira / debug-fpm-segfaut.md
Created May 5, 2021 14:24 — forked from guilhermeblanco/debug-fpm-segfaut.md
Debugging PHP-FPM segfaults

Assuming PHP is compiled with debug enabled.

$ gdb /usr/sbin/php-fpm

Then:

r --nodaemonize --fpm-config /etc/php7/fpm/php-fpm.conf
@fhferreira
fhferreira / Dockerfile
Created April 28, 2021 16:25 — forked from evansims/Dockerfile
Dockerfile: php-fpm 7.4-fpm alpine w/ gd bz2 intl mbstring redis mongodb xdebug opcache
FROM php:7.4-fpm-alpine
WORKDIR "/application"
# Install essential build tools
RUN apk add --no-cache \
git \
yarn \
autoconf \
g++ \
make \
@fhferreira
fhferreira / addrgen
Created April 27, 2021 15:06 — forked from JBaczuk/addrgen
addrgen
#!/bin/bash
echo
echo "Welcome to the Bitcoin address generator!"
echo "input private key (32 bytes, hex format)"
read priv
echo ""
echo "#####################################"
# priv=0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D # Testing only
@fhferreira
fhferreira / bitcoin.js
Created April 3, 2021 22:44 — forked from sanjukurian/bitcoin.js
create bitcoin wallet, make a transaction on bitcoin network using bitcoinjs-lib and blockcypher
var request = require('request');
const bitcoin = require('bitcoinjs-lib');
var buffer = require('buffer');
const bitcoinNetwork = bitcoin.networks.testnet;
var rootUrl = "https://api.blockcypher.com/v1/btc/test3";
//create wallets
const TestNet = bitcoin.networks.testnet3;
@fhferreira
fhferreira / LearnGoIn5mins.md
Created January 14, 2021 03:53 — forked from prologic/LearnGoIn5mins.md
Learn Go in ~5mins