Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

import json
import sys
import boto3
def create_empty_file(bucket_name, key):
s3 = boto3.client('s3')
s3.put_object(Bucket=bucket_name, Key=key, Body=b'')
def revert_to_previous_version(bucket_name, key):
@microft
microft / .zshrc
Created April 3, 2024 17:27
Usefull shell commands
alias webserver="python3 -m http.server"
alias tunnel="ssh -v -D 1337 -C -N"
@microft
microft / code.py
Created March 19, 2024 15:08
serialize a Model to JSON
from .models import YourModel
from .serializers import YourModelSerializer
from rest_framework.renderers import JSONRenderer
# Assuming you have a YourModel instance
instance = YourModel.objects.get(pk=1)
# Serialize the instance using the serializer
serializer = YourModelSerializer(instance)
@microft
microft / templated config example
Last active March 31, 2024 15:59
pydantic BaseSettings example
from pydantic import Field
from pydantic import BaseSettings
class Config(BaseSettings):
x: int
y: str | None
z: str = 'Xpto'
_config = Config()
@microft
microft / .zshrc
Last active March 31, 2024 21:19
zsh functions to create and use python 3 virtualenvs based on the directory name
WORKON_HOME=/home/microft/.virtualenvs
workon(){
cd $1;
source $WORKON_HOME/${PWD##*/}/bin/activate
return 0;
}
mkvenv(){
python3 -m venv $WORKON_HOME/$1
}
@microft
microft / keybase.md
Last active March 31, 2024 16:00
keybase proof

Keybase proof

I hereby claim:

  • I am microft on github.
  • I am luisbraga (https://keybase.io/luisbraga) on keybase.
  • I have a public key ASBF7WEt1jT8maY_cOou8Lm_cxv8y1N0ayQ6t00tQqQTfgo

To claim this, I am signing this object:

@microft
microft / .zshrc
Created April 9, 2020 09:26
smileyface in zsh PS1
function smileyface
{
case $? in
0 )
echo -ne "$fg[green] :)"
;;
1 )
echo -ne "$fg[red] ;("
;;* )
echo -ne "$fg[yellow] %%("
@microft
microft / covid.py
Created April 4, 2020 09:31
get the data from worldometers coronavirus page and display in console
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from tabulate import tabulate
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://www.worldometers.info/coronavirus/')
output_table = []
table = driver.find_element_by_xpath('//*[@id="main_table_countries_today"]/thead[1]')
row = table.find_elements_by_tag_name("tr")[0] # get all of the rows in the table
@microft
microft / 50-marblemouse.conf
Created February 9, 2019 14:41
xorg configuration for left handed logitech marble mouse (middle click and scroll) - Ubuntu 18.04
Section "InputClass"
Identifier "Logitech USB Trackbal"
MatchProduct "Logitech USB Trackball"
Driver "libinput"
Option "MiddleEmulation" "on"
Option "ScrollMethod" "button"
#Option "ButtonMapping" "1 2 3 4 5 6 7 8 9" # right handed
#Option "ScrollButton" "8" # right handed
Option "ScrollButton" "9" # left handed
Option "ButtonMapping" "3 9 1 4 5 6 7 2 8" #left handed
@microft
microft / gideon.py
Created November 29, 2016 09:34
a small Flask service
from __future__ import division
import logging
from flask import Flask, request, jsonify
from gensim import corpora, models, similarities
SIMILARITY_THRESHOLD = 0.5
INDUSTRIES = {
'funding': {},
'txt50': {}