Skip to content

Instantly share code, notes, and snippets.

View simanacci's full-sized avatar
💭
😷

simanacci

💭
😷
View GitHub Profile
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import SubmitField, SelectMultipleField, widgets
class MultiCheckboxField(SelectMultipleField):
widget = widgets.ListWidget(prefix_label=False)
option_widget = widgets.CheckboxInput()
class ExampleForm(FlaskForm):
foo = MultiCheckboxField('label'
@simanacci
simanacci / flask_profiler.py
Created October 29, 2019 06:21 — forked from shreyansb/flask_profiler.py
A profiler for Flask apps
"""
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the profile or cProfile
module to do the profiling and writes the stats to the stream provided
To use, run `flask_profiler.py` instead of `app.py`
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling
"""
@simanacci
simanacci / multiplecheckbox.py
Created April 25, 2020 20:45 — forked from juzten/multiplecheckbox.py
custom multiple checkbox field for wtforms and flask
from flask import Flask, render_template
from flask.ext.wtf import Form, widgets, SelectMultipleField
SECRET_KEY = 'development'
app = Flask(__name__)
app.config.from_object(__name__)
class MultiCheckboxField(SelectMultipleField):
widget = widgets.ListWidget(prefix_label=False)
def generate_password_reset_token(self, expires_in=3600):
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'], expires_in)
return s.dumps(self.email, salt='password-recovery')
@staticmethod
def reset_password(token, new_password):
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
try:
email = s.loads(token, max_age=3600, salt='password-recovery')
except SignatureExpired:
socket.on('notification-message', function(msg) {
var targetContainer = document.getElementById('notification-count');
console.log(targetContainer);
{% if request.endpoint == 'dash.notification' %}
var nextNotificationButton = document.getElementById('next-unread-notification');
var nextNotificationFooter = document.getElementById('notification-footer');
{% endif %}
if (msg.count != 0) {
targetContainer.classList.add("notification-count");
targetContainer.innerHTML = msg.count;
@simanacci
simanacci / mock_object.py
Created July 4, 2021 13:01 — forked from peterldowns/mock_object.py
Simple way of creating Mock objects from nested dictionaries.
import mock
def mock_object(data=None):
result = mock.MagicMock()
for key, value in data.iteritems():
if isinstance(value, dict):
result.configure_mock(**{
key: mock_object(value),
})
else:
result.configure_mock(**{
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
<html>
<body class="container">
<header>
<link href="/static/test.css" rel="stylesheet" type="text/css">
</header>
<main class="main">
<img id="profile-photo" src="https://test.s3.amazonaws.com/profile_photo/test.jpg" alt="Politician Profile Photo" >
</main>
</body>
</html>
@simanacci
simanacci / curl.md
Created November 10, 2022 16:39 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@simanacci
simanacci / wiremock.rs
Last active December 26, 2022 19:18
Mock HN API Request
// The test
let body = format!(
r#"
{{
"about" : "This is a test {}",
"created" : 1173923446,
"delay" : 0,
"id" : {},
"karma" : 2937,
"submitted" : [ 8265435, 8168423, 4289 ]