Skip to content

Instantly share code, notes, and snippets.

View valdergallo's full-sized avatar
🏠
Working from home

Valder Gallo valdergallo

🏠
Working from home
View GitHub Profile
@valdergallo
valdergallo / redisdb.py
Last active August 12, 2020 19:45
Redis as Python List
class RedisDB(object):
def __init__(self, group_name="locust", hostname="localhost", port=6379, db=0):
self.group_name = group_name
self.con = redis.Redis(host=hostname, port=port, db=db)
def append(self, pallet_id):
return self.con.sadd(self.group_name, pallet_id)
def get_random_item(self):
return self.con.srandmember(self.group_name)
@valdergallo
valdergallo / Makefile
Last active February 7, 2020 19:01
Makefile to build images with Docker Composer
.PHONY: build
APP_VERSION := $$(version show)
DOCKER_IMAGE := 134194528133.dkr.ecr.us-west-1.amazonaws.com/
# Make content for developer
help:
@echo "Create docker images for VPCs"
@echo "dev Build for dev"
@echo "qas Build for qas"
@valdergallo
valdergallo / ajaxData.js
Created January 24, 2020 16:58
default function to send and and load data from server
// Example POST method implementation:
// ajaxData(`http://example.com/answer`, {answer: 42})
// .then(data => console.log(JSON.stringify(data))) // JSON-string from `response.json()` call
// .catch(error => console.error(error));
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i += 1) {
@valdergallo
valdergallo / gerencianet_fields.py
Last active December 5, 2019 14:12
Gerencianet integration with mashmellow schema
# -*- coding: utf-8 -*-
from string import ascii_letters, punctuation
from marshmallow import fields
from decimal import Decimal
punctuation_without_subtract = punctuation.replace('-', '')
STRIP_LETTERS = punctuation_without_subtract + ascii_letters
def _strip_values(value):
@valdergallo
valdergallo / base_auth.py
Created April 26, 2018 20:05
BaseAuth using passlib with itsdangerous lib in python to be used as mixin in User model
# -*- coding: utf-8 -*-
from passlib.apps import custom_app_context as pwd_context
from itsdangerous import (TimedJSONWebSignatureSerializer
as Serializer, BadSignature, SignatureExpired)
SECRET_KEY = 'top-secret'
class AuthUser(object):
def __init__(self, id=None, *args, **kwargs):
@valdergallo
valdergallo / sysctl.conf
Created December 8, 2017 17:52 — forked from techgaun/sysctl.conf
Sysctl configuration for high performance
### KERNEL TUNING ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
@valdergallo
valdergallo / text2img.py
Last active November 25, 2017 17:22
create file BW with text
# -*- coding: utf-8 -*-s
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
NEW_LINE_MARK = "\n"
def text2img(text, file_name="text_to_png.png", default_width=300,
bgcolor="#FFF", color="#000", padding=10):
@valdergallo
valdergallo / tw_dracula.go
Created November 6, 2017 23:25
TwiterStorm Dracula Book
package main
import (
"bufio"
"fmt"
"log"
"os"
"time"
)
@valdergallo
valdergallo / keybinds.json
Created November 6, 2017 16:55
VSCode keybinds for ubunto and sublime
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+alt+d",
"command": "editor.action.addSelectionToNextFindMatch",
"when": "editorFocus"
},
{
"key": "ctrl+d",
"command": "editor.action.deleteLines",
@valdergallo
valdergallo / bitwise.py
Last active October 26, 2017 13:00
One simple bitwise method to search items in multiple items
class Bitwise(object):
def __init__(self, value=None):
"""
Create one set to compare multiple lists
Usage:
# consts
SAO_PAULO = 'sp'
RIO_DE_JANEIRO = 'rj'