Skip to content

Instantly share code, notes, and snippets.

View KeithNdhlovu's full-sized avatar

Keith Ndhlovu KeithNdhlovu

View GitHub Profile
@KeithNdhlovu
KeithNdhlovu / WhatsDom.js
Created June 9, 2016 12:07
Since Whatsap Doesnt have an Option to Export contacts in a group, and they only display username, and status, exporting contacts out of one group is straneous, so i made this
var groupList = document.getElementsByClassName("infinite-list-viewport")[0];
var contactList = groupList.getElementsByClassName("infinite-list-item");
var users = [];
for(var cc = 0; cc < contactList.length; cc++){
var name = contactList[cc].getElementsByClassName("chat-title")[0].getElementsByTagName("span")[0].getAttribute("title");
var contactDOM = contactList[cc].getElementsByClassName("chat-title")[0].getAttribute("data-reactid");
var reallNumber = contactDOM.replace(".0.0:$main.3.2.$=10.1:1.2.1:1.0.0.$", "");
reallNumber = reallNumber.substr(0, reallNumber.indexOf("@c=1us"));
@KeithNdhlovu
KeithNdhlovu / GoogleMapsDirections.java
Created July 7, 2016 12:37
how to launch google maps directions API
Uri gmmIntentUri = Uri.parse(String.format(Locale.US, "google.navigation:q=%f,%f", panicLocation.latitude, panicLocation.longitude));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
@KeithNdhlovu
KeithNdhlovu / AndroidImageChooser.java
Created July 7, 2016 12:54
Lanches an Intent to either get image by using camera , or pick image by using Galery or any other applicable software
private Uri outputFileUri;
private void openImageIntent() {
// Determine Uri of camera image to save.
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
root.mkdirs();
final String fname = Utils.getUniqueImageFilename();
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
@KeithNdhlovu
KeithNdhlovu / css-vertical-align.css
Created July 11, 2016 13:37
Css3 Vertical Align Center
.valign-wrapper {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
@KeithNdhlovu
KeithNdhlovu / SimpleDateFormat.java
Created July 12, 2016 13:32
Android Date Formating
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
String expiryDateString = simpleDateFormat.format(Date);
@KeithNdhlovu
KeithNdhlovu / AndroidDateFromString.java
Last active July 14, 2016 11:41
Create a date from string and the reverse
String dtStart = "2010-10-15T09:27:37Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
Date date = format.parse(dtStart);
System.out.println(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@KeithNdhlovu
KeithNdhlovu / enableQueryLog.php
Last active August 11, 2016 11:13
Laravel 5 show query log
<?php
DB::enableQueryLog();
DB::listen(
function ($sql, $bindings, $time) {
// $sql - select * from `ncv_users` where `ncv_users`.`id` = ? limit 1
// $bindings - [5]
// $time(in milliseconds) - 0.38
dd($sql);
@KeithNdhlovu
KeithNdhlovu / adb
Created August 21, 2016 08:06
adb forward ports
adb: implement "adb reverse <local> <remote>"
This implements the logical opposite of 'adb forward', i.e.
the ability to reverse network connections from the device
to the host.
This feature is very useful for testing various programs
running on an Android device without root or poking at the
host's routing table.
Options and parameters are exactly the same as those for
@KeithNdhlovu
KeithNdhlovu / ComapareImage.php
Created September 28, 2016 09:53
PHP Compare image data by thenakos
<?php
class compareImages
{
private function mimeType($i)
{
/*returns array with mime type and if its jpg or png. Returns false if it isn't jpg or png*/
$mime = getimagesize($i);
$return = array($mime[0],$mime[1]);
switch ($mime['mime'])
@KeithNdhlovu
KeithNdhlovu / carbon.php
Last active January 20, 2017 07:00
Laravel Carbon Date DB vs UI
<?php
// For DB
$startDate = Carbon::createFromFormat('d F, Y', $data['start_date'], 'Africa/Johannesburg');
$startDate->setTime($data['start_hour'], $data['start_minute'], 00);
$startDate->setTimeZone('UTC');
//For UI
$startDate = new Carbon($event->start_date);
$startDate->timeZone('Africa/Johannesburg')->format('d-m-Y - H:i:s'),