Skip to content

Instantly share code, notes, and snippets.

@fumingshih
fumingshih / gist:5605501
Created May 18, 2013 19:21
code for gson factory
public TypeAdapterFactory getPipelineFactory() {
return getPipelineFactory(this);
}
private static PipelineFactory PIPELINE_FACTORY;
public static PipelineFactory getPipelineFactory(Context context) {
if (PIPELINE_FACTORY == null) {
PIPELINE_FACTORY = new PipelineFactory(context);
}
return PIPELINE_FACTORY;
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);
@fumingshih
fumingshih / PostSpreadsheetdata.js
Created December 1, 2013 21:04
GAS code that use RowUtilities to read out the spreadsheet data and send it as json using post.
var db = ScriptDb.getMyDb();
// ===== This script will post the data to itself and we can have another gs file to trigger posting another copy of the data ===========
// The idea is to post a payload with id and data
// var payload = {'id': id,
// 'data': data
// }
// data will be computed from RowUtilities
function readSpreadsheetAsJson(){
@fumingshih
fumingshih / StaticMapFromSpreadsheetData.js
Created December 1, 2013 21:08
GAS script that read the location data from spreadsheet and create a static map in the uiApp.
// test showing the map on website
function doGet() {
//var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('locations');
var sheet = SpreadsheetApp.openById('0AmcViZZV0aRjdEZ0amxsQ2NERmthRWx6aF9MVlgyUHc').getSheetByName('locations');
// Read out the data for my locations
var locations = sheet.getRange(2, 1, sheet.getLastRow() - 1, 3).getValues();
// Collecting all unique affected app version for a given data set
var jsonStats = [
{app_versions: ['1.2','1.2.3']},
{app_versions: null},
{app_versions: ['1.2','1.3']}
];
var app_versions = _.uniq(_.flatten(_.compact(_.map(jsonStats, function(day){return day.app_versions }))));
// ["1.2", "1.2.3", "1.3"]
// Bye bye stupid for loops!
@fumingshih
fumingshih / docdictify
Created May 2, 2014 19:12
This piece of python code converts python dictionary object to have access like object attributes
class dotdictify(dict):
marker = object()
def __init__(self, value=None):
if value is None:
pass
elif isinstance(value, dict):
for key in value:
self.__setitem__(key, value[key])
else:
raise TypeError, 'expected dict'