Skip to content

Instantly share code, notes, and snippets.

@sidishere
sidishere / hello_world.py
Created September 30, 2019 08:14
Hello World TensorFlow
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
# Start tf session
sess = tf.Session()
# Run the op
print(sess.run(hello))
@sidishere
sidishere / flower.js
Created October 1, 2019 08:23
Flower Classification using ANN
var dataB1 = [1, 1, 0];
var dataB2 = [2, 1, 0];
var dataB3 = [2, .5, 0];
var dataB4 = [3, 1, 0];
var dataR1 = [3, 1.5, 1];
var dataR2 = [3.5, .5, 1];
var dataR3 = [4, 1.5, 1];
var dataR4 = [5.5, 1, 1];
<?
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title_paired_devices"
android:layout_width="match_parent"
<?
xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="18sp"
/>
private BluetoothAdapter bluetoothAdapter;
Button  scanButton;
private static final int REQUEST_ENABLE_BT = 1;
private ArrayAdapter<String> mNewDevicesArrayAdapter;  
Setup oncreateFirst check if your smartphone supports BluetoothbluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) { Toast.makeText(this, "Device does not support bluetooth",
Toast.LENGTH_SHORT).show();
finish();
}
else if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_CANCELED)
Toast.makeText(this,"Please provide permission to turn on bluetooth",Toast.LENGTH_SHORT).show();
}
scanButton = (Button) findViewById(R.id.button_scan);
scanButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
doDiscovery();
v.setVisibility(View.GONE);
}
}); 
// Register for broadcasts when a device is discovered IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
this.registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
this.registerReceiver(mReceiver, filter);
// Get a set of currently paired devices
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
// If there are paired devices, add each one to the ArrayAdapter
if (pairedDevices.size() > 0) {
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
for (BluetoothDevice device : pairedDevices) {
pairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
} else {
@Override protected void onDestroy() { super.onDestroy();
// Make sure we're not doing discovery anymore
if (bluetoothAdapter != null)
{
bluetoothAdapter.cancelDiscovery();
}
// Unregister broadcast listeners
this.unregisterReceiver(mReceiver);
}