Skip to content

Instantly share code, notes, and snippets.

def add_url(self, endpoint):
"""Adds additional urls to the resource
:endpoint: the end point API to be added
:returns: the url created ( for tastypie )
"""
api = r'(?P<resource_name>%s)/(?P<endpoint>%s)%s$' % (
self._meta.resource_name, endpoint, trailing_slash())
endpoint = endpoint.replace('/', '_')
@d7my11
d7my11 / favorite.py
Last active August 29, 2015 14:22
Favorite last 100 tweets
import tweepy
import argparse
def main(handle):
try:
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ACCESS_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxx'
from PIL import Image
if self.thumbnail:
try:
image = Image.open(self.thumbnail.path)
(width, height) = image.size
"Max width and height 800"
if (700 / width < 471 / height):
factor = 471 / height
else:
import tweepy
import random
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
var quer = {};
var pagination = {};
Restangular.addFullRequestInterceptor(function(element, operation, what, url, headers, params) {
var query = params;
if (operation === 'getList') {
if (Common.query) {
query = _.cloneDeep(Common.query);
angular.extend(query, params);
if (query.limit === 0) {
delete query.page;
# base tastypie class
class BaseResource(ModelResource):
# Endpoint refers to function in the Resource eg. function_data_whatever
# IMPORTANT: URL will be replaced to function/data/whatever
def alter_list_data_to_serialize(self, request, data):
""" Used to return only meta data, if we have meta_only = true """
if request.GET.get('meta_only'):
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
# Base Resource
class MultipartResource(object):
def deserialize(self, request, data, format=None):
if format == 'application/x-www-form-urlencoded':
return request.POST
if format.startswith('multipart'):
data = request.POST.copy()
data.update(request.FILES)
var express = require("express");
var app = express();
app.use(require('prerender-node').set('prerenderServiceUrl', 'http://localhost:1337/').set('prerenderToken', 'TOKEN'));
app.use(express.static(__dirname + "/app"));
app.use("/app/bower_components", express.static(__dirname + "/app/bower_components"));
app.use("/app/dist/min/css/fonts/", express.static(__dirname + "/app/dist/min/css/fonts/"));
app.all('/*', function(req, res, next) {
res.sendFile("/app/index.html", { root: __dirname });
});
var express = require("express");
var app = express();
app.use(express.static(__dirname + "/app"));
app.use("/app/bower_components", express.static(__dirname + "/app/bower_components"));
app.use("/app/dist/min/css/fonts/", express.static(__dirname + "/app/dist/min/css/fonts/"));
app.all('/*', function(req, res, next) {
res.sendFile("/app/index.html", { root: __dirname });
});
app.listen(process.env.PORT || 3000);