Widespread Augmented Reality

Widespread Augmented Reality
Click on the image to get the Android Augmented Reality Heads up Display

Friday, January 10, 2020

Android code - Return to App After Turning on GPS in Settings

Use startActivityForResult from inside a Yes/No dialog box that turns on the GPS after starting the augmented reality heads up display app at www.spideronfire.com.

This code is inside the MainActivity that checks if the GPS is turned on. If it is, then go directly to a Splash Screen. If not, then open a Yes or No dialog and proceed to the Splash Screen if Yes. Developer comments left to illustrate how I found out the return and request codes.

if( !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
final AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.gps_not_found_title); // GPS not found
builder.setMessage(R.string.gps_not_found_message); // Want to enable?
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
//1-10-20 martin changed to startActForResult to return back to app
Intent locset = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(locset, 1);
//1-10-20 removed by martin
// finish();
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
//1-10=20 removed by martin
//System.gc();
//System.exit(0);
finish();
}
});
builder.create().show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Log.d("martin result code is ", Integer.toString(resultCode));
if (resultCode == 0) {
//Log.d("martin request code is ", Integer.toString(requestCode));
switch (requestCode) {
case 1:
//break;
Intent i = new Intent(this, SplashScreen.class);
startActivity(i);
//finish();
}
}
}

Saturday, January 4, 2020

What came from fucking up a tech interview with Facebook

Having decided to focus on what I already know, I disgarded learning binary search trees, which just so happened to be the coding question asked on the technical interview with Facebook. FAIL ! Oh well, moving on, I was prompted to look into its uses and ultimately how the game Doom came into existence. This led to the concept of Binary Search Partitions. Having experimented with 3d rendering back in the 90's, I instinctively knew the rendering limitations. This YouTube video explains how gave developers overcame them. https://www.youtube.com/watch?v=yTRzfKh4Tg0

Wednesday, January 1, 2020

Maya - Newly released single "Quicksand"

I would normally not post something like this, but feel compelled as I was at the hospital when she was born. https://mayamuzic.com/

Friday, November 1, 2019

PHP Set File Permissions

Recently, images uploaded to SpiderOnFire via the Widespread Augmented Reality app were suddenly writing to the server with permissions 0600. No es bueno, since these images need to be viewed in a web browser and on Android. Naturally, the server guys had no idea why the sudden deviation from the default upload permissions of 0644. Therefore I had to add "chmod($target_dir, 0644);" in all my upload and image resizing scripts. Seems to have fixed the issue, but I am sure that I have broken something else by going back in to change code that hasn't been touched in 4 years.

Monday, October 28, 2019

Augmented Reality Heads Up Display

Communicate anonymously through an augmented reality heads up display for Android only. Download app from Google Play.

Sunday, September 8, 2019

Python Machine Learning on Amazon stock prices

This Python code reads Amazon's historical stock prices from 2014 to 2019. I downloaded the CSV file from Yahoo Finance. The chart below shows how well this algorithm predicts stocks prices when compared to actual stock prices. The code was cobbled together from snippets at Analytics Vidhya and Medium.

# importing libraries
import pandas as pd
import numpy as np
from datetime import date, datetime
import calendar
#importing required libraries
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, Dropout, LSTM
# reading the data df = pd.read_csv('amzn2.csv')
# looking at the first five rows of the data
print('\n Original data:')
print(df.head())
print('\n Shape of original data:')
print(df.shape)
# setting the index as date
df['Date'] = pd.to_datetime(df.Date,format='%Y-%m-%d')
df.index = df['Date']
#creating dataframe
data = df.sort_index(ascending=True, axis=0)
new_data = pd.DataFrame(index=range(0,len(df)),columns=['Date', 'Close'])
#populate new data frame
for i in range(0,len(data)):
new_data['Date'][i] = data['Date'][i]
new_data['Close'][i] = data['Close'][i]
#setting index
new_data.index = new_data.Date
new_data.drop('Date', axis=1, inplace=True)
#creating train and test sets
dataset = new_data.values
#the csv file has 1260 records
train = dataset[0:630,:]
valid = dataset[630:,:]
#converting dataset into x_train and y_train
scaler = MinMaxScaler(feature_range=(0, 1))
scaled_data = scaler.fit_transform(dataset)
x_train, y_train = [], []
for i in range(60,len(train)):
x_train.append(scaled_data[i-60:i,0])
y_train.append(scaled_data[i,0])
x_train, y_train = np.array(x_train), np.array(y_train)
x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1))
# create and fit the LSTM network
model = Sequential()
model.add(LSTM(units=50, return_sequences=True, input_shape=(x_train.shape[1],1)))
model.add(LSTM(units=50))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train, epochs=1, batch_size=1, verbose=2)
#predicting 246 values, using past 60 from the train data
inputs = new_data[len(new_data) - len(valid) - 60:].values
inputs = inputs.reshape(-1,1)
inputs = scaler.transform(inputs)
X_test = []
for i in range(60,inputs.shape[0]):
X_test.append(inputs[i-60:i,0])
X_test = np.array(X_test)
X_test = np.reshape(X_test, (X_test.shape[0],X_test.shape[1],1))
closing_price = model.predict(X_test)
closing_price = scaler.inverse_transform(closing_price)
rms=np.sqrt(np.mean(np.power((valid-closing_price),2)))
print('\n Root Mean Square Deviation:')
print(rms)
#for plotting
#plot
import matplotlib.pyplot as plt
train = new_data[:630]
valid = new_data[630:]
valid['Predictions'] = closing_price
plt.plot(train['Close'])
plt.plot(valid[['Close','Predictions']])
plt.show()