This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculate_score(votes, item_hour_age, gravity=1.8): | |
return (votes - 1) / pow((item_hour_age+2), gravity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To get all entities of one kind: | |
http://api.crunchbase.com/v/1/<plural-namespace> | |
Namespace can be: | |
companies | |
people | |
financial-organizations | |
products |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.tweet').each(function(index, element){ | |
var tweet = $(element).find('.entry-content').html().replace(new RegExp('<strong></strong><strong></strong>', 'gm'),' ').replace(new RegExp('<(/){0,1}strong>', 'gm'), '').replace(new RegExp('"', 'gm'),''); | |
var date = $(element).find('.published').attr('title'); | |
console.log(tweet+' <my-deliminator> ' +date); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Creating the data to be sent, note the escaped quotes that are required | |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); | |
nameValuePairs.add(new BasicNameValuePair("\A\"", "\"/api/v1/a/1/\"")); | |
nameValuePairs.add(new BasicNameValuePair("\"B\"", "\"/api/v1/b/1/\"")); | |
nameValuePairs.add(new BasicNameValuePair("\"C\"", "\"Hello from Android\"")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#s3_object_key is the file path relative to the your S3 URL where you want to store the file | |
Eg. | |
s3_object_key = '%s/%s' %(settings.USER_PROFILE_PICTURE_DIR, filename) | |
#file is the file that you have create locally either in ephermal storage (Like the Heroku Dyno) or permanent storage like your local file system | |
#Write to local storage | |
Eg. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
#Input date is a datetime instance | |
""" | |
>>> get_days_in_week(datetime(2013,06,17)) | |
[datetime.datetime(2013, 6, 17, 0, 0), datetime.datetime(2013, 6, 18, 0, 0), datetime.datetime(2013, 6, 19, 0, 0), datetime.datetime(2013, 6, 20, 0, 0), datetime.datet ime(2013, 6, 21, 0, 0), datetime.datetime(2013, 6, 22, 0, 0), datetime.datetime(2013, 6, 23, 0, 0)] | |
>>> get_days_in_week(datetime(2013,06,17)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
I faced a problem when sending a HTTP PATCH to django models containing an ImageField. | |
The same problem was discussed on the django-tastypie mailing list - https://groups.google.com/forum/?fromgroups#!topic/django-tastypie/cxrI6Cl1z4s | |
When PATCHing a resource, tasypie dehydrates the original object, merges the changed fields, and then simulates a PUT. This presents a problem for FileField and ImageField as dehydrating these fields produces a URL to the file, rather than the path relative to MEDIA_ROOT stored in the database. Therefore, after a PATCH to a model with FileFields, those fields will contain full URLs rather than relatives paths. | |
For example, consider a set up in which media for a site is served from http://media.example.com/. When PATCHing a resource containing a file field, a reference to "/directory/file.jpg" will be dehydrated to "http://media.example.com/directory/file.jpg" which is the value that will be written back to the database. - Nikolas Stevenson-Molnar, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from annoying.decorators import ajax_request | |
from django.contrib.auth import authenticate, login | |
from django.views.decorators.http import require_http_methods | |
@ajax_request | |
@require_http_methods(["POST"]) | |
def ajax_login(request): | |
username = request.POST['username'] | |
password = request.POST['password'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Directory sizes sorted in reverse order | |
du -ch --exclude=.git --max-depth=1|sort -hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py graph_models <app > <app>.dot | |
dot <app>.dot -Tpng -o <app>+`date`.png |
OlderNewer