Skip to content

Instantly share code, notes, and snippets.

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

Lindemberg Barbosa bergpb

🏠
Working from home
View GitHub Profile
@bergpb
bergpb / generate_secret_key_flask.py
Created February 25, 2019 14:21
Create a SECRET_KEY for Flask apps.
#using os, python2/3
import os
os.urandom(12)
#using uuid, python2/3
import uuid
uuid.uuid4().hex
#using secrets, python>=3.6
import secrets
@bergpb
bergpb / adjust_brightness.py
Created March 7, 2019 14:06
Adjust Brightness in second monitor with XFCE.
import sys
import subprocess
value = float(sys.argv[1])
print('Value is {}.'.format(value))
if (value == 0 or value > 9):
print('Only values between 1 and 9 is permited.')
else:
subprocess.call(["xrandr --output HDMI-1 --brightness {}".format(value/10)], shell=True)
import sys
import time
import PyPDF2
import shutil
from pdfrw import PdfReader, PdfWriter
file = sys.argv[1]
get_name_file = file.split('.')

##Fixing npm permissions

You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.

You can fix this problem using one of three options:

Change the permission to npm's default directory. Change npm's default directory to another directory. Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.

@bergpb
bergpb / python-enumerate.py
Created April 16, 2019 01:29
Uso de enumerate para retornar o índice dos itens de uma lista
In [1]: itens = enumerate([0,1,2,3,4,5])
In [2]: for i in itens:
...: print(i)
...:
(0, 0)
(1, 1)
(2, 2)
(3, 3)
(4, 4)
@bergpb
bergpb / audit_mixin.py
Created April 25, 2019 16:56 — forked from techniq/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@bergpb
bergpb / combination.cpp
Created April 30, 2019 00:31
Combinação - Disciplina de Matemática Discreta
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
float r, n, i, fatorial, aux = 1, numerador, denominador_1, denominador_2;
printf("Entre com o valor de n: ");
scanf("%f", &n);
@bergpb
bergpb / carbon-config.json
Created June 10, 2019 20:01
My Carbon Config
{
"paddingVertical":"14px",
"paddingHorizontal":"22px",
"marginVertical":"45px",
"marginHorizontal":"45px",
"backgroundImage":null,
"backgroundImageSelection":null,
"backgroundMode":"color",
"backgroundColor":"rgba(255,255,255,1)",
"dropShadow":true,
@bergpb
bergpb / will_paginate in Sinatra.md
Created June 27, 2019 13:11 — forked from ChengLong/will_paginate in Sinatra.md
Use will_paginate with ActiveRecord in Sinatra
  1. Add gem 'will_paginate', '~> 3.0' to Gemfile
  2. Add %w(will_paginate will_paginate/active_record).each {|lib| require lib} to config.ru
  3. Assuming modular Sinatra, open Sinatra::Base and add include WillPaginate::Sinatra::Helpers so that all views can use will_paginate
  4. In controller, @users = User.paginate(:page => params[:page], :per_page => 30)
  5. In view, = will_paginate @users will generate the pagers

If you want to style your pagers

  • Include this css in your layout
  • Style it
import gc
import ujson
# from libs import ssd1306
from machine import Pin, I2C, reset
from dht import DHT11
from time import sleep_ms
from ujson import dump, load
from umqtt.simple import MQTTClient