Skip to content

Instantly share code, notes, and snippets.

View tanftw's full-sized avatar
😅
Fixing bugs

Tan Nguyen tanftw

😅
Fixing bugs
View GitHub Profile
$pattern1 = '/<img [^>]*class="[^"]*\balignnone\b[^"]*"[^>]*>/i';
$replacement = '<figure class="penci-wrapper-image">$0</figure>';
$content = '<div><img src="image.jpg" class="alignnone"></div>';
// run preg_replace() on the $content
$content = preg_replace($pattern1, $replacement, $content);
var_dump($content);
@tanftw
tanftw / aliases.sh
Created July 22, 2018 09:49
Useful Bash Aliases
# Homestead Vagrant up
alias vu='cd ~/Homestead && vagrant up'
# Homestead Vagrant SSH
alias vs='cd ~/Homestead && vagrant ssh'
# Ngrok share with site parameter
# usage: share wp.test
share() {
./ngrok http -subdomain devgiga -host-header=rewrite $1:80
@tanftw
tanftw / delete.php
Created September 21, 2017 16:41
Delete User Blade
{!! Form::open(['method' => 'delete', 'url' => '/dashboard/users/' . $user->id]) !!}
<a href="{{ url('/dashboard/users/' . $user->id) }}" class="btn btn-sm btn-default"><i
class="glyphicon glyphicon-edit"></i> Edit</a>
<button type="submit" class="btn btn-danger btn-sm"><i
class="glyphicon glyphicon-trash"></i> Delete
</button>
{!! Form::close() !!}
@tanftw
tanftw / redirect.html
Created May 14, 2017 16:00
Redirect Google Form
<iframe id="myframe" name="myframe" style="display: none" onload="if(typeof redirect!='undefined'){window.location.href='/REDIRECT_URI';}"></iframe>
<form onsubmit="redirect=true" action="{{ URL }}" method="POST" target="myframe"></form>
@tanftw
tanftw / list.php
Created March 13, 2017 08:36
Messenger Bot List Template
$bot->answer('list', [
'elements' => [
[
'title' => 'Classic T-Shirt Collection',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
'subtitle' => 'See all our colors',
'default_action' => [
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/shop_collection',
],
@tanftw
tanftw / send-message.php
Last active April 18, 2018 04:00
Send messages to all leads with Giga AI
<?php
$leads = GigaAI\Storage\Eloquent\Lead::all();
$leads->each(function ($lead) use ($bot) {
$bot->says("Hi [first_name]", [], $lead);
});
@tanftw
tanftw / storage.php
Last active April 18, 2018 04:02
Messenger Bot Storage Example
<?php
$bot->answers('buy sneaker', 'Which sneaker do you want to buy?')->then(function ($lead, $input) {
$lead->data('sneaker', $input);
return 'Thanks for purchasing';
});
@tanftw
tanftw / Image.php
Created December 6, 2016 06:09
Image Resizer
<?php
class Image
{
public static function resize($path, $new_width, $new_height)
{
list($width, $height) = getimagesize($path);
if ($new_width > max( $width, $height ) && $new_height > max($width, $height))
return;
@tanftw
tanftw / random-material-color.php
Created September 11, 2016 15:12
Random Material Color
<?php
function random_material_color()
{
$colors = [
'#F44336', '#F44336', '#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C', // red
'#E91E63','#FCE4EC','#F8BBD0','#F48FB1','#F06292','#EC407A','#E91E63','#D81B60','#C2185B','#AD1457','#880E4F','#FF80AB','#FF4081','#F50057','#C51162', // pink
'#9C27B0','#F3E5F5','#E1BEE7','#CE93D8','#BA68C8','#AB47BC','#9C27B0','#8E24AA','#7B1FA2','#6A1B9A','#4A148C','#EA80FC','#E040FB','#D500F9','#AA00FF', // purple
'#673AB7','#EDE7F6','#D1C4E9','#B39DDB','#9575CD','#7E57C2','#673AB7','#5E35B1','#512DA8','#4527A0','#311B92','#B388FF','#7C4DFF','#651FFF','#6200EA', // deep purple
'#3F51B5','#E8EAF6','#C5CAE9','#9FA8DA','#7986CB','#5C6BC0','#3F51B5','#3949AB','#303F9F','#283593','#1A237E','#8C9EFF','#536DFE','#3D5AFE','#304FFE', // indigo
'#2196F3','#E3F2FD','#BBDEFB','#90CAF9','#64B5F6','#42A5F5','#2196F3','#1E88E5','#1976D2','#1565C0','#0D47A1','#82B1FF','#448AFF','#2979FF','#2962FF', // blue
@tanftw
tanftw / orderByRaw.php
Last active September 12, 2016 19:33
orderByRaw() Laravel
// Usage: When you need, for example order by sticky post and updated_at
Post::orderByRaw(\DB::raw("CASE `status` WHEN 'sticky' THEN 1 ELSE 2 END"))
->orderBy('updated_at', 'desc')
->paginate(15);