Skip to content

Instantly share code, notes, and snippets.

@kuroski
kuroski / checkSitemap.js
Last active May 31, 2022 14:51
Check if urls from sitemap.xml file are active
/* eslint-disable */
const fs = require('fs')
const urlExists = require('url-exists')
const parser = require('xml2js')
const { PromisePool } = require('@supercharge/promise-pool')
async function init() {
const sitemapXml = fs.readFileSync('./public/sitemap.xml', 'utf8')
parser.parseString(sitemapXml, async (err, result) => {
const urls = result.urlset.url.map(({ loc }) => loc).flat()
@kuroski
kuroski / camel-case-01.js
Last active June 29, 2021 14:00
Confident JS series
// utils.d.ts
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ?
`${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${CamelToSnakeCase<U>}` :
S
export type KeysToCamelCase<T> = {
@kuroski
kuroski / camelCase-snake_case-types.ts
Last active November 5, 2024 10:22
Typescript type camelCase / snake_case conversion
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>
type KeysToCamelCase<T> = {
[K in keyof T as CamelCase<string & K>]: T[K]
}
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ?
@kuroski
kuroski / machine.js
Created February 9, 2021 09:08
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kuroski
kuroski / machine.js
Last active October 6, 2020 14:14
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kuroski
kuroski / lambda-function-mov-to-gif.js
Last active September 29, 2020 06:11
This is just a basic function to handle mov to gif conversion in a lambda function
const fs = require("fs");
const path = require("path");
const ffmpegStatic = require("ffmpeg-static");
const ffmpeg = require("fluent-ffmpeg");
ffmpeg.setFfmpegPath(ffmpegStatic);
const allowCors = fn => async (req, res) => {
res.setHeader("Access-Control-Allow-Credentials", true);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
@kuroski
kuroski / machine.js
Created August 14, 2020 07:38
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
jest.mock('@/guards');
import router from "@/router";
import { guardToken, guardCustom } from "@/guards";
describe("router", () => {
it("calls 'guardToken' before each route transition", () => {
router.push({ name: 'dashboard' });
expect(guardToken).toHaveBeenCalled();
});
import { shallowMount, mount, createLocalVue } from '@vue/test-utils'
import ElementUI from 'element-ui'
import VUserSearchForm from '@/components/VUserSearchForm'
const localVue = createLocalVue()
localVue.use(ElementUI)
describe('VUserSearchForm', () => {
const build = () => {
const options = { localVue }