Skip to content

Instantly share code, notes, and snippets.

View KeithNdhlovu's full-sized avatar

Keith Ndhlovu KeithNdhlovu

View GitHub Profile
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
@KeithNdhlovu
KeithNdhlovu / BrowserDetect.js
Created February 6, 2017 06:44
Checks the browser type, and version
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "Other";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown";
},
searchString: function (data) {
for (var i = 0; i < data.length; i++) {
var dataString = data[i].string;
this.versionSearchString = data[i].subString;
@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'),
@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 / 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 / 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 / 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 / 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 / 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 / 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);