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 / LineNumberedEditText
Created May 16, 2017 08:32
implementing an EditText with line number on the left. What is new is: - get/set line number margin gap - set line number visible - set line number color Everything is done in the overridden onDraw() method.
import android.widget.*;
import android.util.*;
import android.content.*;
import android.graphics.*;
/**
* the simple implementation of an EditText where each line is numbered on the left
*/
public class LineNumberedEditText extends EditText {
@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 / EditorUtils.java
Created May 29, 2017 03:48
i need your advice. this is the class i use for highlighting my text in my EditText. It works fine, well to some extents! But when the text starts growing in size, it starts freezing! I know, this is due to multiple while...loops. My concern is the way of changing so that i have at least one loop.
package fnn.smirl.note.util;
import java.util.regex.*;
import android.text.*;
import android.text.style.*;
import android.graphics.*;
import java.util.*;
public class EditorUtils implements Tokenize {
public static void formatEditor(Editable ssb) {
@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 / 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 / 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 / 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();
}