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
@tanftw
tanftw / change.js
Created August 17, 2016 00:03
Location change message
$scope.$on('$locationChangeStart', function( event ) {
var answer = confirm("Are you sure you want to leave this page?")
if (!answer) {
event.preventDefault();
}
});
@tanftw
tanftw / weather.php
Last active November 10, 2016 18:42
Weather Intended Actions
<?php
// Matches with 'weather + anything'
$bot->answer('weather%', function ($bot, $user_id, $input)
{
$city = ltrim($input, 'weather');
// Pseudo code to get weather from database
$weather = DB::getWeather($city);
@tanftw
tanftw / form-group.sublime-snippet
Last active June 23, 2016 07:08
Sublime Snippet - Form Control
<snippet>
<content><![CDATA[
<div class="form-group">
<label for="${1:id}">${1/^(\w)|(?:_(\w))/(?1\u$1:)(?2 \u$2:)/g}</label>
<input type="${2:text}" id="${1:id}" name="${1:id}" class="form-control">
</div>
]]></content>
<tabTrigger>fg</tabTrigger>
</snippet>
@tanftw
tanftw / sample.php
Created May 17, 2016 16:23
Facebook Messenger Bots sample
<?php
// Welcome Message Template. Includes two buttons
$welcome_message = array(
'button' => array(
'text' => "Hi mate, thanks god, you are here. Let's start talking man. Do you like cars?",
'buttons' => array(
// Button can be postback or web url
@tanftw
tanftw / meta-box-geolocation-example.php
Last active November 30, 2021 05:10
Meta Box Geolocation Example
<?php
/**
* This is Meta Box Geolocation usage example.
* Include this file to your plugin or theme or see the usage guide below to apply to your Meta Box.
*/
add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'geolocation',
'title' => 'GeoLocation',
@tanftw
tanftw / iframe.md
Created December 28, 2015 07:06
Embed Iframe Dashboard
@tanftw
tanftw / Student.php
Created October 23, 2015 18:14
Student extends User use StudentScope
<?php
namespace App;
class Student extends User
{
public static function boot()
{
static::addGlobalScope(new StudentScope);
}
@tanftw
tanftw / StudentScope.php
Created October 23, 2015 18:13
Student scope
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ScopeInterface;
class StudentScope implements ScopeInterface
{
@tanftw
tanftw / CanUseCreator.php
Created October 23, 2015 18:12
CanUseCreator trait for Laravel 5
<?php
namespace App;
trait CanUseCreator
{
public function scopeOfCreator($query, $value)
{
return $query->whereCreatorId($value);
}
@tanftw
tanftw / CanUseMeta.php
Created October 13, 2015 03:20
CanUseMeta traits for Laravel
<?php
namespace App;
trait CanUseMeta
{
public function getMetaTable()
{
return $this->table . '_meta';
}