Skip to content

Instantly share code, notes, and snippets.

@kennarddh
kennarddh / MockMongoose.test.ts
Created August 10, 2024 16:40
Mocking utilities for jest and mongoose
// Models
import User from 'Models/User'
import MockMongoose, { ResetAll } from '../MockMongoose'
describe('Mock Mongoose', () => {
afterEach(() => {
ResetAll()
})
[{"_id":"6321afc42fb0f02dd5b1c1fc","ip":"41.60.232.61","anonymityLevel":"elite","asn":"AS30844","city":"Nairobi","country":"KE","created_at":"2022-09-14T10:41:08.200Z","google":false,"isp":"Maintainer Liquid Telecommunications Operations Limited","lastChecked":1700201153,"latency":209.388,"org":"Liquid Telecommunications Operations Limited","port":"5678","protocols":["socks4"],"region":null,"responseTime":4699,"speed":3,"updated_at":"2023-11-17T06:05:53.901Z","workingPercent":null,"upTime":84.3456480901691,"upTimeSuccessCount":4041,"upTimeTryCount":4791},{"_id":"6303d68fe607212ee5115141","ip":"193.169.4.184","anonymityLevel":"elite","asn":"AS49261","city":"Reutov","country":"RU","created_at":"2022-08-22T19:18:39.625Z","google":false,"isp":"Lekstar Communication Ltd","lastChecked":1700201153,"latency":92.413,"org":"SVS-Telecom Ltd","port":"10801","protocols":["socks5"],"region":null,"responseTime":4804,"speed":99,"updated_at":"2023-11-17T06:05:53.303Z","workingPercent":null,"upTime":98.5137115344358,"upTimeSuc
const dgram = require('node:dgram')
class CustomBuffer {
#offset = 0
#buffer
/**
* @returns {number}
*/
get() {
const fs = require('fs')
const path = require('path')
const data = JSON.parse(fs.readFileSync('./data.json'))
const outputDir = path.resolve('./output/')
const main = async () => {
for (const [fileName, url] of data) {
console.log({ fileName })
const merge2DArray = arr => {
return arr.reduce((acc, secondData) => {
if (acc.length < secondData.length) {
const loopTimes = secondData.length - acc.length
for (let i = 1; i <= loopTimes; i++) {
acc.push('')
}
}
secondData.map((value, index) => {
{
"AF": "Afghanistan",
"AX": "Åland Islands",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American Samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
"AQ": "Antarctica",
#!/bin/bash
# Create new create react app pwa with eslint, prettier, jsconfig, and editorconfig
# Second argument is set to true if you want to open vscode
# Third argument is set to true if you to test with jest
echo "Create new create react app pwa with eslint, prettier, jsconfig, and editorconfig"
echo "Second argument is set to true if you want to open vscode"
echo "Third argument is set to true if you to test with jest"
@kennarddh
kennarddh / setup-react-app.sh
Last active June 3, 2022 10:46
Setup react app with eslint, prettier, jsconfig, and editorconfig
#!/bin/bash
# Create new create react app with eslint, prettier, jsconfig, and editorconfig
# Second argument is set to true if you want to open vscode
# Third argument is set to true if you to test with jest
echo "Create new create react app with eslint, prettier, jsconfig, and editorconfig"
echo "Second argument is set to true if you want to open vscode"
echo "Third argument is set to true if you to test with jest"