Skip to content

Instantly share code, notes, and snippets.

View ishmaelmakitla's full-sized avatar

Ishmael Makitla ishmaelmakitla

View GitHub Profile
@ishmaelmakitla
ishmaelmakitla / db.js
Created March 13, 2017 10:02
This gist illustrates the use of Knex and Bookshelf in a NodeJS application. This script defines an KNEX object which connects to a running instance of PostgreSQL;
var pg = require('pg');
//Optionally, you may have config file that has the parameters used to connect to PG
//var config = require('../utilities/config');
var knex = require('knex')({
client: 'pg',
connection: {
host : '127.0.0.1',
port : '5432',
user : 'some-role-name',
/**
* This utility function is used to prompt the user to give details of the traffic incident
*/
public static void renderIncidentReportDialog(final Context appContext){
try{
final Dialog dialog = new Dialog(appContext);
dialog.setContentView(R.layout.report_creator_dialog_layout);
dialog.setTitle("Traffic Incident Report");
<?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" >
<Spinner
android:id="@+id/types_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
public class Item{
String entity_id;
String attribute_set_id;
String type_id;
public Item(){}
public String getEntityId(){return this.entity_id;}
public void setEntityId(String id){this.entity_id = id;}
package za.co.ishlema.blog.examples;
import java.io.Serializable;
import java.util.UUID;
import com.google.gson.Gson;
/**
* This class represents the user of the app.
* Its serialized JSON is stored in the Shared Preferences (if the user elects a 'remember me' option when loging in)
*
private void getUserLogoutConfirmation(Context context, final SharedPreferences sharedPrefs){
new AlertDialog.Builder(context)
.setTitle("Loggin out of IshLema App")
.setMessage("Loging out will make the system ask you for username and password next time you use it.")
.setPositiveButton("Fine, Forget Me", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//remove the cached user
try{
Editor sharedPrefsEditor = sharedPrefs.edit();
sharedPrefsEditor.remove(USER_SHAREDPREFERENCE_KEY);
<?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" >
<LinearLayout
android:id="@+id/loginContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
package za.co.ishlema.blog.examples;
/**
* This is an example of implementing "remember me" login option using SharedPreferences in Android.
* @author Ishmael Makitla,
*
* */
public class LoginActivity extends Activity {
private static final String TAG = LoginActivity.class.getSimpleName();
public static final String USER_SHAREDPREFERENCE_KEY = "userPrefKey";
public static final String USER_SHAREDPREFERENCE_VALIDITY_KEY = "valid";
package za.co.ishlema.blog.examples;
import java.util.HashMap;
import java.util.Map.Entry;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
/**
This object represents JSON string:
{
"email" : "kalle@hotmail.se",
"waypoints" : {
"-KH9UAPH5NmLJExaUa5g" : {
"-KH9UAPH5NmLJExaS2s" : {
"latitude" : 111,
"longitude" : 111.1
}