Skip to content

Instantly share code, notes, and snippets.

View Hoxtygen's full-sized avatar
🎯
Focusing

Wasiu Idowu Hoxtygen

🎯
Focusing
  • Nigeria
View GitHub Profile
@filiph
filiph / main.dart
Last active July 11, 2021 10:22
A functional way to capitalize each word in a sentence (a.k.a. Title Case). This is not efficient -- use something like string_scanner if you need to run this in a tight loop.
main() {
var city = "new york";
print(titleCase(city));
}
/// Inefficient way of capitalizing each word in a string.
String titleCase(String text) {
if (text.length <= 1) return text.toUpperCase();
var words = text.split(' ');
var capitalized = words.map((word) {
@iamandrewluca
iamandrewluca / oss-tools.md
Last active May 20, 2022 07:18
Open source software tools
@noelvo
noelvo / download-multiple-files.js
Created December 6, 2015 23:22
Download multiple files then compress to one zip file using JSZip & JSZip-utils
var zip = new JSZip();
var count = 0;
var zipFilename = "zipFilename.zip";
var urls = [
'http://image-url-1',
'http://image-url-2',
'http://image-url-3'
];
urls.forEach(function(url){
//file: ./pages/api/checkHTTPMethod.ts
/* this code will allow only GET method requests on this route */
import { Middleware, use } from 'next-api-route-middleware';
import type { NextApiRequest, NextApiResponse } from 'next';
export const allowMethods = (allowedMethods: string[]): Middleware => {
return async function (req, res, next) {
@BilalBudhani
BilalBudhani / FileUpload.js
Last active September 17, 2023 07:21
Upload Multiple Files To Cloudinary With React & Axios
handleDrop = files => {
// Push all the axios request promise into a single array
const uploaders = files.map(file => {
// Initial FormData
const formData = new FormData();
formData.append("file", file);
formData.append("tags", `codeinfuse, medium, gist`);
formData.append("upload_preset", "pvhilzh7"); // Replace the preset name with your own
formData.append("api_key", "1234567"); // Replace API key with your own Cloudinary key
formData.append("timestamp", (Date.now() / 1000) | 0);
@timosadchiy
timosadchiy / jest.config.js
Last active September 22, 2023 05:46
Jest + Typescript. Resolve tsconfig.json paths.
/**
* Converts paths defined in tsconfig.json to the format of
* moduleNameMapper in jest.config.js.
*
* For example, {'@alias/*': [ 'path/to/alias/*' ]}
* Becomes {'@alias/(.*)': [ '<rootDir>/path/to/alias/$1' ]}
*
* @param {string} srcPath
* @param {string} tsconfigPath
*/
@mhaecal
mhaecal / middleware.ts
Created July 19, 2022 08:25
Protected Routes Middleware NextJS 12
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(req: NextRequest) {
// get cookie token
const hasToken = req.cookies.get('token')
// protected routes (admin routes)
if (req.nextUrl.pathname.startsWith('/admin')) {
if (hasToken) {
@ca0v
ca0v / debounce.ts
Last active April 4, 2024 08:28
Typescript Debounce
// ts 3.6x
function debounce<T extends Function>(cb: T, wait = 20) {
let h = 0;
let callable = (...args: any) => {
clearTimeout(h);
h = setTimeout(() => cb(...args), wait);
};
return <T>(<any>callable);
}
@graydon
graydon / country-bounding-boxes.py
Created April 23, 2014 00:03
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//