inalogic

jay taoko

UI Demo

A few years ago, I created a demo showcasing lighting shaders. I recently updated the demo to support my latest development framework and voila!
The demo features some exotic lighting shaders. It was part of a user interface experiment I was running at the time.
The demo will be available through GitHub at some point.

YQL and Python

I used Python and Yahoo YQL to make queries about stocks and format the result in a shorter custom JSON object. Here is the code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json  
import yahoo.yql  
from pprint import pprint

def YahooFinance ():  
  response = yahoo.yql.YQLQuery().execute('select * from yahoo.finance.quote where symbol in ("YHOO","AAPL","GOOG","MSFT","TWTR")')

  if 'error' in response :
    print 'YQL query failed with error: "%s".' % response['error']['description']
    return ''
  elif ('query' not in response) or ('results' not in response['query']):
    print 'YQL response malformed.'
    return ''

  stocks = {}

  for stock in response['query']['results']['quote'] :
    ticker = stock['symbol'];
    change = stock['Change'];
    price = stock['LastTradePriceOnly'];
    stocks[ticker] = [price, change]

  stocks_json = json.dumps(stocks)
  return stocks_json

if __name__== '__main__':  
     pprint(YahooFinance())

Running the above code returns:

{
   "GOOG":[
      "1135.394",
      "+28.474"
   ],
   "TWTR":[
      "63.47",
      "+4.02"
   ],
   "AAPL":[
      "499.782",
      "-0.968"
   ],
   "YHOO":[
      "35.31",
      "+0.42"
   ],
   "MSFT":[
      "36.86",
      "+0.20"
   ]
}

Iso-8859-1 text decoding in Python

I have been using a web service that returns text in ISO-8859-1 encoding, also known as latin-1. My Python source code declares the unicode encoding to be utf-8.
Converting text string from iso-8859-1 to utf-8 is simple:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
...
utf8String = latin1String.decode('iso-8859-1')  
...