Category Archives: Uncategorized

Defensive Coding

Clean Code: Easy to read Sample Minimal Thoughtful Verify and Coding contract Parameters Data Return Type Exception Clean, Testable, Predictable Methods: Good Name Focused Code Short Exception  

Posted in Uncategorized | Leave a comment

Flask+AngularJS Http Post Download file

Download csv file Server Side: @userprogressreport.route(‘/filedownload’, methods=[‘POST’]) def filedownload(): csv = “”””REVIEW_DATE”,”AUTHOR”,”ISBN”,”DISCOUNTED_PRICE” “1985/01/21″,”Douglas Adams”,0345391802,5.95 “1990/01/12″,”Douglas Hofstadter”,0465026567,9.95 “1998/07/15”,”Timothy “”The Parser”” Campbell”,0968411304,18.99 “1999/12/03″,”Richard Friedman”,0060630353,5.95 “2004/10/04″,”Randel Helms”,0879755725,4.50″”” file_name = “a.csv” response = make_response(csv) # This is the key: Set the right header for … Continue reading

Posted in Uncategorized | Leave a comment

Renaming a virtualenv folder without breaking it

http://stackoverflow.com/questions/6628476/renaming-a-virtualenv-folder-without-breaking-it If you want to fix this manually, that is the way: modify /tmp/project/env/bin/activate with yout favoriate editor like Vim, usually in Line 42 VIRTUAL_ENV=’/tmp/myproject/env’ => VIRTUAL_ENV=’/tmp/project/env’ 2. modify /tmp/project/env/bin/pip in Line 1 #!/tmp/myproject/env/bin/python => #!/tmp/project/env/bin/python

Posted in Uncategorized | Leave a comment

Load data in a json file into mongo db

“”” Load data in a json file into mongo db “”” import os import json from pymongo import MongoClient CONN_STR = ‘mongodb://{}’ CONN_STR_AUTH = ‘mongodb://{}:{}@{}’ DB_NAME = “” MONGO_SERVER = “127.0.0.1:27017” conn_str = CONN_STR.format(MONGO_SERVER) conn = MongoClient(conn_str) db = conn[DB_NAME] … Continue reading

Posted in Uncategorized | Leave a comment

Set row color in ui-grid conditionally

$scope.regularAssignmentGridOptions = { rowTemplate: ‘ ng-style=” row.entity.target == 4 && {\’font-weight\’:\’bold\’,\’color\’:\’red\’}”> ‘, columnDefs: [ {name: ‘grade’, width: ‘5%’}, {name: ‘type’, width: ‘8%’}, {name: ‘start’, width: ‘6%’, displayName: ‘Start Level/Score ‘}, {name: ‘target’, width: ‘6%’,displayName: ‘Target Level/Score ‘}, ] }

Posted in Uncategorized | Leave a comment

Python obj to JSON in Flask

Posted in Uncategorized | Leave a comment

Python object to/from JSON string

import json user = { “name”: “Test”, “_id”: “1234567890”, “address”: { “street”: “De Anza”, “city”: “San Jose” } } json_from_user = json.JSONEncoder().encode(user) print json_from_user user_from_json = json.JSONDecoder().decode(json_from_user) print user_from_json

Posted in Uncategorized | Leave a comment

Best article about H-bridge.

http://hardwarefun.com/tutorials/creating-robots-using-arduino-h-bridge The following is the explanation for the different pins of the IC. Vcc1 (pin 16) takes in regulated 5V for operating the IC. Vcc2 (pin 8) takes the external voltage (up to 36V) which 1,2 EN (pin 1) and … Continue reading

Posted in Uncategorized | Leave a comment

2000minuts 365days/$80 CDMA Cell phone

1. Buy a “Page Plus Cellular Prepaid Wireless Airtime Minutes Refill” at http://www.callingmart.com/Select 2 Steps to Buy a Wireless RefillSelect “Page Plus Cellular Prepaid Wireless Airtime Minutes Refill” and $80Before Checkout, try to find out(Google) Coupon Code. The coupon code … Continue reading

Posted in Uncategorized | Leave a comment

乐乐对求学和工作的见解

乐乐不喜欢上学,但是很喜欢西游记,投其所好,每天送乐乐上学时我都会套用西游记里的情节,把上学比作孙悟空学艺:“走,我们去斜月三星洞,去学72般变化”。今天在上学的路上,乐乐问我,孙悟空在斜月三星洞被开除以后,就做了自由自在的齐天大圣,我从斜月三星洞出来还要上中学,我什么时候才能做齐天大圣啊。我回答,等你上完中学,再上完大学,然后有了工作,你就可以自由自在地玩了。乐乐听了大惊,有了工作,那不就是弼马温吗?

Posted in Uncategorized | Leave a comment