Skip to content

Instantly share code, notes, and snippets.

Avatar
😀

LE VAN THANH zerolethanh

😀
View GitHub Profile
@zerolethanh
zerolethanh / SearchComponent.js
Last active Feb 10, 2021
search with fuse.js
View SearchComponent.js
import {Avatar, Input, Popover} from 'antd';
import React, {useState} from 'react';
import Fuse from 'fuse.js';
import {useGlobal} from 'reactn';
const {Search} = Input;
export default function SearchComponent() {
const [gPosts] = useGlobal('gPosts');
@zerolethanh
zerolethanh / AvatarEditor.js
Last active Feb 9, 2021
Update avatar using react-avatar-edit
View AvatarEditor.js
import React, {useState} from 'react';
import dynamic from 'next/dynamic';
import {message, Modal} from 'antd';
import {auth, db, storage} from '../../../firebase/clientApp';
import isEmpty from 'lodash/isEmpty';
const Avatar = dynamic(() => import('react-avatar-edit'), {ssr: false});
function AvatarEditor({show, setShow, user}) {
const [data, setData] = useState(null);
@zerolethanh
zerolethanh / CFAuthProvider.js
Last active Jan 23, 2021
Giữ trạng thái đăng nhập của với firebase.
View CFAuthProvider.js
import React, {createContext, useEffect, useState} from 'react';
import {useGlobal} from 'reactn';
import {useAuthState} from 'react-firebase-hooks/auth';
import {useDocument} from 'react-firebase-hooks/firestore';
const CFAuthContext = createContext({});
const useUser = ({auth, firestore}) => {
const [gUser, setGUser] = useGlobal('user');
const [user, loading, error] = useAuthState(auth);
View button.css
<p><a style="display: block; text-align: center; margin: auto; width: 120px; padding: 5px 10px; background: #ff7733; border-bottom: 5px solid #dd5500; color: #fff; font-weight: bolder; font-size: 0.8rem; border-radius: 10px; text-decoration: none;" href="http://amzn.asia/31AdXyo" target="_blank" onclick="ga('send', 'event', 'OutboundLink', 'click', 'PR_201703_wacom3_b2');">購入はこちらから</a></p>
View reduce.js
// Production steps of ECMA-262, Edition 5, 15.4.4.21
// Reference: http://es5.github.io/#x15.4.4.21
// https://tc39.github.io/ecma262/#sec-array.prototype.reduce
if (!Array.prototype.reduce) {
Object.defineProperty(Array.prototype, 'reduce', {
value: function(callback /*, initialValue*/) {
if (this === null) {
throw new TypeError( 'Array.prototype.reduce ' +
'called on null or undefined' );
}
View forEach.js
// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.io/#x15.4.4.18
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback/*, thisArg*/) {
var T, k;
if (this == null) {
throw new TypeError('this is null or not defined');
View dbLog.php
<?php
if (!function_exists('dbStartLog')) {
function dbStartLog()
{
app('db')->enableQueryLog();
}
}
if (!function_exists('dbEndLog')) {
function dbEndLog(Closure $closure = null)
{
@zerolethanh
zerolethanh / saveBlob.php
Last active Mar 11, 2017
saveBlob to public dir
View saveBlob.php
<?php
if (!function_exists('saveBlob')) {
function saveBlob($blobdata = 'blobdata', $dir = 'blobdata')
{
//$blobdata head : data:image/jpeg;base64,
$blobdata = request($blobdata);
list($type, $blobdata) = explode(';', $blobdata);
list(, $blobdata) = explode(',', $blobdata);
$blobdata = base64_decode($blobdata);