Skip to content

Instantly share code, notes, and snippets.

@esseti
esseti / setting.py
Created January 29, 2013 12:07
This is an example of how to write your setting.py (Django) for running the app on AppFog and localhost without the need of changing settings every time. Plus at the bottom i added a trick on how to init the db, since AppFog does not let to do that (you have to use the tunnelling)
# Django settings for DjangoProjects project.
import os
#if this value exsist you are on appfog.
if 'VCAP_SERVICES' in os.environ:
DEBUG = False
#othewhise it's localhost
else:
DEBUG = True
@esseti
esseti / curl-trick
Created January 31, 2013 14:56
Avoid "The document has moved" in GDocs requests from curl (and similar)
curl -L -d headers YOUR_URL
@esseti
esseti / models.py
Last active December 13, 2015 22:48
Pipe for django-social-auth for having a user profile populated with facebook data
class Language(models.Model):
name = models.CharField(max_length=100, default='')
fb_id = models.CharField(max_length=100, default='0')
def __unicode__(self):
return str(self.fb_id)
class UserProfile(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=100, default='')
@esseti
esseti / JoinObjects.py
Last active December 19, 2015 07:39
Function that i created to manage some data.
def joinObjects(objects, field):
'''
takes a list of objects and merge them.
objects are dicts
if objects have same keys, values are joined into a list.
[{'id':1,'tag':'ciao1'},
{'id':2,'tag':['ciao1',ciao3]},
{'id':1,'smt':'else2'},
{'id':2,'tag':'ciao2'}]
becomes
@esseti
esseti / BetterGmail
Created October 10, 2013 11:34
BetterGmail experience
//This function archives all the read mail that are not in the inbox
function markArchivedAsRead() {
//i add "has:nouserlabels" beacuse i have filter that skip the emails form the inbox and place them in lables. for that case i want to keep the emails as unread.
var threads = GmailApp.search('label:unread has:nouserlabels -label:inbox');
GmailApp.markThreadsRead(threads);
};
//this funciton cleans the inbox
function cleanInbox() {
// for all the inbox mail that are not starred and are read, it archives them
//labels: change the names accordingly to your needs.
//those labels have to be in the gmail.
var l_morning = GmailApp.getUserLabelByName("Delay/Morning");
var l_midday = GmailApp.getUserLabelByName("Delay/Midday");
var l_tonight = GmailApp.getUserLabelByName("Delay/Tonight");
var l_tomorrow = GmailApp.getUserLabelByName("Delay/Tomorrow");
var l_nextweek = GmailApp.getUserLabelByName("Delay/Nextweek");
var me = "YOUR EMAIL GOES HERE";
//array of all the labels: DO IT
@esseti
esseti / gist:fa6ba43cc37202bd1073
Created September 4, 2014 14:42
Performance generator PY
from datetime import datetime
import random
#user id
userId=122
sessionId = 143 #141 #142 #143
# this is needed to keep track of the new ids we create and use them in the indicator_measure
ids = []
id = int(datetime.utcnow().strftime("%s"))
@esseti
esseti / gist:a7db0251e62a33437de6
Created November 7, 2014 16:45
output example
http://127.0.0.1:8080/clubs?size=2
{
"nexPage": "E-ABAIICJ2oSZGV2fmZpbmUtcHJpZGUtNzMzchELEgRDbHViGICAgICAgIAJDIgCABQ=",
"total": 4,
"items": [
{
"description": "desc",
"id": 4785074604081152,
@esseti
esseti / gist:228a6c3bec325cca1d08
Created April 26, 2015 10:38
json list example
{
"results":[{"name":"item1"},{"name":"item2"},{"name":"item3"},{"name":"item4"},{"name":"item5"},{"name":"item6"},{"name":"item7"},{"name":"item8"}],
"total":8
}
@esseti
esseti / GcCourseFormCtrl.js
Last active August 29, 2015 14:20
Date conversion angular, directive
angular.module('gcCoachApp')
.controller('GcCourseFormCtrl', function ($scope, gcResourceCourses, $stateParams, gettext, $timeout) {
//...
$scope.editFn = function (course) {
$scope.edit = true;
//this is to overcome the problem in conversion.
//in this way we fake the conversion.
//we fill in the data that are shown in the form.
$scope.course._endDate = new Date(course.endDate);
$scope.course._startDate = new Date(course.startDate);