Skip to content

Instantly share code, notes, and snippets.

View kgundula's full-sized avatar

Khuthadzo Gundula kgundula

View GitHub Profile
@kgundula
kgundula / Menu Tree Builder
Created November 13, 2013 09:31
Menu Tree Builder from an sql resultset.
/*
* This function can be use to build a menu tree.
*/
function buildMenuTree($menus, $parentId = 0) {
$branch = array();
foreach ($menus as $menu) {
if ($menu['parent_id'] == $parentId) {
$children = $this->buildMenuTree($menus, $menu['id']);
if ($children) {
$menu['child'] = $children;
@kgundula
kgundula / MSSQL equivalent MySQL query with limit clause
Last active January 4, 2016 06:09
MSSQL equivalent MySQL query with limit clause
SELECT * FROM
(
SELECT TOP 30 *, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS rnum
FROM table1
) a
WHERE rnum > 10
@kgundula
kgundula / boundbox
Last active September 22, 2016 15:43
Calculate distance between two sets lat/lon coordinates and Calculate destination lat/lon given a starting point lat/lon cordinates, bearing, and distance, and Calculate the bounding box
// Calculating the bounding box
function boundbox ($lat, $lon, $distance, $units="km") {
return array ( "N" => getDestinationCoordinates ($lat,$lon, 0,$distance,$units),
"E" => getDestinationCoordinates ($lat,$lon, 90,$distance,$units),
"S" => getDestinationCoordinates ($lat,$lon, 180,$distance,$units),
"W" => getDestinationCoordinates ($lat,$lon, 270,$distance,$units));
}
@kgundula
kgundula / color codes array
Created August 8, 2014 09:32
PHP Array of Color Codes
$color_list = array("#5d8aa8","#f0f8ff","#e32636","#efdecd","#e52b50","#ffbf00","#ff033e","#9966cc","#a4c639","#f2f3f4","#cd9575","#915c83","#faebd7","#008000","#8db600","#fbceb1","#00ffff","#7fffd4","#4b5320","#e9d66b","#b2beb5","#87a96b","#ff9966","#a52a2a","#fdee00","#6e7f80","#ff2052","#007fff","#f0ffff","#89cff0","#a1caf1","#f4c2c2","#21abcd","#fae7b5","#ffe135","#848482","#98777b","#bcd4e6","#9f8170","#f5f5dc","#ffe4c4","#3d2b1f","#fe6f5e","#000000","#ffebcd","#318ce7","#ace5ee","#faf0be","#0000ff","#a2a2d0","#6699cc","#0d98ba","#8a2be2","#8a2be2","#de5d83","#79443b","#0095b6","#e3dac9","#cc0000","#006a4e","#873260","#0070ff","#b5a642","#cb4154","#1dacd6","#66ff00","#bf94e4","#c32148","#ff007f","#08e8de","#d19fe8","#f4bbff","#ff55a3","#fb607f","#004225","#cd7f32","#a52a2a","#ffc1cc","#e7feff","#f0dc82","#480607","#800020","#deb887","#cc5500","#e97451","#8a3324","#bd33a4","#702963","#007aa5","#e03c31","#536872","#5f9ea0","#91a3b0","#006b3c","#ed872d","#e30022","#fff600","#a67b5b","#4b3621","#1e4d2b","#a3
@kgundula
kgundula / Java MD5 Hash Generator
Created August 28, 2015 08:58
Java MD5 Hash Generator which is equivalent to PHP MD5()
public static String md5Hash (String input) throws NoSuchAlgorithmException {
String result = input;
if(input != null) {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(input.getBytes());
BigInteger hash = new BigInteger(1, messageDigest.digest());
result = hash.toString(16);
while (result.length() < 32) {
result = "0"+result;
}

Keybase proof

I hereby claim:

  • I am kgundula on github.
  • I am kgundula (https://keybase.io/kgundula) on keybase.
  • I have a public key ASBgYWM9mCXoGzTbb5iaJftP6jR7x6kqqLH6cpINKdDsXQo

To claim this, I am signing this object:

@kgundula
kgundula / MainActivity.java
Created March 8, 2017 09:47
Fab color capture
package za.co.gundula.app.androidcolorpicker;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
@kgundula
kgundula / CaptureActivity.java
Created March 8, 2017 09:51
Setting background color on the captureactivity
package za.co.gundula.app.androidcolorpicker;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
[
{
"id": "4",
"photo": "https://dl.dropboxusercontent.com/u/231329/xyzreader_data/images/p004.jpg",
"thumb": "https://dl.dropboxusercontent.com/u/231329/xyzreader_data/thumbs/p004.jpg",
"aspect_ratio": 1.49925,
"author": "Carl Sagan",
"title": "Mysteries of the Universe Solved",
"published_date": "2013-06-20T00:00:00.000Z",
@kgundula
kgundula / genesis_public_key
Created February 25, 2018 12:57
genesis_public_key
04beb3977942ed59480f3b6a8f59acc511050735d59e2d8b79b87f6da737d1373ac329a6be8b4bc18095f6824b27cedfb56c4b776858542fe7dbebc694ee8278c7;c-darwin