Skip to content

Instantly share code, notes, and snippets.

View Somtuzy's full-sized avatar

Somtochukwu Onyeka Uzuakpunwa Somtuzy

View GitHub Profile
@Somtuzy
Somtuzy / app.js
Last active January 12, 2024 14:26
const express = require('express')
const app = express()
const uploadRouter = require('./upload.route')
app.use(uploadRouter)
app.listen(3000, () => {
console.log('Server is running on port 3000')
})
@Somtuzy
Somtuzy / fileUpload.js
Created January 1, 2024 10:59
This is a simple React template for uploading files showing the component and page.
// components/FileUpload.js
import React, { useState } from 'react';
import axios from 'axios';
const FileUpload = () => {
const [selectedFile, setSelectedFile] = useState(null);
const handleFileChange = (event) => {
setSelectedFile(event.target.files[0]);
};
// This stores the token in your local storage
const setAuthToken = (token) => {
localStorage.setItem('token', token)
}
// This extracts the token from your local storage
const getAuthToken = () => {
return localStorage.getItem('token')
}
// Question 1: Create a function that will convert Fahrenheit to Celsius
function fahrenheitToCelsius( valueInFarenheit ) {
let valueInCelsius = (5 / 9) * (valueInFarenheit - 32);
return valueInCelsius;
}
// Question 1: Test cases
console.log(fahrenheitToCelsius(32) + "C"); // Output: 0C
@Somtuzy
Somtuzy / visacard.js
Last active January 14, 2023 09:04
This code is a RegEx for validating a Visa Credit Card. You can test the code by replying the prompt with a random 16 digits Credit Card number that starts with 4 and has no spaces between the digits.
"use strict"
const prompt = require("prompt-sync")({sigint: true})
// This RegEx tests for a Visa card that starts with 4 and has a total card number of 16 digits ONLY. Please run the code & reply the prompt with a random 16 digit card number that starts with 4 and has no spaces between the digits.
const auth = /^4\d{12,15}$/
// Function to validate the Visa credit card number.
const validate = (cardNumber) => {
cardNumber = parseFloat(prompt('Please input your 13 - 16 digits Visa Card number: '))
@Somtuzy
Somtuzy / Learnable
Created October 31, 2022 13:23
Learnable Technical Test Attempt
function nth_most_rate_signature(list, n) {
list.sort();
let min_count = n+1, res = -1;
let curr_count = 1;
for (let i = 1; i < n; i++) {
// eslint-disable-next-line eqeqeq
if (list[i] == list[i - 1])
curr_count++;