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 / bbcode-html.php
Created February 2, 2019 05:00
Convert BBcode to HTML and Vice-Versa
<?php
//This function let convert BBcode to HTML
function bbcode_to_html($text)
{
$text = nl2br(htmlentities($text, ENT_QUOTES, 'UTF-8'));
$in = array(
'#\[b\](.*)\[/b\]#Usi',
'#\[i\](.*)\[/i\]#Usi',
'#\[u\](.*)\[/u\]#Usi',
'#\[s\](.*)\[/s\]#Usi',
@jgmuchiri
jgmuchiri / tag-extractor.php
Created February 2, 2019 05:57
Extracts attribute values inside an element from html content
<?php
/**
* You can modify preg_match_all to match your needs
*
* Extracts attribute values inside an element from html content
* You post html content and inside the content, you have shortcodes with attributes like [pageBreak id="home" title="Home page"]
* You want to extract id and title attribute values so you can save them in db as a matching pair.
*/
$content = 'hello there [pageBreak ="home" title="Home page"] new page [/pageBreak] another page';
extract($content);
@jgmuchiri
jgmuchiri / composer.json
Created February 2, 2019 16:55
PHP Stripe gateway
{
"require": {
"stripe/stripe-php": "^6.8",
"phpmailer/phpmailer": "^6.0",
"symfony/polyfill-mbstring": "^1.8"
}
}
<style>
.penguin {
/* change code below */
--penguin-skin: gray;
--penguin-belly: white;
--penguin-beak: orange;
/* change code above */
position: relative;
@jgmuchiri
jgmuchiri / 404.html
Created February 16, 2019 20:44
Responsive 404 page not found
<!doctype html>
<html lang="en">
<head>
<title>404 - Page Not Found!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
@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..."
<?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 / 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)
{
@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)
{
"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."