Skip to content

Instantly share code, notes, and snippets.

View mmuoDev's full-sized avatar

obioha uche mmuoDev

  • Berlin
View GitHub Profile
@mmuoDev
mmuoDev / gist:5249df327e03a36395a4a29be41f565d
Created April 24, 2017 22:08
Snippet of code that is supposed to return generic list of items for Facebook messenger bot
while($result = mysqli_fetch_assoc($res)){
$array[] = array(
"title"=> $result['title'],
"image_url"=> $result['img_url'],
"subtitle"=> "See all our colors",
"buttons"=>[
[
"type"=>"postback",
"title"=>$result['title'],
@mmuoDev
mmuoDev / gist:a63e3352e51b842c9077d92e0a9f8e56
Created September 23, 2017 11:08
Laravel 5 - Dynamically load select box using another select box
For those with Javascript phobia like me, this is how to dynamically load contents into a select box using another select box. This gist uses AJAX and JQuery.
The view
<div class="form-group col-sm-12">
<label class=""> Category</label>
<select name="category" class="form-control category" id="input-category">
<option value=""> --- Please Select ---</option>
@foreach(session('categories') as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
For those with Javascript phobia like me, this is how to dynamically load contents into a input textfield using a select box. This gist uses AJAX and JQuery.
The view
<div class="form-group col-sm-8">
<label class="">Select Bank Account</label>
<select class="form-control bank_account" name="bank_account">
<option value="">--Please select--</option>
@foreach($banks as $bank)
<option value="{{$bank->id}}">{{$bank->name}}[{{$bank->account_number}}]</option>
@mmuoDev
mmuoDev / signature.php
Created February 22, 2018 14:04
Adding signature to Laravel form.
For this to work, you have to include CDNs for JQuery and FabricJS.
***The View****
===The blade file===
The CSS
<style>
#sheet-container {
width: 250px;
height: 100px;
border: 1px solid black;
@mmuoDev
mmuoDev / date_time.php
Created May 31, 2020 18:22
Validate date and time
function validateDateTime($value){
$array = explode(" ", $value);
if(count($array) != 2){
return 'Kindly separate your date and time in this format for example, 11/12/2020 2.20pm';
}
//validate date
$date = $array[0];
if(preg_match("/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/", $date) === 0) {
return 'Your date '.$date.' is in an invalid format';
@mmuoDev
mmuoDev / whatsapp.php
Created June 9, 2020 19:17
whatsapp chatbot navigation in sub-menus
if((int)$query == 0){
$states = #fetch states from the session
if(count($states) > 1){
$count = count($states);
$prev = $count - 2;
$prev_state = $states[$prev];
if($prev_state != '0'){
//go to previous key - /menus/{$prev_state}
//show sub-menus
//contatenate '0. Previous Menu'
@mmuoDev
mmuoDev / latest_date.go
Last active June 28, 2021 12:32
Get latest date in a golang slice
import (
"fmt"
"time"
)
func main() {
dates := []string{"2021-01-20", "2021-03-05", "2021-02-25", "2021-03-04"}
latest, _ := time.Parse("2006-01-02", dates[0])
for _, date := range dates {
dateValue, _ := time.Parse("2006-01-02", date) // convert 'String' to 'Time' data type
@mmuoDev
mmuoDev / network.go
Created October 26, 2021 13:06
Return the network provider of a Nigerian phone number
func getNetwork(phone string) string {
networks := make(map[string][]string)
networks["mtn"] = []string{"0803", "0806", "0814", "0810", "0813", "0814", "0816", "0703", "0706", "0903", "0906"}
networks["9mobile"] = []string{"0809", "0817", "0818", "0908", "0909"}
networks["airtel"] = []string{"0802", "0808", "0812", "0708", "0701", "0902", "0901", "0907"}
networks["glo"] = []string{"0805", "0807", "0811", "0815", "0705", "0905"}
for k, prefixes := range networks {
for _, p := range prefixes {
if phone[:4] == p {