Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
alexanderankin / bookmark.py
Last active October 13, 2018 14:10
fpdf2 Bookmarks Feature Draft Specification
from collections import OrderedDict as o_dict
from fpdf import FPDF
from fpdf.util import textstring
def create_dictionary_string(dict_):
"""format ordered dictionary as PDF dictionary"""
return ''.join([
'<<',
'\n'.join([' '.join(f) for f in dict_.items()]),
@underdoeg
underdoeg / hx711.py
Last active August 26, 2023 23:33
Python port for RaspberryPI of the HX711 Breakout Board
import RPi.GPIO as GPIO
import time
def createBoolList(size=8):
ret = []
for i in range(8):
ret.append(False)
return ret
# coding: utf-8
# http://forums.fedoraforum.org/showthread.php?t=272322
import os
import uuid
import fnmatch
import subprocess
CURRENT_DIR = os.path.dirname(__file__)
CFG_DIR = '/etc/NetworkManager/system-connections'
@mrjoes
mrjoes / ckedit.py
Created March 18, 2013 19:04
Flask-Admin and CKEditor WYSIWYG textarea integration. Basically, all you have to do: 1. Create new wtforms widget which will emit 'ckeditor' class 2. Make new wtforms field which will use this widget 3. Create new jinja2 template, which includes ckeditor javascript 4. Tell flask-admin to use new field and new template
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin, wtf
from flask.ext.admin.contrib import sqlamodel
app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite'
db = SQLAlchemy(app)
@doobeh
doobeh / example.html
Last active June 8, 2023 18:09
Checkbox WTForms Example (in Flask)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post">
{{ form.hidden_tag() }}
{{ form.example }}
@greatghoul
greatghoul / group_sum.py
Created November 15, 2012 14:24
SqlAlchemy Group By
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from sqlalchemy import create_engine, Column, Integer, String, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class StudentInfo(Base):
@techniq
techniq / base.html
Created November 13, 2012 14:47
Flask-Admin WTForms boostrap-wysihtml5
<!DOCTYPE html>
<html lang="en">
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<link href='/static/bootstrap/css/bootstrap.css' rel='stylesheet' type='text/css' />
<link href='/static/wysihtml5/bootstrap-wysihtml5.css' rel='stylesheet' type='text/css' />
</head>
<body>
...
<script src="/static/wysihtml5/wysihtml5-0.3.0.min.js"></script>
@finnjohnsen
finnjohnsen / UDPListenerService
Created September 6, 2012 11:18
Android UDP Broadcast listener service
package no.nsb.ombord;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.http.util.ExceptionUtils;
# Jarvis March O(nh) - Tom Switzer <thomas.switzer@gmail.com>
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)
def turn(p, q, r):
"""Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn."""
return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0)
def _dist(p, q):
"""Returns the squared Euclidean distance between p and q."""