Skip to content

Instantly share code, notes, and snippets.

View ngugijames's full-sized avatar
🇰🇪
.

James Ngugi ngugijames

🇰🇪
.
View GitHub Profile
@mubbi
mubbi / nginx.conf
Created August 19, 2018 16:28 — forked from lkmadushan/nginx.conf
NGINX configuration for multi-tenant PHP application
map $http_accept $api_version {
default 0;
"application/vnd.example.v1+json" 1;
}
server {
listen 80;
listen [::]:80;
@neilrackett
neilrackett / php-to-moment.js
Last active December 13, 2022 07:39
Convert PHP date string to Moment.js format
function phpToMoment(str) {
let replacements = {
'd' : 'DD',
'D' : 'ddd',
'j' : 'D',
'l' : 'dddd',
'N' : 'E',
'S' : 'o',
'w' : 'e',
@tdchien
tdchien / EventServiceProvider.php
Created November 17, 2016 14:53
Laravel 5 - Log DB query
public function boot(DispatcherContract $events)
{
parent::boot($events);
$path = storage_path().'/logs/query.log';
\Event::listen('illuminate.query', function($sql, $bindings, $time) use($path) {
// Uncomment this if you want to include bindings to queries
//$sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
//$sql = vsprintf($sql, $bindings);
$time_now = date('Y-m-d H:i:s');
@ngugijames
ngugijames / Ussd-varying-questions.php
Last active August 30, 2016 10:20
Ussd with varying questions and responses
<?php
/**
* Collaborated with http://github.com/pittgikera
*/
$text = $_GET['text'];
//$questions = "How was is it? # Was it enjoyable?# Did you have fun? # Will you come back?";
$questions = "";
@muya
muya / random_saf_ke_msisdn_faker.php
Last active October 8, 2020 16:41
Code for creating random Safaricom Kenya Phone numbers (accompanying blog post: https://blog.muya.co.ke/random-safaricom-kenya-phone-numbers/)
<?php
// include Faker in your project (https://github.com/fzaninotto/Faker#installation)
use Faker\Factory as Faker;
$faker = Faker::create();
$regex = "/(\+?254|0){1}[7]{1}([0-2]{1}[0-9]{1}|[9]{1}[0-2]{1})[0-9]{6}/";
$samplePhoneNumber = $faker->regexify($regex);
@muya
muya / msisdn_regex.txt
Created February 28, 2016 16:06
Regex for Safaricom Kenya, Airtel Kenya & Tigo Tanzania Phone Numbers
# KE
SAFARICOM: "/(\+?254|0|^){1}[-. ]?[7]{1}([0-2]{1}[0-9]{1}|[9]{1}[0-2]{1})[0-9]{6}\z/"
AIRTEL: "/(\+254|0|^){1}[-. ]?[7]{1}([3]{1}[0-9]{1}|[8]{1}[5-9])[0-9]{6}\z/"
# TZ
TIGO: "/(\+?255|0|^){1}[-. ]?([7]{1}[1]{1}[2-9]{1}|[6]{1}[57]{1}[2-9]{1})[0-9]{6}\z/"
@fer-ri
fer-ri / laravel.js
Last active October 18, 2021 12:45 — forked from soufianeEL/laravel.js
You use Laravel 5 and you want to send a DELETE request without creating a form? This will handle the form-creation bits for you dynamically, similar to the Rails implementation. To use, import script, and create a link with the `data-method="DELETE"` and `data-token="{{csrf_token()}}"` attributes.
/*
Taken from: https://gist.github.com/soufianeEL/3f8483f0f3dc9e3ec5d9
Modified by Ferri Sutanto
- use promise for verifyConfirm
Examples :
<a href="posts/2" data-method="delete" data-token="{{csrf_token()}}">
- Or, request confirmation in the process -
<a href="posts/2" data-method="delete" data-token="{{csrf_token()}}" data-confirm="Are you sure?">
@wesrice
wesrice / AbstractEntity.php
Last active August 4, 2021 22:02
Self Validating Value Objects and Entities (Laravel Implementation)
<?php
abstract class AbstractEntity extends AbstractValueObject
{
/**
* Offset Set
*
* @param mixed $offset
* @param mixed $value
*
<?php
/**
* Description of VideoStream
*
* @author Rana
* @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial
*/
class VideoStream
{
private $path = "";