Skip to content

Instantly share code, notes, and snippets.

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

Glauber Brennon gbrennon

🏠
Working from home
  • São Paulo/SP - Brazil
  • 11:49 (UTC -03:00)
View GitHub Profile
@chaconnewu
chaconnewu / xlsx_reader.py
Created June 22, 2018 16:22
Excel XLSX DictReader in Python 3
import xlrd, mmap
def XLSDictReader(filename, sheet_index=0):
'''
Excel xlsd dict reader.
'''
with open(filename) as f:
book = xlrd.open_workbook(
file_contents=mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ))
@owainlewis
owainlewis / Either.scala
Last active August 12, 2021 07:03
Validation examples
object EitherValidationExamples {
type ValidationError = String
def validateEmail(user: User): Either[ValidationError, User] =
if (user.email contains "@") Right(user) else Left("Must supply a valid email")
def validateAge(user: User): Either[ValidationError, User] =
if (user.age > 18) Right(user) else Left("Must be over 18")
@evanscottgray
evanscottgray / docker_kill.sh
Last active November 7, 2023 03:40
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt
@yprez
yprez / fields.py
Last active February 19, 2023 12:08
Django rest framework - Base64 image field
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def from_native(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@DavidBruant
DavidBruant / ScreenTreeNode.js
Created August 25, 2013 21:36
2D BSP in JavaScript
(function(global){
"use strict";
function constEnumPropValueDesc(v){
return {
value: v,
enumerable: true,
configurable: false,
writable: false
};
@wildiney
wildiney / verifica_cartao.js
Created October 19, 2012 17:39
Função Javascript para validar cartão de crédito
function checkCard(num){
var msg = Array();
var tipo = null;
if(num.length > 16 || num[0]==0){
msg.push("Número de cartão inválido");
} else {
@djgraham
djgraham / battery_info.sh
Created December 5, 2011 13:45
Bash script for linux to show you how worn your battery is
#!/bin/bash
bats=`ls /proc/acpi/battery/`;
for bat in $bats;do
remain=`cat /proc/acpi/battery/$bat/{info,state}|grep remaining|grep -o "[0-9]\+"`
full=`cat /proc/acpi/battery/$bat/{info,state}|grep full |grep -o "[0-9]\+"`
descap=`cat /proc/acpi/battery/$bat/{info,state}|grep "design capacity:" |grep -o "[0-9]\+"`
rate=`cat /proc/acpi/battery/$bat/{info,state}|grep "present rate:" |grep -o "[0-9]\+"`
state=`cat /proc/acpi/battery/$bat/{info,state}|grep "charging state:" |grep -o "[a-z]\+$"`
echo $state;
lostcap=$((((descap-full)*100)/descap));