This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
"use strict"; | |
function constEnumPropValueDesc(v){ | |
return { | |
value: v, | |
enumerable: true, | |
configurable: false, | |
writable: false | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)); |