Skip to content

Instantly share code, notes, and snippets.

View ToeJamson's full-sized avatar

Joe Hanson ToeJamson

  • @observe.ai
  • San Francisco, CA
View GitHub Profile
@ToeJamson
ToeJamson / publisher.js
Created January 30, 2018 21:34
cryptocurrency price tracker
var pubnub = new PubNub({
publishKey: 'YOUR_KEYS_HERE',
subscribeKey: 'YOUR_KEYS_HERE'
});
var xhr = new XMLHttpRequest();
{
"timestamp": "2016-08-23T22:31:40.255Z",
"Novato": {
"geo": "38.1074° N, 122.5697° W",
"temperature": {
"F": "99.9",
"C": "37.7"
},
"humidity": "40.965",
"barometric": "1011.8",
public class FlightPathsTabContentFragment extends Fragment implements OnMapReadyCallback {
...
private static ImmutableMap<String, String> getNewLocationMessage(String userName, int randomLat, int randomLng, long elapsedTime) {
String newLat = Double.toString(generatorOriginLat + ((randomLat + elapsedTime) * 0.000003));
String newLng = Double.toString(generatorOriginLng + ((randomLng + elapsedTime) * 0.00001));
return ImmutableMap.<String, String>of("who", userName, "lat", newLat, "lng", newLng);
}
...
private void scheduleRandomUpdates() {
this.executorService = Executors.newSingleThreadScheduledExecutor();
public class FlightPathsMapAdapter {
...
private List<LatLng> polylinePoints;
...
public void locationUpdated(final Map<String, String> newLocation) {
if (newLocation.containsKey("lat") && newLocation.containsKey("lng")) {
String lat = newLocation.get("lat");
String lng = newLocation.get("lng");
doUiUpdate(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
} else {
public class FlightPathsPnCallback extends SubscribeCallback {
...
@Override
public void message(PubNub pubnub, PNMessageResult message) {
if (!message.getChannel().equals(watchChannel)) {
return;
}
try {
Log.d(TAG, "message: " + message.toString());
Map<String, String> newLocation = JsonUtil.fromJson(message.getMessage().toString(), LinkedHashMap.class);
...
@Override
public void onMapReady(GoogleMap map) {
this.map = map;
pubNub.addListener(new FlightPathsPnCallback(new FlightPathsMapAdapter((Activity) this.getContext(), map), Constants.FLIGHTPATHS_CHANNEL_NAME));
pubNub.subscribe().channels(Arrays.asList(Constants.FLIGHTPATHS_CHANNEL_NAME)).execute();
scheduleRandomUpdates();
}
...
public class FlightPathsTabContentFragment extends Fragment implements OnMapReadyCallback {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_flightpaths, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map_flightpaths);
mapFragment.getMapAsync(this);
return view;
public class LocationHelper implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
...
public LocationHelper(Context context, LocationListener mLocationListener) {
this.mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
this.mGoogleApiClient.connect();
this.mLocationListener = mLocationListener;
public class LocationPublishMapAdapter {
...
public void locationUpdated(final Map<String, String> newLocation) {
if (newLocation.containsKey("lat") && newLocation.containsKey("lng")) {
String lat = newLocation.get("lat");
String lng = newLocation.get("lng");
doUiUpdate(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
} else {
Log.w(TAG, "message ignored: " + newLocation.toString());
}
public class LocationPublishPnCallback extends SubscribeCallback {
...
@Override
public void message(PubNub pubnub, PNMessageResult message) {
if (!message.getChannel().equals(watchChannel)) {
return;
}
try {
Log.d(TAG, "message: " + message.toString());
Map<String, String> newLocation = JsonUtil.fromJson(message.getMessage().toString(), LinkedHashMap.class);