Skip to content

Instantly share code, notes, and snippets.

View hello-alf's full-sized avatar
🏠
Working from home

Luis Alfredo Quispe Villca hello-alf

🏠
Working from home
  • La Paz, Bolivia
  • 16:00 (UTC -04:00)
View GitHub Profile
@hello-alf
hello-alf / api.py
Created June 26, 2016 02:30 — forked from SeanHayes/api.py
TastyPie: Return 400 Bad Request when deserialization fails
from tastypie import http
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.resources import ModelResource
class CustomModelResource(ModelResource):
def deserialize(self, request, data, format='application/json'):
try:
return super(CustomModelResource, self).deserialize(request, data, format=format)
except Exception as e:
# if an exception occurred here it must be due to deserialization
@hello-alf
hello-alf / precise_round.js
Created October 1, 2015 16:33 — forked from a-r-m-i-n/precise_round.js
How to round correctly in JavaScript
function sign(num) {
// IE does not support method sign here
if (typeof Math.sign === 'undefined') {
if (num > 0) {
return 1;
}
if (num < 0) {
return -1;
}
return 0;