Let's normalize the response of media data to only include the photos we want.
777135
function normalizeTwitterData(data,req,res){
  
  var normalized = {
    error: false,
    error_message: '',
    media: []
  }
  
  // console.dir(req.session.twitter)
  
  if( isTwitterOverCapacity() ){
    normalized.error = true
    normalized.error_message = "It appears Twitter is over capacity. Try again." 
  }
  else{
    
    console.log("Twitter Response array length: %s\n", data.length)
    // If the media response is empty...
    if(!data.length){
      normalized.error = true
      normalized.error_message = "We were unable to fetch any images from your media timeline."
      console.dir(data) 
      return processNormalizedResponse(normalized, req, res)
    }
    
    // We use a for loop so we can break out if
    // the cache is met
    for(i=0, len = data.length; i<len; i++){
      
      var el = data[i]

      // console.dir(el)
      // TODO: Session won't stash this much data so switch this logic to pull from redis.
      if( req.session.media_cache && isItemFirstCacheItem(el.id, req.session.media_cache.latest_id ) ){
        console.log('\n\nCache is same so we are breaking...\n\n')
        // update latest_id in cache
        normalized.latest_id = el.id
        // Now process the the response with new updated normalized data
        processNormalizedResponse(normalized, req, res)
        break
      }
      
      // The first time we run this, we need to stash the latest_id
      if( i === len-1 ){
        normalized.latest_id = data[0].id
      }
      
      // In the case of just pic.twitter.com....
      if(el.entities && el.entities.media && el.entities.media.length){

        var twitMediaObj = el.entities.media[0]

        var item = {
          full_url: twitMediaObj.media_url+":large",
          thumb_url: twitMediaObj.media_url+":thumb",
        }
        
        normalized.media.push(item)          

      }
      // Otherwise, we have 3rd part attributed providers.
      else if(el.entities && el.entities.urls && el.entities.urls.length && el.entities.urls[0].display_url){

        var url = el.entities.urls[el.entities.urls.length-1].display_url

        if(url.indexOf('instagr.am') > -1){

          var item = {
            full_url: "https://" + url + "/media/?size=l",
            thumb_url: "https://" + url + "/media/?size=t",
          }
          
          normalized.media.push(item)          
        
        }
        if(url.indexOf('twimg.com') > -1){
      
        // https://p.twimg.com/A128d2CCIAAPt--.jpg:small
        // https://p.twimg.com/A128d2CCIAAPt--.jpg:large
        
        }
        if(url.indexOf('flickr.com') > -1){
          /*
        
          <div class="thumbnail-wrapper" data-url="http://flickr.com/groups/dalekcakes">
            <img class="scaled-image" src="//farm7.static.flickr.com/6140/5917491915_8e92c65aa8.jpg"></div>
        
          */
        
          // WILL NEED TO FIGURE OUT FLICKR RESPONSE
        
          // Requires API call via photo ID, or just use twitter:
        
          /*
          https://widgets.platform.twitter.com/services/rest?jsoncallback=jQuery15205886323538143188_1346683837796&format=json&api_key=2a56884b56a00758525eaa2fee16a798&method=flickr.photos.getInfo&photo_id=7275880290&_=1346683837809
          */
        
          console.dir(el)
        }
        if(url.indexOf('twitpic.com') > -1){
      
          // POP OFF ID OF END OF TWITPIC URL
          // http://twitpic.com/9k68zj

          var url_id = url.split('com')[1] // includes slash

          var item = {
            full_url: "https://twitpic.com/show/iphone" + url_id,
            thumb_url: "https://twitpic.com/show/iphone" + url_id,
          }

          normalized.media.push(item)          
      
        }
        // if(url.indexOf('etsy.am') > -1){}

        if(url.indexOf('twitgoo.com') > -1){
          // http://twitgoo.com/66akxy/img

          var item = {
            full_url: url + '/img',
            thumb_url: url + '/img',
          }

          normalized.media.push(item)          

        }
        // Daily booth closed down....
        // if(url.indexOf('dailybooth.com') > -1){
        //   console.log(url)
        //   request({
        //     followRedirect: false,
        //     uri: 'http://'+url,
        //     callback: function(e,r,b){
                // need to handle errors better...
        //       if(e) console.error(e)
        //       
        //       console.dir(r)
        // 
        //       var id = r.headers.location.split('/').pop()
        //       
        //       request({
        //         uri: "https://api.dailybooth.com/v1/picture/" + id + ".json",
        //         json: true,
        //         callback: function(e,r,b){
        //           if(e) return console.error(e)
        //           /*
        //           urls: 
        //             { tiny: 'http://d1oi94rh653f1l.cloudfront.net/15/pictures/tiny/78e4b486c80b29435504d94fdf626b7c_29230840.jpg',
        //               small: 'http://d1oi94rh653f1l.cloudfront.net/15/pictures/small/78e4b486c80b29435504d94fdf626b7c_29230840.jpg',
        //               medium: 'http://d1oi94rh653f1l.cloudfront.net/15/pictures/medium/78e4b486c80b29435504d94fdf626b7c_29230840.jpg',
        //               large: 'http://d1oi94rh653f1l.cloudfront.net/15/pictures/large/78e4b486c80b29435504d94fdf626b7c_29230840.jpg' 
        //             }
        //           
        //           { error: 
        //              { error: 'rate_limit',
        //                error_description: 'Rate limit exceeded.',
        //                error_code: 412 } }
        //           var item = {
        //             full_url: b.urls.large + '/img',
        //             thumb_url: b.urls.small + '/img',
        //           }
        //           */
        //           
        //           if( (r.statusCode >= 400) || b.error) {
        //             console.log('Fail. '.red +'Status Code for Daily Booth request:  %s', r.statusCode)
        //             console.error(b.error)
        //           }
        //           else{
        //             
        //             var item = {
        //               full_url: b.urls.large,
        //               thumb_url: b.urls.small,
        //             }
        //             
        //             normalized.media.push(item)          
        //           }
        //           
        //           delay = false
        //           
        //           processNormalizedResponse(normalized, req, res)
        //           
        //         } // end inner request callback
        //       }) // end request()
        //     } // end outer request callback
        //   }) // end request()
        //   
        //   // Because of the async nature of the above request() calls,
        //   // we set the delay here and mark it false in the last callback
        //   if(!delay) delay = true
        //   
        // }
        if(url.indexOf('yfrog.com') > -1){
          // console.dir(el)

          var item = {
            full_url: "https://" + url + ":tw1",
            thumb_url: "https://" + url + ":tw1",
          }

          normalized.media.push(item)          
        
        }
        // if(url.indexOf('lockerz.am') > -1){}
        // if(url.indexOf('kiva.am') > -1){}

        // if(url.indexOf('kickstarter.com') > -1){}
        if(url.indexOf('dipdive.com') > -1){
          isVideo = false || true; // could be photo
        
        }
        // if(url.indexOf('photobucket.com') > -1){}
        // if(url.indexOf('with.me') > -1){}
        // if(url.indexOf('facebook.com') > -1){}
        if(url.indexOf('deviantart.com') > -1 || url.indexOf('fav.me') > -1){
        
          // TODO: IMAGES DON'T SHOW UP?
        
        }
      
      } // end if el.entities.url

    } // end forloop
    
  } // end else capacity
  
  return processNormalizedResponse(normalized, req, res)
  
}
1347053
def normalize_bboxes(bboxes, rows, cols):
    """"""
    return [normalize_bbox(bbox, rows, cols) for bbox in bboxes]
885143
def _clean_data(api_response):
    '''
    
    '''
    data = {}
    data.update(api_response['DATA'])

    if not data:
        response_data = api_response['DATA']
        data.update(response_data)

    return data
1342075
def adjust_response(self, response):
        ''

        try:
            c1 = self._replace(response.content,
                               self.header_placeholder,
                               self.embedded_holder.css)

            response.content = self._replace(c1,
                                             self.footer_placeholder,
                                             "\n".join([self.embedded_holder.config,
                                                        self.embedded_holder.scripts]))
        except AttributeError:
            # Catch the "FileResponse instance has no `content` attribute" error when serving media files in the Django development server.
            pass

        return response
358518
function normalizeResponse(response)
{
  // if the response doesn't already have a getResponseHeader() method, add one
  if (response && !response.getResponseHeader)
  {
    response.getResponseHeader = function(header)
    {
      return response.headers && response.headers[
              Util.isString(header) ? header.toLowerCase() : header];
    };
  }

  return response;
}
41148
def normalize_result(result, default, threshold=0.2):
    """"""
    if result is None:
        return default
    if result.get('confidence') is None:
        return default
    if result.get('confidence') < threshold:
        return default
    return normalize_encoding(result.get('encoding'),
                              default=default)
60599
def people_getPublicPhotos(user_id, per_page='', page=''):
    """"""
    method = 'flickr.people.getPublicPhotos'
    data = _doget(method, user_id=user_id, per_page=per_page, page=page)
    photos = []
    if hasattr(data.rsp.photos, "photo"): # Check if there are photos at all (may be been paging too far).
        if isinstance(data.rsp.photos.photo, list):
            for photo in data.rsp.photos.photo:
                photos.append(_parse_photo(photo))
        else:
            photos = [_parse_photo(data.rsp.photos.photo)]
    return photos
230863
def parse_photo(data):
    
    return MeetupPhoto(
        id=data.get('photo_id', data.get('id', None)),
        url=data.get('photo_link', None),
        highres_url=data.get('highres_link', None),
        thumb_url=data.get('thumb_link', None)
    )
562771
def __pull_image_info(self, title, imageinfo, normalized):
        
        for info in imageinfo:
            info.update({'title': title})

            # get API normalized "from" filename for matching
            _from = None
            for norm in normalized:
                if title == norm['to']:
                    _from = norm['from']

            # let's put all "metadata" in one member
            info['metadata'] = {}
            extmetadata = info.get('extmetadata')
            if extmetadata:
                info['metadata'].update(extmetadata)
                del info['extmetadata']

            self.__insert_image_info(title, _from, info)
771266
def parse_image_response(self, response):
        
        if 'xml' in response.headers.get('Content-Type'):
            # Got an XML response, likely an error code.
            xml = xmltodict.parse(response.text)
            self.analyze_reply_code(xml_response_dict=xml)

        obj = self._response_object_from_header(
            obj_head_dict=response.headers,
            content=response.content)
        return obj
530085
def binarizing(img,threshold):
    
    pixdata = img.load()
    w, h = img.size
    for y in range(h):
        for x in range(w):
            if pixdata[x, y] < threshold:
                pixdata[x, y] = 0
            else:
                pixdata[x, y] = 255
    return img
1318915
function normalize(result) {
  return {
    relevance: result.relevance || 0,
    language: result.language || null,
    value: result.value || []
  }
}
663270
def _correctArtefacts(self, image, threshold):
        '''
        
        '''
        image = np.nan_to_num(image)
        medianThreshold(image, threshold, copy=False)
        return image
209823
function normalizeSnapshot() {
		snapshot.heap.forEach(function(obj) {
			if (!obj) return;
			if (obj.function && obj.function.type === 'BindFunc') {
				obj.function.target = convertUndefined(obj.function.target)
				obj.function.arguments = obj.function.arguments.map(convertUndefined)
			}
			if ('env' in obj) {
				obj.env = convertUndefined(obj.env)
			}
			if ('prototype' in obj) {
				obj.prototype = convertUndefined(obj.prototype)
			}
			for (var k in obj.properties) {
				var prty = obj.properties[k]
				if ('value' in prty) {
					prty.value = convertUndefined(prty.value)
				}
				if ('get' in prty) {
					prty.get = convertUndefined(prty.get)
				}
				if ('set' in prty) {
					prty.set = convertUndefined(prty.set)
				}
			}
		})
	}
647279
async def guessImageMetadataFromHttpData(response):
    
    metadata = None
    img_data = bytearray()

    while len(img_data) < CoverSourceResult.MAX_FILE_METADATA_PEEK_SIZE:
      new_img_data = await response.content.read(__class__.METADATA_PEEK_SIZE_INCREMENT)
      if not new_img_data:
        break
      img_data.extend(new_img_data)

      metadata = __class__.guessImageMetadataFromData(img_data)
      if (metadata is not None) and all(metadata):
        return metadata

    return metadata
522275
def clean_video_data(_data):
    

    data = _data.copy()

    # TODO: fix this ugliness
    title = data.get('title')
    if title:
        data['title'] = clean_title(title)

    return data
1095585
def clean_picture(self):
        
        if self.cleaned_data.get('picture'):
            picture_data = self.cleaned_data['picture']
            if 'error' in picture_data:
                raise forms.ValidationError(_(u'Upload a valid image. '
                            'The file you uploaded was either not an image '
                            'or a corrupted image.'))
                
            content_type = picture_data.content_type
            if content_type:
                main, sub = content_type.split('/')
                if not (main == 'image' 
                            and sub in defaults.ACCOUNTS_PICTURE_FORMATS):
                    raise forms.ValidationError(_(u'%s only.' % 
                                    defaults.ACCOUNTS_PICTURE_FORMATS))
        
            if picture_data.size > int(defaults.ACCOUNTS_PICTURE_MAX_FILE):
                raise forms.ValidationError(_(u'Image size is too big.'))
            return self.cleaned_data['picture']