Skip to content

Instantly share code, notes, and snippets.

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

Huy Pham huypn

🏠
Working from home
View GitHub Profile
@huypn
huypn / gist:3f1739747f2b848ff485a13cefa861df
Created August 17, 2017 08:14 — forked from jrmadsen67/gist:bd0f9ad0ef1ed6bb594e
Laravel Quick Tip: Handling CsrfToken Expiration gracefully
Quick tip for handling CSRF Token Expiration - common issue is when you use csrf protection is that if
a form sits there for a while (like a login form, but any the same) the csrf token in the form will
expire & throw a strange error.
Handling it is simple, and is a good lesson for dealing with other types of errors in a custom manner.
In Middleware you will see a file VerifyCsrfToken.php and be tempted to handle things there. DON'T!
Instead, look at your app/Exceptions/Handler.php, at the render($request, Exception $e) function.
All of your exceptions go through here, unless you have excluded them in the $dontReport array at the
@huypn
huypn / youtubeID.js
Created August 15, 2017 17:36 — forked from takien/youtubeID.js
Get YouTube ID from various YouTube URL using JavaScript
/**
* Get YouTube ID from various YouTube URL
* @author: takien
* @url: http://takien.com
* For PHP YouTube parser, go here http://takien.com/864
*/
function YouTubeGetID(url){
var ID = '';
url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
@huypn
huypn / PushNotifications.php
Created February 23, 2017 18:50 — forked from joashp/PushNotifications.php
Simple PHP script to send Android Push Notification, iOS Push Notification and Windows Phone 8 Push Notification
<?php
// Server file
class PushNotifications {
// (Android)API access key from Google API's Console.
private static $API_ACCESS_KEY = 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI';
// (iOS) Private key's passphrase.
private static $passphrase = 'joashp';
// (Windows Phone 8) The name of our push channel.
private static $channelName = "joashp";
@huypn
huypn / com.edb.launchd.postgresql-9.1.plist
Created April 14, 2016 14:17 — forked from abhishekdev/com.edb.launchd.postgresql-9.1.plist
Disable/Enable PostgreSQL Autostart on Mac OS X Lion
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.edb.launchd.postgresql-9.1</string>
<key>ProgramArguments</key>
<?php
wp_embed_register_handler( 'jsfiddle', '#https?://jsfiddle.net/.*#i', 'huypham_embed_handler_jsfiddle' );
function huypham_embed_handler_jsfiddle( $url ){
global $content_width;
$url = $url[0];
$height = '300';
$width = $content_width?$content_width:'100%';
$query = parse_url($url,PHP_URL_QUERY);
$url = trailingslashit(preg_replace('#\?.+#i', '', $url));
parse_str($query,$query);
<?php
/**
* Embed Gists with a URL
*
* Usage:
* Paste a gist link into a blog post or page and it will be embedded eg:
* https://gist.github.com/6bd924af89539957f63e4e17b10d0c6d
*
* If a gist has multiple files you can select one using a url in the following format:
* https://gist.github.com/6bd924af89539957f63e4e17b10d0c6d?file=embed-gist.php