Skip to content

Instantly share code, notes, and snippets.

View francisnnumbi's full-sized avatar
😀
Learn and share

Francis Nduba Numbi francisnnumbi

😀
Learn and share
View GitHub Profile
@francisnnumbi
francisnnumbi / gist:410ed55635e8ec68a625ad88f3592c9d
Created July 14, 2020 14:20 — forked from djandyr/gist:3c083bd1790aeecd1c9e
XAMPP Automatically start Apache (MacOS)

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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@francisnnumbi
francisnnumbi / flash-android-rom-with-heimdall-on-mac.md
Created July 10, 2020 11:25 — forked from kevinpapst/flash-android-rom-with-heimdall-on-mac.md
Flash a new Android ROM on Mac with ADB and Heimdall

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
francisnnumbi / Calculation.java
Created November 4, 2017 09:41
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
francisnnumbi / MyDateUtils.java
Last active January 8, 2018 11:03
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 HH:mm.ss"
@francisnnumbi
francisnnumbi / SimplePromptDialog.java
Created September 9, 2017 11:16
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.app.Activity;
import android.support.v7.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.EditText;
import android.app.*;
import android.content.*;
public class SimplePromptDialog {
private static Activity activity;
@francisnnumbi
francisnnumbi / SaveToFileUsingFormatter.txt
Created August 5, 2017 21:34
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".
public void saveText(File file, String content){
try{
Formatter out = new Formatter(file);
out.format("%s", content);
out.close();
}catch(IOException ioe){}
}
@francisnnumbi
francisnnumbi / backgroundTaskOfActivity.txt
Created August 4, 2017 19:10
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…
private void bgdrun() {
final Handler handler = new Handler();
runOnUiThread(new Runnable(){
@Override
public void run() {
// update your views here.
// do not use loops in here.
handler.postDelayed(this, 1000);
}
});
@francisnnumbi
francisnnumbi / ReadingPlainTextUsingScanner.txt
Created August 4, 2017 09:18
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.
public String readText(File file){
StringBuilder builder = new StringBuilder();
try{
Scanner scanner = new Scanner(file);
while(scanner.hasNext()){
builder.append(scanner.nextLine());
builder.append('\n');
}
scanner.close();
}
@francisnnumbi
francisnnumbi / hidekeyboardsnippet.txt
Created August 4, 2017 07:17
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,...)
private void hideKeyboard(View v) {
try {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} catch (Exception e) {}
}
@francisnnumbi
francisnnumbi / Notification.txt
Created July 20, 2017 18:31
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…
/**
* 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())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)