Skip to content

Instantly share code, notes, and snippets.

View sourcec0de's full-sized avatar
:octocat:
Focusing

James R Qualls sourcec0de

:octocat:
Focusing
View GitHub Profile

Nutritionix Querying Language (NXQL)

NXQL allows developers to write more advanced queries against our data pool. Examples of what you can do with an advanced query:

  • Filter items by their type (show ONLY USDA items or ONLY CPG items)
  • Filter nutrient ranges (>100 calories AND <500 calories)

All requests are POST and require a valid JSON object be sent to https://api.nutritionix.com/v1_1/search You can paste any of the below JSON examples into this curl request and they will retrieve results assuming you have added your appKey, and appId.

Request Requirements

@sourcec0de
sourcec0de / django_setup_osx_10_8.sh
Created February 12, 2014 04:07
Setup Django and virtualenv on OSX 10.8
# Install python virtualenv
# this helps with managing python dependencies
# on a per env / application basis much easier
sudo pip install virtualenv
# Create a project folder to store you envs / projects
mkdir python_projects
cd python_projects/
# start a new ENV
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
@sourcec0de
sourcec0de / createNewIndex.sh
Created March 17, 2014 19:20
Create new ElasticSearch index with multiple mappings
curl -XPUT http://localhost:9200/newindex2 -d '{
"settings":{
// settings, analyzers, etc
},
// multiple mappings
"mappings":{
"type1":{
"properties":{

Nutritionix Querying Language (NXQL)

NXQL allows developers to write more advanced queries against our data pool. Examples of what you can do with an advanced query:

  • Filter items by their type (show ONLY USDA items or ONLY CPG items)
  • Filter nutrient ranges (>100 calories AND <500 calories)

All requests are POST and require a valid JSON object be sent to https://api.nutritionix.com/v1_1/search You can paste any of the below JSON examples into this curl request and they will retrieve results assuming you have added your appKey, and appId.

Request Requirements

Nutritionix Querying Language (NXQL)

NXQL allows developers to write more advanced queries against our data pool. Examples of what you can do with an advanced query:

  • Filter items by their type (show ONLY USDA items or ONLY CPG items)
  • Filter nutrient ranges (>100 calories AND <500 calories)

All requests are POST and require a valid JSON object be sent to https://api.nutritionix.com/v1_1/search You can paste any of the below JSON examples into this curl request and they will retrieve results assuming you have added your appKey, and appId.

Request Requirements

Get all USDA servings

If you want to retrieve a list of items by their NDB number (an id assigned by the USDA). Then you can send Nutritionix a filter to get all its sizes. "remote_db_id":3 tells us to filter by our USDA database and "remote_db_key":11143 tells us to filter by the NDB number.

curl -XPOST https://api.nutritionix.com/v1_1/search -d'
{
  "appId":"YOUR_APP_ID",
  "appKey":"YOUR_APP_KEY",
@sourcec0de
sourcec0de / varnish
Created May 8, 2014 16:48
multi site varnish config
backend example1 {
.host = "backend.example1.com";
.port = "8080";
}
backend example2 {
.host = "backend.example2.com";
.port = "8080";
}
sub vcl_recv {
if (req.http.host == "example1.com") {
@sourcec0de
sourcec0de / commands.md
Last active August 29, 2015 14:01
Purge all cache from varnish - found here http://mesmor.com/2012/02/29/varnish-purge-all-cache/

Clear all

curl -X BAN http://<VarnishServerIP>/

Clear specific cached file.

curl -X BAN http:///static/images.png
@sourcec0de
sourcec0de / no_global.js
Created May 8, 2014 18:57
How to avoid global variables in Javascript - https://www.youtube.com/watch?v=hQVTIJBZook#t=1679
/**
* Avoid Global Variables
* ========================
* One easy way to avoid global variables in javascript
* is to use closures. This is a best practice that not only makes it
* so you only initialize your variable 1 time, but you keep your global namespace clear.
*/
var digit_name = function () {
var names = ['zero','one','two',