Skip to content

Instantly share code, notes, and snippets.

View scabbiaza's full-sized avatar

scabbiaza scabbiaza

View GitHub Profile
@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 / 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)
// check that event.target is the one that we need
var isNavbarToogle = event.target.path.filter(function(item) {
return (item.classList.contains("navbar-toggle") || item.classList.contains("navbar-header"));
}).length == 2;
// to know when gulp task is end
Gulp.task("name", function () {
console.log('started >>>');
return .....
.pipe(Gulp.dest("build"))
// http://jquense.github.io/react-widgets/docs/#/datetime-picker
//
// <form>
// [date] [time]
// </form>
//
// Both fields return datetime format:
// To compine them in one
let dateField = "Fri Jun 12 2015 15:08:31 GMT+0200";
@scabbiaza
scabbiaza / gist:b75f4725c7c1bf7b5513
Created June 11, 2015 14:36
JS: missed module error cases
*Compilation JS with gulp-browserify*
Case # 0. Any error in NOT included files
Result: no errors by compilation and running
Case # 1. Missed lib on the disk
app.js