Skip to content

Instantly share code, notes, and snippets.

@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'
// 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 / 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();
@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(){
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 / 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;
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl
@fumingshih
fumingshih / gist:4942199
Created February 13, 2013 04:10
A shell script that allows you to install recommended fonts for texlive on Mac
curl http://packages.ubuntu.com/quantal/all/texlive-fonts-recommended/filelist | sed -En 's!/usr/share/texlive/texmf-dist/fonts/tfm/.*/([^/]+)/[^/]+\.tfm$!\1!p'
@fumingshih
fumingshih / gist:2970112
Created June 22, 2012 03:50
Fix FunfManager.unrequestAllData
public void unrequestAllData2(DataListener listener){
Map<IJsonObject,List<DataRequestInfo>> changedEntrySet = new HashMap<IJsonObject, List<DataRequestInfo>>();
synchronized (dataRequests) {
for (Entry<IJsonObject,List<DataRequestInfo>> entry : dataRequests.entrySet()) {
IJsonObject probeConfig = entry.getKey();
List<DataRequestInfo> dataRequestInfos = entry.getValue();
def get_loc_data(self):
return [x for x in self.numeric_lst if x[9] == 0]
def get_sit_data(self):
return [x for x in self.numeric_lst if x[9] == 1]
def get_bluetooth_data(self):
return [x for x in self.numeric_lst if x[9] == 2]
def get_location(self, idx):
return self.name_map['loc'][idx]