Skip to content

Instantly share code, notes, and snippets.

View jgmuchiri's full-sized avatar
🏠
Working from home

John Muchiri jgmuchiri

🏠
Working from home
View GitHub Profile
@jgmuchiri
jgmuchiri / ModuleFilamentServiceProvider.php
Last active March 15, 2023 02:59
Plugin to load filament resources, pages and widgets for nwidart/laravel-modules
<?php
/**
* ModuleFilamentServiceProvider.php
*
* Plugin to load filament resources, pages and widgets for
* nwidart/laravel-modules
*
* @author jgmuchiri
* @license MIT
* @copyright Copyright (c) 2023, John Muchiri
@jgmuchiri
jgmuchiri / gitfixname.sh
Last active July 30, 2020 11:52
Add this to your .bashrc or .bash_profile to change email in a repo. This is useful to remove personal email in public repo
gitfixname(){
git filter-branch --env-filter '
WRONG_EMAIL="old or personal email to remove"
NEW_NAME="github username"
NEW_EMAIL="new email such as private github email"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
@jgmuchiri
jgmuchiri / gitremove.sh
Created July 30, 2020 11:48
Add this to your .bashrc to permanently remove a file from git repo and history
gitremove(){
echo "Enter file to remove"
read FILE
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch $FILE' --prune-
empty --tag-name-filter cat -- --all
git push origin master -f
}
@jgmuchiri
jgmuchiri / creditcard-type-check.php
Last active November 21, 2019 16:23
Check the type of credit number used
<?php
function cardType($number)
{
$number = preg_replace('/[^\d]/', '', $number);
if(preg_match('/^3[47][0-9]{13}$/', $number)){
return 'AX'; // 'American Express'
}
elseif(preg_match('/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/', $number)){
@jgmuchiri
jgmuchiri / amex_regex.php
Created June 4, 2019 19:56
American express regex
$pattern ="/^([34|37]{2})([0-9]{13})$/";
//you can now do great things
{
"stories": [{
"id":1,
"name": "John Muchiri",
"title": "Full-stack Developer",
"image": "https://randomuser.me/api/portraits/men/34.jpg",
"points": 10,
"company":"Builders Inc",
"story": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pellentesque fringilla nibh, in congue eros sollicitudin nec. Donec suscipit tellus eu enim ultrices, vel convallis dolor semper. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris urna libero, ornare sit amet erat non, dictum molestie arcu."
@jgmuchiri
jgmuchiri / Hander.php
Last active April 17, 2019 01:49
Send application error log to email in Laravel //app/Exceptions/Handler.php
<?php
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
@jgmuchiri
jgmuchiri / Hander.php
Created April 17, 2019 01:49
Send application error log to email in Laravel //app/Exceptions/Handler.php
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
<?php
# composer require stripe/stripe-php
require_once 'vendor/autoload.php';
$stripe_secret = "" //enter your Stripe key here
$plan = "" //enter the subscription plan name
\Stripe\Stripe::setApiKey($stripe_secret);
@jgmuchiri
jgmuchiri / mysql-dump.sh
Last active March 26, 2019 16:01
Bash script for dump all your MySQL databases
#!/bin/bash
# Specify number of backups to keep in days
NUMBER_OF_BACKUPS=3
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
IGNORE_LIST="SELECT schema_name FROM information_schema.SCHEMATA WHERE schema_name NOT LIKE '% %' AND schema_name NOT LIKE '%-%' AND schema_name != 'information_schema' AND schema_name != 'mysql' AND schema_name != 'performance_schema';"
echo "Reading databases..."