Setup Pebble on Linux

The Pebble watches are no more but for those of us who love the old school, these watches are great. Unfortunately, the Pebble dev environment is hard to access. This is how to do it on Linux.

Download the Pebble SDK from here.

Create a folder called pebble-dev/ in your ‘home’ directory.
Change into that directory and extract the Pebble SDK that you just downloaded. If the sdk you downloaded is 4.5 the commands would be:
cd ~/pebble-dev/
tar -jxf ~/Downloads/pebble-sdk-4.5-linux64.tar.bz2

You should now have the directory ~/pebble-dev/pebble-sdk-4.5-linux64 with the SDK files and directories inside it.

Now add the pebble command to your path (so you can run pebble cmds without having to change into the directory where pebble SDK is) by running:
echo ‘export PATH=~/pebble-dev/pebble-sdk-4.5-linux64/bin:$PATH’ >> ~/.bash_profile && . ~/.bash_profile

Now we install pip and virtualenv:
sudo apt-get install python-pip python2.7-dev
sudo pip install virtualenv

Install the Python library dependencies locally by running each of these commands:
cd ~/pebble-dev/pebble-sdk-4.5-linux64
virtualenv –no-site-packages .env
source .env/bin/activate
pip install -r requirements.txt
deactivate

Get emulator dependencies:
sudo apt-get install libsdl1.2debian libfdt1 libpixman-1-0

Install NPM: sudo apt-get install npm

Install the archived SDK using pebble sdk install: https://github.com/aveao/PebbleArchive/raw/master/SDKCores/sdk-core-4.3.tar.bz2

Navigate to ~/.pebble-sdk, and make a blank file inside called NO_TRACKING using:
touch NO_TRACKING
If there is already a file called ENABLE_ANALYTICS in the folder, remove it.

Type into the command line: pebble –version
You should see a response like: Pebble Tool v4.5 (active SDK v4.3)

Your Pebble development environment should now be set up.

Create a new directory and run the following command in the root of the new directory:
pebble new-project hello-pebble
cd to the root of the hello-pebble directory.
Next, run: pebble build
When the code is compiled, you should see the message ‘build’ finished successfully and a number of new files in the build directory.

Pebble uses platform names to differentiate the three generations of Pebble smartwatches.
• Aplite is the platform name for Pebble and Pebble Steel.
• Basalt is the platform name for Pebble Time.
• And Chalk is the platform name for Pebble Time Round.

The run : pebble install –emulator aplite
This command launches the emulator, starts the selected platform, and installs the .pbw file stored in the build directory.

If you want to install the .pbw file to a watch:
pebble install — phone phone ip address

The MySQL server is running with the –secure-file-priv option so it cannot execute this statement

If you get this error after running the command:

LOAD DATA INFILE "path_to_file/file.csv"
INTO TABLE table_name
COLUMNS TERMINATED BY ','

Then just add the keyword LOCAL to the command and it will work:

LOAD DATA LOCAL INFILE "path_to_file/file.csv
INTO TABLE table_name"
COLUMNS TERMINATED BY ','

Copy MySql table

To create a copy of a table in MySql use the command:

CREATE TABLE foo SELECT * FROM bar

This will copy the table and the data.

To copy the table structure only, use the command:

CREATE TABLE foo SELECT * FROM bar LIMIT 0

POST data to URL using cURL and PHP.


$url = 'http://www.someurl.com';
$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );

Retrieve contents of file on SD card. Android

public void getFile(){
//Get the text file
        File file = new File(newFolder,"MyTest.txt");

//Read text from file
        StringBuilder text = new StringBuilder();

        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;

            while ((line = br.readLine()) != null) {
                text.append(line);
                text.append('\n');
            }
            br.close();
        }
        catch (IOException e) {
            Log.i("TAG","ERROR." + e);
        }

//Find the view by its id
        TextView tv = (TextView)findViewById(R.id.showFile);

//Set the text
        tv.setText(text.toString());
    }

Android. Create folder on SD card and write data

This will create a folder called TestFolder in /storage/emulated/0/ and write
to a text file called MyTest.txt in that folder.

File newFolder;//path to folder
File file;//path to file

public void writeData() {
createFolderIfNoneExists();

FileWriter writer = null;
try {
writer = new FileWriter(file);
// Writes the content to the file
writer.write("This\n is\n an\n example\n");
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public void createFolderIfNoneExists(){
try {
newFolder = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
try {
file = new File(newFolder, "MyTest" + ".txt");
file.createNewFile();
} catch (Exception ex) {
Log.i("TAG", "Exception: " + ex);
}
} catch (Exception e) {
Log.i("TAG", "Exception 2: " + e);
}
}

To view the contents of the file you will need a reference to the folders path (The ‘folder’ variable in the above code) and the name of the file.
then use this code:
Retrieve file from SD card

Check if you can Read or write to SD Card android

The following method will check and see what read and write options are available
before writing to the SD card.

public void writeTocard(){
    Log.i("TAG", "writeTocard started");
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        Log.i("TAG", "We can read and write to card");
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        Log.i("TAG", "We can only read to card");
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but all we need
        //  to know is we can neither read nor write
        Log.i("TAG", "We can NOT read or write to card");
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
}

Install Stetho to view SQLite and local files on android device.

Create java file MyApplication

import android.app.Application;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.facebook.stetho.Stetho;

public class MyApplication extends Application {

public void onCreate() {
//Log.i("TAG","MyApplication started");

super.onCreate();
//Stetho.initializeWithDefaults(this);

// Create an InitializerBuilder
Stetho.InitializerBuilder initializerBuilder =
Stetho.newInitializerBuilder(this);

// Enable Chrome DevTools
initializerBuilder.enableWebKitInspector(
Stetho.defaultInspectorModulesProvider(this)
);

// Enable command line interface
initializerBuilder.enableDumpapp(
Stetho.defaultDumperPluginsProvider(this)
);

// Use the InitializerBuilder to generate an Initializer
Stetho.Initializer initializer = initializerBuilder.build();

// Initialize Stetho with the Initializer
Stetho.initialize(initializer);

}
}

In the androidManifest file add:

<application
    android:name=".MyApplication">

In the build.gradle(Module.app) add the following to the dependencies:

//Stetho is used to see SQLite database in Chrome. Go to Chrome://inspect
// Stetho core
compile 'com.facebook.stetho:stetho:1.3.1'
//Optional network helper
compile 'com.facebook.stetho:stetho-okhttp:1.3.1'
compile 'com.facebook.stetho:stetho-js-rhino:1.4.2'

Android Parcelable List

If you have a List in the class that is implementing Parcelable:


public class myClass implements Parcelable{
private List myList;


...
protected myClass(Parcel in) {
this.myList = new LinkedList();
in.readList(myList, myClass.class.getClassLoader());
}


...
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(myList);
}
}

Get an SQLite database off an Android device.

Open up your command prompt and change directory (cd command)to the directory that has your adb.exe file in it. On windows it is usually in:
C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools.
Then type in:

adb pull /data/data/com.package.name/databases/YourDatabaseName

If the application is not debuggable then you will need to try another option:
You can create a backup of the application and then extract the backup file.
To do this type in:

adb backup "-f /FileName.ab -noapk com.package.name"

This will create an Android backup file (.ab) in the base directory of you main drive.
To extract this file, download the Android Backup Extractor at this address:

https://sourceforge.net/projects/adbextractor/

Extract the Android Backup Extractor files and then put your .ab file in the Android Backup Extractor folder. The open a command prompt and cd to the Android Backup Extractor folder. The type in the command:

java -jar abe.jar unpack YourFile.ab YourFile.tar

You will now have a zipped file in the Android Backup Extractor folder. Extract this file and you will have the applications database in the extracted folder.