Skip to content

Instantly share code, notes, and snippets.

@philfreo
philfreo / gist:b307afd2339767481426
Created August 22, 2014 21:56
How to have Flask download a file and then serve it as an attachment
@app.route('/download/', methods=['GET'])
def download():
url = request.args['url']
filename = request.args.get('filename', 'image.png')
r = requests.get(url)
strIO = StringIO.StringIO(r.content)
return send_file(strIO, as_attachment=True, attachment_filename=filename)
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}