NOTE: 534 stars, 106 forks. I love you all. Please contribute tips and edits back to this cheat sheet -- email's [email protected] and you can treat gists like git repositories and send git diffs.
function youtube(){ | |
// Setup OAuthServiceConfig | |
var oAuthConfig = UrlFetchApp.addOAuthService("youtube"); | |
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); | |
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fgdata.youtube.com%2F"); | |
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); | |
oAuthConfig.setConsumerKey("anonymous"); | |
oAuthConfig.setConsumerSecret("anonymous"); | |
// Setup optional parameters to point request at OAuthConfigService. The "twitter" |
groupBy('source) { | |
_.sortBy('links) | |
.reverse | |
.mapStream[(String,Int), (String, Int, Int, Int)] | |
(('destination, 'links) -> ('destination, 'links, 'rank, 'gap)) { destLinks => | |
destLinks.scanLeft(None: Option[(String, Int, Int, Int)]) { | |
(prevRowOut: Option[(String,Int,Int,Int)], thisRow: (String, Int)) => | |
val (dest, links) = thisRow | |
prevRowOut match { | |
case None => Some((dest, links, 1, 0)) // rank 1, gap 0 -- not exactly what you wanted... |
from sqlalchemy.dialects import registry | |
from sqlalchemy.engine import reflection | |
from sqlalchemy.connectors.pyodbc import PyODBCConnector | |
from sqlalchemy.dialects.postgresql.base import ( | |
PGDialect, PGTypeCompiler, PGCompiler, PGDDLCompiler, DOUBLE_PRECISION, | |
INTERVAL, TIME, TIMESTAMP) | |
from sqlalchemy import MetaData | |
import sqlalchemy.types as sqltypes | |
from sqlalchemy.schema import SchemaItem | |
from sqlalchemy.sql import Select, text, bindparam |
NOTE: 534 stars, 106 forks. I love you all. Please contribute tips and edits back to this cheat sheet -- email's [email protected] and you can treat gists like git repositories and send git diffs.
location / { | |
more_set_headers 'Access-Control-Allow-Origin: $http_origin' 'Access-Control-Allow-Credentials: true'; | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since'; | |
add_header 'Content-Length' 0; | |
add_header 'Content-Type' 'text/plain charset=UTF-8'; |
import unittest | |
from pyramid import testing | |
from paste.deploy.loadwsgi import appconfig | |
from webtest import TestApp | |
from mock import Mock | |
from sqlalchemy import engine_from_config | |
from sqlalchemy.orm import sessionmaker | |
from app.db import Session |
# Empty |
import unittest | |
from pyramid import testing | |
from paste.deploy.loadwsgi import appconfig | |
from webtest import TestApp | |
from mock import Mock | |
from sqlalchemy import engine_from_config | |
from sqlalchemy.orm import sessionmaker | |
from app.db import Session |
(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)
I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)
I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.
I based my approach on [sontek's blog post](http://sontek.net/blog/