Skip to content

Instantly share code, notes, and snippets.

@ndinhbang
ndinhbang / mobile.apache.conf
Created February 9, 2023 03:52 — forked from justinkelly/mobile.apache.conf
Apache mobile detect config
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|meego.+mobile|midp|mmp|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno
@ndinhbang
ndinhbang / .htacccess
Created February 9, 2023 03:29 — forked from kikmedia/.htacccess
Mobile / desktop redirect via .htaccess, setting cookies
RewriteEngine on
RewriteBase /
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:www.example.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
@ndinhbang
ndinhbang / README.md
Created February 1, 2023 09:03 — forked from shanginn/ README.md
Get available relationships trait for Eloquent model (Laravel 5.*)

GetRelationships Trait

This trait will allow you to get defined relationships on the model. I wish Laravel have a way to get this without any additions(except for trait), but there is no way.

Here we have 2 versions of the trait: for PHP7 and for PHP5.

Both method uses Reflections to collect information about the model.

PHP7

With PHP7 version you'll only need to add return class for the relationship method like this:

@ndinhbang
ndinhbang / Brand.php
Created April 18, 2022 02:21 — forked from monoman81/Brand.php
Using Filament with Spatie Media Library
//Model Brand.php.
<?php
namespace App\Models\Admin;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\HasMedia;
@ndinhbang
ndinhbang / server_time_sync.js
Created November 20, 2021 15:46 — forked from ethaizone/server_time_sync.js
Sync server time to client browser with JS. Implement follow Network Time Protocol.
// Thanks http://stackoverflow.com/questions/1638337/the-best-way-to-synchronize-client-side-javascript-clock-with-server-date
var serverTimeOffset = false;
function getServerTime(callback) {
if (serverTimeOffset === false) {
var scripts = document.getElementsByTagName("script"),
URL = scripts[scripts.length - 1].src;
var clientTimestamp = Date.parse(new Date().toUTCString());
@ndinhbang
ndinhbang / Qr.vue
Created September 30, 2021 15:39 — forked from ggarcia92/Qr.vue
QrCode Display and Export to PDF in Vue/Quasar
<template>
<q-page class="flex flex-center">
<qrcode :value="json" ref="qr" :options="{ width: 200 }"></qrcode>
<q-btn label="Export" @click="exportPDF"/>
</q-page>
</template>
<script>
import Jspdf from 'jspdf'
@ndinhbang
ndinhbang / Controller.php
Created May 31, 2021 18:47 — forked from sebastiaanluca/Controller.php
A HasMany relation sync method implementation using macros
<?php
$business->locations()->sync([1, 42, 16, 8]);
@ndinhbang
ndinhbang / client.js
Created October 21, 2020 15:05 — forked from hagino3000/client.js
WebSocket with binary data
var socket = null;
function bootstrap() {
// 適当な図形を描画
var c = document.getElementById('mycanvas');
var ctx = c.getContext('2d');
ctx.globalalpha = 0.3;
for(var i=0; i<1000; i++) {
ctx.beginPath();
@ndinhbang
ndinhbang / api.js
Created October 24, 2019 05:06
JWT authentication handler using Axios interceptors. It refreshes access token on the fly when backend API throws out a 401 error. Multiple requests at the same time supported.
import axios from 'axios';
import JWTDecode from 'jwt-decode';
import { AuthApi } from './auth.api';
import { config } from '../config';
const { API_ENDPOINT } = config[process.env.NODE_ENV];
axios.defaults.baseURL = API_ENDPOINT;
axios.defaults.timeout = 7000;