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
# FULL WORKING POST FOR JSON & FILE | |
def post(self, request, format=None): | |
up_file = request.data.get('file') | |
serializer = ridesSerializer(data=request.data) | |
if serializer.is_valid(): | |
serializer.save() | |
if up_file is not None: | |
if socket.getfqdn() == 'STG' or socket.getfqdn() == 'PRD': | |
destination = open(PRD_UPLOAD + up_file.name, 'wb+') | |
else: |
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
""" | |
Django REST Framework filtering by comma (used with Ember.js). | |
Change from the standard ?var=1&var=2 etc. | |
""" | |
# GET querystring i.e. ?var=1,2,4,6 | |
get_my_var = self.request.query_params.get('var', None) | |
if get_my_var: | |
my_var = get_my_var.split(',') | |
else: |
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
import csv | |
reader=csv.reader(open('UserstoImport.csv', 'r'), delimiter=',') | |
writer=csv.writer(open('UserstoImport_withoutduplicates.csv', 'w'), delimiter=',') | |
entries = set() | |
for row in reader: | |
key = (row[1], row[2]) # CSV rows by num |
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
/********************************************************************************* | |
Author: Nicholas Cole | |
Author URI: http://oceanbluecreative.com.au | |
License: MIT | |
Usage: Sass Partial for native UI tweaks in Cordova/PhoneGap apps | |
Gist: https://gist.github.com/ncole458/49bb6b0309572dc429ea | |
**********************************************************************************/ |
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
/** Preload Images (plays nicely with Cordova/PhoneGap i.e. stops images 'popping' in!) **/ | |
body { | |
color: $fontColor; | |
background: url('../images/bg.jpg') no-repeat -9999px -9999px, | |
url('../images/bg1.png') no-repeat -9999px -9999px, | |
url('../images/bg2.png') no-repeat -9999px -9999px, | |
url('../images/bg3.png') no-repeat -9999px -9999px, | |
url('../images/[email protected]') no-repeat -9999px -9999px, | |
url('../images/[email protected]') no-repeat -9999px -9999px, |
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
<div data-role="view" data-title="View One" id="view-one"> | |
<header data-role="header"> | |
<div data-role="navbar"> | |
<span data-role="view-title" id="one-title"></span> | |
</div> | |
</header> | |
<a data-role="button" data-mytitle="username 1" onclick="viewtwo(this)">go to view username 1</a> | |
<a data-role="button" data-mytitle="username 2" onclick="viewtwo(this)">go to view username 2</a> | |
</div> |
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
""" | |
Mailgun is a nice option over common Gmail & can be used with a custom domain | |
"" | |
# 1. setup a Mailgun account @ https://mailgun.com | |
# 2. add your domain & DNS records as provided on Mailgun (note: add "" around TXT records) | |
# 3. create new 'Route' with rules = match_recipient("[email protected]") & forward("[email protected]") | |
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" | |
EMAIL_HOST = "smtp.mailgun.org" |
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
""" | |
Find user/database entries within a km radius based on long/lat co-ords. | |
i.e. return all objects where longlat lies within 10km of my current long/lat. | |
Using with Django REST Framework but approach is same for any similar req. | |
""" | |
import math | |
def get_queryset(self): | |
user = self.request.user | |
lat = self.request.query_params.get('lat', None) |
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
# Simple version of Django queryset for objects within X long/lat radius | |
import math | |
def get_queryset(self): | |
user = self.request.user | |
lat = self.request.query_params.get('lat', None) | |
lon = self.request.query_params.get('long', None) | |
if lat and lon: | |
lat = float(lat) |
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
// https://en.wikipedia.org/wiki/Universally_unique_identifier | |
// https://en.wikipedia.org/wiki/Globally_unique_identifier | |
// No hyphens (-) in below but can be add in the 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx' | |
var uuid = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); | |
console.log(uuid); |
OlderNewer