Skip to content

Instantly share code, notes, and snippets.

View MaxMorais's full-sized avatar
🏢
Building TechMax Soluções

Maxwell Morais MaxMorais

🏢
Building TechMax Soluções
View GitHub Profile
// add a trigger on field "custom_field1"
cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
// update a new field "custom_field3"
doc.custom_field3 = flt(doc.custom_field1)*flt(doc.custom_field2)/1000;
// refresh in form
refresh_field('custom_field3');
}
@MaxMorais
MaxMorais / maskedinput.py
Last active December 11, 2015 04:59
Web2py MaskedInput Widget
# This widget requires jQuery-iMask to run
#https://github.com/cwolves/jQuery-iMask
from gluon.dal import Field
import re
def factory(mask='', auto_start=True, empty_chr="_", error_message="Did not match!"):
assert len(mask)>1, 'empty mask not is allowed'
assert len(empty_chr)==1, 'empty_chr requires one character'
from gluon.sqlhtml import StringWidget
from gluon.validators import IS_MATCH, IS_NOT_EMPTY
@MaxMorais
MaxMorais / currency.json
Last active December 11, 2015 07:18
I18N Money Support
// Display Source http://www.thefinancials.com/Default.aspx?SubSectionID=curformat
{
'default': {
"symbol": null,
"display": "#,###.##"
},
"AFN": {
"symbol": null,
"display": "######"
},
@MaxMorais
MaxMorais / moneyinput.py
Last active November 10, 2017 19:33
Web2py MoneyInput Widget
# This widget requires jQuery-iMask to run
#https://github.com/cwolves/jQuery-iMask
def money_widget_factory(international=False):
import locale, string, random
from gluon.sqlhtml import StringWidget
from gluon import current
from gluon.http import HTTP
T = current.T
@MaxMorais
MaxMorais / linkinput.py
Last active August 1, 2016 13:54
Web2Py Link Widget [UNDER DEVELOPMENT] This widget adds 3 new features to AutoCompleteWidget` ```      - Search: Allows the user to easily locate a record.      - Preview: Allows the user to view the records referenced.      - Add: Allows the user to add and self-references a record. ```
#-*- coding: utf-8 -*-
from gluon.sqlhtml import AutoCompleteWidget
from gluon.contrib.simplejson import loads
class LinkWidget(AutoCompleteWidget):
AGGREGATION = 'agg'
CONDITION = 'condition'
FIELD = 'fieldname'
QUERY = 'query'
# This widget requires jQuery-iMask to run
#https://github.com/cwolves/jQuery-iMask
def numeric_widget_factory():
import locale, string, random
from gluon.sqlhtml import StringWidget
from gluon import current
from gluon.http import HTTP
T = current.T

Sete Atitudes para Hackear a Indústria de Software

By Klaus Wuestefeld

1) Torne-se excelente.

Seja realmente bom em alguma coisa. Não fique só choramingando ou querendo progredir às custas dos outros. Não pense q pq vc sentou 4 anos numa faculdade ouvindo um professor falar sobre software q vc sabe alguma coisa. Jogador de futebol não aprende a jogar bola tendo

# coding: utf-8
u"""
Redimensionamento proporcional de imagem, com base na altura, feito com um simples cálculo de proporção.
Ex:
+------+ 10 15 (altura desejada para a nova imagem)
| | -- x --
| 10x5 | 5 x (largura proporcional a nova altura)
| |
+------+ (10 x x) = (5 x 15)
10x = 75
from PIL import Image
def get_white_noise_image(width, height):
pil_map = Image.new("RGBA", (width, height), 255)
random_grid = map(lambda x: (
int(random.random() * 256),
int(random.random() * 256),
int(random.random() * 256)
), [0] * width * height)
pil_map.putdata(random_grid)
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
from StringIO import StringIO
font = ImageFont.load_default()
input = StringIO(self.request.get("img"))
img = Image.open(input)
draw = ImageDraw.Draw(img)