Skip to content

Instantly share code, notes, and snippets.

View keidarcy's full-sized avatar
🏖️
On vacation

Xing Yahao keidarcy

🏖️
On vacation
View GitHub Profile
@keidarcy
keidarcy / useAddEventListener.tsx
Created September 2, 2020 02:58
custom addEventListener hook with typescript
import React, { useEffect, useRef, useState } from 'react';
import logo from './logo.svg';
import './App.css';
interface Options {
enable?: boolean;
target?: GlobalEventHandlers;
}
const useEventListener = (
targetEvent: keyof GlobalEventHandlersEventMap,
@keidarcy
keidarcy / shopify-graphql.md
Last active August 29, 2020 01:49
Shopify GraphQL Examples

Products with Search Query

query{
    products(first: 100,  query: "tag:vans AND title:AUTHENTIC") {
        edges {
            node {
                id
                title
 tags
@keidarcy
keidarcy / LNMP.md
Last active September 22, 2020 05:25
latest PHP + Ngnix + Redis + Mysql + Node + Composer + Git in Amazon Linux 2(2020.08)

OS

$ cat /etc/system-release
Amazon Linux release 2 (Karoo)

set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory

@keidarcy
keidarcy / PromiseAllSettled.js
Last active August 16, 2022 01:10
How to use Promise.allSettled and fetch api with GET and POST together
const p1 = new Promise((resolve, reject) => setTimeout(resolve(1), 200))
const p2 = new Promise((resolve, reject) => setTimeout(reject('error'), 300))
const p3 = new Promise((resolve, reject) => setTimeout(resolve(3), 4000))
Promise.all([p1, p2, p3]).then((res) => console.log(res)).catch(e => console.log(e))
Promise.allSettled([p1, p2, p3]).then((res) => console.log(res)).catch(e => console.log(e))
@keidarcy
keidarcy / dropzone.js
Created July 22, 2020 03:57
polaris drop zone one single picture
import React, { useCallback } from 'react'
import { DropZone, MediaCard } from '@shopify/polaris'
const ImageUploadDropZone = ({ files, setFiles }) => {
const handleDropZoneDrop = useCallback(
(_dropFiles) => setFiles([..._dropFiles]),
[]
)
const validImageTypes = ['image/gif', 'image/jpeg', 'image/png']
@keidarcy
keidarcy / css-selectors.md
Created July 8, 2020 02:18 — forked from magicznyleszek/css-selectors.md
CSS Selectors Cheatsheet

CSS Selectors Cheatsheet

Element selectors

Element -- selects all h2 elements on the page

h2 {
    foo: bar;
@keidarcy
keidarcy / Cors.php
Created June 29, 2020 02:33 — forked from drewjoh/Cors.php
Laravel CORS Middleware
<?php // /app/Http/Middleware/Cors.php
namespace App\Http\Middleware;
use Closure;
class Cors {
public function handle($request, Closure $next)
{
return $next($request)
@keidarcy
keidarcy / validation-japanese-postcode.js
Last active June 23, 2020 12:41
check number and post code real time
const zipInput = document.getElementById("checkout_shipping_address_zip")
const numberInput = document.getElementById("checkout_shipping_address_phone")
const submitButton = document.getElementById('continue_button')
const submitText = submitButton.children[0]
let zipError = document.createElement('p')
zipError.setAttribute('id', 'error-for-zip')
zipError.setAttribute('class', 'field__message field__message--error')
zipError.innerHTML = "日本の有効な郵便番号を入力してください"
@keidarcy
keidarcy / app.js
Last active June 21, 2020 06:59
dom manipulate
document.addEventListener('DOMContentLoaded', function(){
const list = document.querySelector('#book-list ul');
const forms = document.forms;
// delete books
list.addEventListener('click', (e) => {
if(e.target.className == 'delete'){
const li = e.target.parentElement;
li.parentNode.removeChild(li);
@keidarcy
keidarcy / watch_video.js
Created June 21, 2020 03:31 — forked from kushalvyas/watch_video.js
JS for Camera capture from browser
/**
* Created by kushal
*
* Usage :
* To access local system webcam on the internet/
* Couple of points to be remembered:
*
* - Accessing the webcam using HTML5 and JS requires permission from
* the browser. The url of the file has to be a valid one. Url such as file:/// in your browser will not permit the browser to access local webcam.
* - Whereas, an http or https url will surely make a paved way for it. Hence, while developing, one can use Xampp, Wamp or the LAMP Stack.