Skip to content

Instantly share code, notes, and snippets.

// send POST request to /wp-json/jwt-auth/v1/token voi data
{
"username" : "admin",
"password": "123456"
}
// ket qua nhan ve se gom truong token
type TemplateType = {
template: string;
id: string;
};
function withTemplate(templateObj: TemplateType) {
return function (constructor: any) {
let el = document.getElementById(templateObj.id);
let p = new constructor();
if (el) {
@coder054
coder054 / vimrc
Created May 23, 2022 04:08 — forked from Apsu/vimrc
Colemak DHm vim remap
noremap f e
noremap p r
noremap b t
noremap j y
noremap l u
noremap u i
noremap y o
noremap ' p
noremap r s
noremap s d
//// Demo of render props pattern in React
//// Provider pattern in Emberjs (https://guides.emberjs.com/release/tutorial/part-2/provider-components/)
import React from 'react';
import './style.css';
const RentalsFilter = ({ rentals, query, render }) => {
const filteredRentals = React.useMemo(() => {
if (query) {
rentals = rentals.filter((rental) => rental.title.includes(query));
@coder054
coder054 / axios-401-response-interceptor.js
Created August 18, 2022 02:49 — forked from yajra/axios-401-response-interceptor.js
Axios 401 response interceptor.
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@coder054
coder054 / words.erl
Created September 19, 2022 10:06 — forked from iain17/words.erl
Write a function that uses recursion to return the number of words in a string.
-module(words).
-export([strlen/1]).
%Assignment: Write a function that uses recursion to return the number of words in a string.
% If we send an empty list, return 0.
strlen([]) -> 0;
%Entry point for this module
strlen(Sentence) -> count(Sentence, 1).
%Base case. When its finally empty return the sum count.
count([], Count) -> Count;
import { apiClient, REACT_QUERY_KEYS } from '@/config'
import { getErrorMessage } from '@/utils/utils'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useRouter } from 'next/router'
import { toast } from 'react-toastify'
export const useDeleteDevice = ({
isOnDeviceListPage,
callbackOnSuccess,
}: {
@coder054
coder054 / ConsCarCdr.js
Created February 6, 2023 07:58 — forked from scotthaleen/ConsCarCdr.js
JavaScript implementation of cons, car and cdr
function cons(x, y) {
return function(w) { return w(x, y) };
};
function car(z) {
return z(function(x, y) { return x });
};
function cdr(z) {
return z(function(x, y) { return y });
/**
* DERIVING THE Y COMBINATOR IN 7 EASY STEPS
*
* Ionut G. Stan | ionut.g.stan@gmail.com | http://igstan.ro | http://twitter.com/igstan
*
*
* The Y combinator is a method of implementing recursion in a programming
* language that does not support it natively (actually, it's used more for
* exercising programming brains). The requirement is the language to support
* anonymous functions.
@coder054
coder054 / The Y combinator
Created April 5, 2023 03:23
The Y combinator
const Y = (fn) => ((g) => g(g))((g) => fn((x) => g(g)(x)))
const factorialGenerator = (f) => (n) => n === 0 ? 1 : n * f(n - 1)
const factorial = Y(factorialGenerator)
factorial(5) // 120
const sumFromZeroToNGenerator = (f) => (n) => n <= 1 ? n : n + f(n - 1)
const sumFromZeroToN = Y(sumFromZeroToNGenerator)
sumFromZeroToN(5) // 15