Skip to content

Instantly share code, notes, and snippets.

View vfulco's full-sized avatar

Vincent C Fulco vfulco

  • Weisisheng Corporate Management Consulting (Shanghai) Ltd.
  • Shanghai, China
View GitHub Profile
anonymous
anonymous / bootstrap.sh
Created June 2, 2011 17:19
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@jessejlt
jessejlt / about.txt
Created October 23, 2011 03:20
nginx, flask, and file downloads
Okay so here's the setup:
[-] The primary server API is exposed via Flask (Python) and all static files, including all html, css, js is served by nginx.
[-] Python is exposing an API at url http://domain.com/api/download/<file_id>, where file_id is a database id for the file that we're interested in downloading.
1. User wants to download a file, so we spawn a new window with the url '/api/download/<file_id>'
2. Nginx intercepts the request, sees that it starts with /api/, and then forwards the request to Flask, which is being served on port 5000.
3. Flask routes the request to its download method, retrieves the pertinent data from the file_id, and constructs additional header settings to make nginx happy and to force the browser to see the file stream as a download request instead of the browser just trying to open the file in a new window. Flask then returns the modified header stream to nginx
4. Nginx is finally ready to do some work. While parsing the headers for the incoming request, it encounters "X
@cspanring
cspanring / pagination.html
Created November 8, 2011 02:53
linaro django pagination template for Bootstrap framework
{# use in combination with https://github.com/zyga/django-pagination #}
{# and http://twitter.github.com/bootstrap/ #}
{# project-dir/templates/pagination/pagination.html #}
{% if is_paginated %}
{% load i18n %}
<div class="pagination">
<ul>
{% block previouslink %}
{% if page_obj.has_previous %}
anonymous
anonymous / py_example.py
Created March 22, 2012 19:40
#!/usr/bin/env python
class BidAskParseError(Exception): pass
import datetime
from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import ClientFactory
class ExampleClient(LineReceiver):
@ses4j
ses4j / incrementalmr.py
Created March 29, 2012 03:42
Periodically-updating pymongo/MongoDB incremental MapReduce example
def incremental_map_reduce(
map_f,
reduce_f,
db,
source_table_name,
target_table_name,
source_queued_date_field_name,
counter_table_name = "IncrementalMRCounters",
counter_key = None,
max_datetime = None,
@jeromyanglim
jeromyanglim / example-r-markdown.rmd
Created May 17, 2012 04:23
Example of using R Markdown
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown)
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96.
This combination of tools provides an exciting improvement in usability for
[reproducible analysis](http://stats.stackexchange.com/a/15006/183).
Specifically, this post
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96;
(2) provides a basic example of producing console output and plots using R Markdown;
(3) highlights several code chunk options such as caching and controlling how input and output is displayed;
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and
(5) discusses the implications of R Markdown.
@dsparks
dsparks / Making k-folds.R
Created September 11, 2012 01:55
Random, equally-sized partitions
# Randomly allocating observations into groups, for, e.g. cross-validation
kk <- 10 # Number of partitions, as in "kk-fold cross-validation."
# Here is a data.frame full of good data:
nn <- 1003
myData <- data.frame(matrix(rnorm(nn * 3), ncol = 3))
colnames(myData) <- LETTERS[1:3]
# This does not work:
whichK <- sample(LETTERS[1:kk], nrow(myData), replace = T)
@jpennell
jpennell / fabfile.py
Created September 18, 2012 01:15
Fabric fabfile for Django/Heroku App
from fabric.api import env, local, require
def deploy():
"""fab [environment] deploy"""
require('environment')
maintenance_on()
push()
syncdb()
migrate()
@gladson
gladson / bootstrap-recaptcha.css
Created October 1, 2012 15:46 — forked from boh1996/bootstrap-recaptcha.css
Twitter Bootstrap reCAPTCHA
.input-recaptcha {
width:172px;
}
@johnschimmel
johnschimmel / sample_form.html
Last active January 20, 2016 12:58
sample form with flask-mongoengine wtform validation
<form method="POST" role="form">
{{ form.csrf_token }}
<legend><h3>Share Your Ideas</h3></legend>
{% if form.errors %}
<ul class="errors">
{% for field_name, field_errors in form.errors|dictsort if field_errors %}
{% for error in field_errors %}
<li>{{ form[field_name].label }}: {{ error }}</li>