Skip to content

Instantly share code, notes, and snippets.

View danielflira's full-sized avatar

Daniel Fonseca de Lira danielflira

View GitHub Profile
@danielflira
danielflira / client.py
Last active June 14, 2020 03:13
Exemplo de servidor e client tcp com socket e select
from simplesocket import SimpleSocket, SocketDisconnected
class CharClient(SimpleSocket):
def __init__(self, *args, **kwargs):
self.create_client(*args, **kwargs)
def handle_recv(self, client):
char = str(client.recv(1), "utf8")
if len(char) == 0:
raise SocketDisconnected()
@danielflira
danielflira / silver_tape.sh
Last active January 11, 2021 20:48
comandos úteis para manutenção do elasticsearch
#!/bin/bash
set -e
export ELASTIC_URL="http://engpro.totvs.com.br:9200"
curl -sL -X GET "${ELASTIC_URL}/_cat/indices" | awk '$1 != "green" {print($3)}' | while read indice; do
echo -n "${indice} zero replicas to zero: "
curl -sL -XPUT "${ELASTIC_URL}/${indice}/_settings" -d '{"number_of_replicas": 0}'
echo
sleep 1
#!/usr/bin/env python3
import os
import subprocess
import configparser
def find(path):
paths = [path]
while len(paths) > 0:
path = paths.pop()
@danielflira
danielflira / latency_check.py
Last active April 9, 2021 19:57
DigitalOcean region latency check
#!/usr/bin/env python3
import subprocess
import re
def gen_hosts():
'''
Current regions list on https://status.digitalocean.com/
'''
regions = [
@danielflira
danielflira / openssl_sign.sh
Created January 15, 2020 18:17
Assinando arquivos com OpenSSL
#!/bin/bash
# gerando chaves
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -out public.pem -pubout
# gerando assinatura
openssl dgst -sign private.pem -sha256 -out sign.sha256 /bin/ls
# verificando assinatura
@danielflira
danielflira / wrk_status_result.lua
Created December 2, 2019 12:56
wrk strip to list request status
local threads = {}
function setup(thread)
table.insert(threads, thread)
end
function init(args)
results = {}
end
@danielflira
danielflira / index.js
Created October 31, 2019 20:01
exemplo autenticação com ldap
// Para usar npm i ldap e executar assim:
// $ USER="usuario@dominio" PASS=`get_senha` index.js
const ldap = require("ldap");
let SERVER = process.env.SERVER || "ldap://10.171.59.13:3268";
let USER = process.env.USER;
let PASS = process.env.PASS;
let LOGIN = process.env.LOGIN;
'''
duckdns - update a https://duckdns.org domain
usage:
duckdns host=hostname token=duckdns-token ip=[ip|local|net]
parameters:
host - name of host created at https://duckdns.org
token - token of your account at https://duckdns.org
ip - ip (valid ip) 'local' (lan address) 'net' (internet address)
@danielflira
danielflira / waitress_flask_sse.py
Last active June 11, 2020 07:41
waitress and flask sse (server sent events) example
from flask import Flask, Response, url_for
from waitress import serve
from datetime import datetime
import time
import json
app = Flask(__name__)
@app.route('/sse')
@danielflira
danielflira / do_nothing_openal.c
Created September 8, 2017 17:03
do nothing capture with openal
#include <AL/al.h>
#include <AL/alc.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#define BUFF_SIZE 44100
#define FREQUENCY 44100
int running;