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
(note, the concept definitely works, but the implementation may have some bug, spelling mistakes etc). | |
Your problem is your request is missing the Cross Site Request Forgery token (CSRF). | |
This is a precaution django provide automatically to prevent others doing nefarious stuff. | |
Non-POST requests don't need the CSRF token, but for POST we need to do some magic: | |
we need to pass the CSRF token from django to javascript. This is best done like so: | |
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
/** | |
* converts querystring to object. Allows multiple values per key | |
* @param {String} querystring - optional querystring. default address bar | |
* @return {object} | |
*/ | |
self.querystringToObject = function(querystring){ | |
var params = {}; | |
(querystring || window.location.search) | |
.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) { | |
if (params[$1]){ |
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
// render playlist of songs | |
var template = '<li/><a>{{title}} by {{artist}}</a></li>'; | |
context = [ | |
{title: 'Killing Me Softly', artist: 'Roberta Flack'}, | |
{title: 'Run Around Sue', artist: 'Dion'}, | |
{title: 'Will You Still Love Me Tomorrow', artist: 'Shirelles'} | |
]; | |
$('<ul/>', {text: 'songs'}).html( | |
$.map(context, function(item){ |
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 rest_framework.views import APIView | |
from rest_framwrork import serializers | |
class NonDjangoModelSerializer(serializers.Serializer): | |
class Meta: | |
fields = ('field1', 'field1',) | |
field1 = serializers.Field() | |
field1 = serializers.Field() |
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
function appendSlash(url){ | |
return url + /\/$/.test(url) ? '' : '/'; | |
} |
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
// NewProductDescriptionField.jsx | |
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import TextField from 'material-ui/lib/text-field'; | |
import { | |
setFormFieldValidityMessage, | |
setNewProductData, | |
} from '../../actions'; |
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 array | |
import struct | |
def float_to_16_bit_pcm(raw_floats): | |
floats = array.array('f', raw_floats) | |
samples = [sample * 32767 for sample in floats] | |
raw_ints = struct.pack("<%dh" % len(samples), *samples) | |
return raw_ints |
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
class WavAudioEncoder { | |
encode = buffer => { | |
const channelData = buffer.getChannelData(0); | |
const length = buffer.length; | |
const data = [] | |
for (let i = 0; i < length; ++i) { | |
let x = channelData[i] * 0x7fff; | |
data.push(Math.round(x < 0 ? Math.max(x, -0x8000) : Math.min(x, 0x7fff))); | |
} |
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
Your client-side logging is turned on in prod. the logic I see is: | |
```js | |
const isDevEnv = () => { | |
return !!(global.NutmegConfig && global.NutmegConfig.ENVIRONMENT !== 'production'); | |
}; | |
export const logger = ({ interactionPath, properties }, subst = 'info') => { | |
if (isDevEnv()) { | |
// do the logging |