Skip to content

Instantly share code, notes, and snippets.

Very active

Francis Nduba Numbi francisnnumbi

Very active
View GitHub Profile
View gist:410ed55635e8ec68a625ad88f3592c9d

Automatically start XAMPP Apache when logging into MacOSX.

  1. Create xampp.startapache.plist in /Library/LaunchDaemons with the following content :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Installing an Android ROM with your Mac via Heimdall and bash

Because every time I want to flash a new ROM, I forgot how I did it the last time.

This is how I re-flashed my unbranded Samsung Galaxy S4 (german black edition) with a stock ROM (because Cyanogenmod crashed my phone all the time). The correct Stock ROM for my Galaxy S4 is: I9505XXUHOJ2_I9505OXAHOJ2_I9505XXUHOJ2

Software you need

  • adb
  • heimdall (brew cask install heimdall-suite)
francisnnumbi /
Created Nov 4, 2017
stage 1 : trying to solve math expression such as (12+5)(2-5)/(6-3) it is evolving...
import java.util.*;
public class Calculation {
private static final String OPS = "+*/^%";
private static ArrayList<Character> ops = new ArrayList<>();
private static String[] vars;
private static StringBuilder expression;
francisnnumbi /
Last active Jan 8, 2018
Converting a String date from one displayable format to another.
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
public class MyDateUtils {
* Convert from one format to another
* @param date the date in string. e.g. "23/10/2014 23:45.50"
* @param currentFormat the actual format of date. e.g. "dd/MM/yyyy"
francisnnumbi /
Created Sep 9, 2017
Implementing a simple prompt dialog with internal listener. How to use it: SimplePromptDialog.from(this) .showPrompt("test title", "", new SimplePromptDialog.OnDismissListener(){ @override public void onDismiss(String message) { if(message != null) { // use the message } } });
import android.content.DialogInterface;
import android.widget.EditText;
import android.content.*;
public class SimplePromptDialog {
private static Activity activity;
francisnnumbi / SaveToFileUsingFormatter.txt
Created Aug 5, 2017
Did you know that you can save plain text to file using Formatter.class? You need to import java.util package. You'll use format() method for that and specify the format expression to be of type String - "%s".
View SaveToFileUsingFormatter.txt
public void saveText(File file, String content){
Formatter out = new Formatter(file);
out.format("%s", content);
}catch(IOException ioe){}
francisnnumbi / backgroundTaskOfActivity.txt
Created Aug 4, 2017
If you want a background task (thread) to update your ui, this is the snippet. You need 3 things: - a handler that enables repetition; - the activity's method runOnUiThread() and; - a runnable object in which run() method is implemented. All the ui updates are put inside run() method. And set the pause between repetitions with handler inside run…
View backgroundTaskOfActivity.txt
private void bgdrun() {
final Handler handler = new Handler();
runOnUiThread(new Runnable(){
public void run() {
// update your views here.
// do not use loops in here.
handler.postDelayed(this, 1000);
francisnnumbi / ReadingPlainTextUsingScanner.txt
Created Aug 4, 2017
Simplest way of reading plain text from external file using Scanner.class. Remember to include this permission in your manifest file: READ_EXTERNAL_STORAGE but if you got write permission, it is not necessary to include read permission as it is already incorporated in write permission.
View ReadingPlainTextUsingScanner.txt
public String readText(File file){
StringBuilder builder = new StringBuilder();
Scanner scanner = new Scanner(file);
francisnnumbi / hidekeyboardsnippet.txt
Created Aug 4, 2017
Do you want to hide your soft keyboard programmatically? For example, when you click a button or when you press ENTER (for single line editText). This snippet method is all you need. Call it and pass in any view available (layout, textView, editText, button,...)
View hidekeyboardsnippet.txt
private void hideKeyboard(View v) {
try {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} catch (Exception e) {}
francisnnumbi / Notification.txt
Created Jul 20, 2017
This is a snippet of a method that enables you to show a notification with minimum requirements. 3 arguments are required: - the id that is unique, if you use same id for different notifications the previous ones will be replaced by recent ones. - title of the notification. - message to display. But remember that a notification needs an icon for…
View Notification.txt
* This is the simplest method that enables you to pop a notification with a minimum requirement
* Remember to add an icon as an icon or a drawable
public void popNotification(int notifId, String title, String msg){
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notif = new Notification.Builder(getBaseContext())
You can’t perform that action at this time.