Skip to content

Instantly share code, notes, and snippets.

View scabbiaza's full-sized avatar

scabbiaza scabbiaza

View GitHub Profile
@scabbiaza
scabbiaza / macros.html
Last active December 14, 2017 08:06 — forked from maximebf/gist:3986659
form_field macros for WTForms, Flask, Bootstrap 3
{% macro form_field(form, field, print_status=True) -%}
{% set has_label = kwargs.pop('has_label', True) %}
{% set placeholder = '' %}
{% if not has_label %}
{% set placeholder = field.label.text %}
{% endif %}
{% set field_status = '' %}
{% if form.errors and (form.submitted or (form.is_submitted() and form.submit.data)) %}
{# form.submit.data for support multiple forms on page #}
{# form.submitted - manual control for form without button (ajax) #}
@scabbiaza
scabbiaza / flask.py
Last active August 29, 2015 14:06 — forked from kageurufu/flask.py
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.wtf import Form
from flask.ext.babel import gettext
from wtforms import SelectField, TelField, TextField, FormField, Fieldlist, SubmitField
from wtforms.validators import Optional, Required
app = Flask(__name__)
db = SQLAlchemy(app)
@scabbiaza
scabbiaza / README.md
Last active August 29, 2015 14:06
Date interval form

Date interval form

Form could be useful for creating fields like Education interval or Work Experience interval. You could see such fields on facebook and linkedin.

Using: Flask, WTForms, SQLAlchemy, jQuery, Bootstrap

Date interval form

Date interval form. Error example

@scabbiaza
scabbiaza / README.md
Created September 22, 2014 18:29
Flask with infinity scroll navigation

Flask with infinity scroll navigation

Using: Flask, SQLAlchemy, Infinite-scroll

@scabbiaza
scabbiaza / test.py
Last active August 29, 2015 14:06
Flask-SQLAlchemy sketches
# Execute plain query
db.engine.execute("Query here")
result = db.engine.execute("Query here")
for row in result:
print(row['id'])
@scabbiaza
scabbiaza / test.py
Last active August 29, 2015 14:06
WTForms sketches
# Caching results in SELECT choices
# http://stackoverflow.com/questions/10368900/how-to-make-wtforms-read-from-the-datastore
# Choices will be cached
def get_clients_list_choices():
choices = [(0, '')]
clients = Client.query.order_by('company')
for client in clients:
choices.append((client.id, client.fullname))
return choices
@scabbiaza
scabbiaza / gist:8d722db0eb30bd1cd3af
Last active August 29, 2015 14:06
Terminal sketches
# list of files in current dir
$ ls -la
# open file for reading
$ cat filename
# open file for changes
$ nano filename
# remove folter and its contain
@scabbiaza
scabbiaza / gist:873c12d026e1689ffa89
Last active August 29, 2015 14:06
Postgres sketches
# Install
# http://postgresapp.com/
# http://postgresapp.com/documentation/cli-tools.html
DROP USER <username>;
CREATE USER <username> WITH PASSWORD '<password>';
CREATE DATABASE <database-name>;
GRANT ALL privileges ON DATABASE <database-name> TO <username>;
# Create DB
@scabbiaza
scabbiaza / example1.py
Last active August 29, 2015 14:15
SQLAlchemy.Association Proxy.
# N to M relationship without association_proxy
from sqlalchemy import create_engine, ForeignKey, Column, Integer, String, Table
from sqlalchemy.orm import backref, Session, relationship
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite:///', echo=False)
Base = declarative_base()
session = Session(bind=engine)
@scabbiaza
scabbiaza / npm.md
Last active October 26, 2017 12:30
NPM sketches

Install / Update node modules

npm install 

List of installed modules

npm list
npm list -g
npm list --depth=0