Skip to content

Instantly share code, notes, and snippets.

@cybertoast
cybertoast / gdrive-dl.py
Created January 10, 2018 22:35 — forked from joshtch/gdrive-dl.py
Google Drive file downloader for Python, with progress bar with tqdm. Based on this SO answer https://stackoverflow.com/a/39225039/3175094
#!/usr/bin/env python2
import requests
from tqdm import tqdm
import re
import os
def download_file_from_google_drive(id, destination):
URL = 'https://docs.google.com/uc?export=download'
session = requests.Session()
@cybertoast
cybertoast / ckedit.py
Last active August 29, 2015 14:17 — forked from dengshuan/ckedit.py
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin
from wtforms import TextAreaField
from wtforms.widgets import TextArea
from flask.ext.admin.contrib.sqla import ModelView
app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790'
@cybertoast
cybertoast / gist:8359387
Created January 10, 2014 18:05
Changing the response structure of any flask module after the fact
# To override flask-security's API response add the following into your app's configure_security():
@app.after_request
def after_request(response):
"""Convert flask-security response into a format we can use
Flask-security returns
{'meta': {'code': 200}, 'response': { 'user': {...} }
But we need {'code': 200, 'data': {'user': ...} }
"""
@cybertoast
cybertoast / gist:6499708
Last active February 9, 2023 00:20
Get a list of all flask routes, and their endpoint's docstrings as a helper resource for API documentation.
@admin_api.route('/help', methods=['GET'])
def routes_info():
"""Print all defined routes and their endpoint docstrings
This also handles flask-router, which uses a centralized scheme
to deal with routes, instead of defining them as a decorator
on the target function.
"""
routes = []
for rule in app.url_map.iter_rules():
@cybertoast
cybertoast / gist:5571293
Created May 13, 2013 20:35
MongoDB: export and import a filtered set of documents
#!/bin/bash
set -ex
now=$(date -u +%Y%m%d%H%M%S)
dest_dir="/tmp/"
dest_file="query_$now.json"
# Export your documents with a query
mongoexport --db YOURDB --username USERNAME --password PASSWORD --collection media \