Skip to content

Instantly share code, notes, and snippets.

@dd701116
dd701116 / gist:2cf20c14a32e1c92e45e974750ef4b29
Created February 20, 2024 15:37
Search in select options
const searchInput = document.getElementById("search-in-select-input")
const selectTagToManage = document.getElementById("csvBoxAbove")
function searchInSelect(value) {
for (let index = 0; index < selectTagToManage.options.length; index++) {
selectTagToManage.options[index].hidden = !(new RegExp(`${value}`, "ig")).test(selectTagToManage.options[index].value)
}
}
@dd701116
dd701116 / getDomainName.js
Created December 20, 2023 16:56
Get domain name
function getDomainName(url){
function isDomainName(domain){
return domain.match(/^[a-zA-Z0-9][a-zA-Z0-9-\.]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/)!==null
}
let matches = url.match(/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/)
if(matches.length>=2){
let domain = matches[1]
return isDomainName(domain)? domain : null
// An asynchronous function
async function theAsynchronousMethod() {
return Math.floor(Math.random() * Math.floor(6));
}
// Another asynchronous function
async function anotherAsynchronousMethod() {
// Wait the response
let dice = await theAsynchronousMethod();
// And continue
// Execute the first method and THEN call the resolve method or CATCH the rejection
thePromiseGiver().then(yes).catch(no);
// The method wich return a promise
function thePromiseGiver() {
return new Promise((resolve, reject) => {
let dice = Math.floor(Math.random() * Math.floor(6));
if (dice>=3) {
resolve(dice);
}else{
reject(new Error(dice));
}
});
@dd701116
dd701116 / devto-1-callback-example.js
Last active March 29, 2021 05:32
The 3 ways to make an asynchronous method in JavaScript
// The callback method
function theCallback() {
console.log("Hello from the callback !");
}
// The callback will execute in 1000 ms
setTimeout(theCallback,1000);
console.log("Hello World !");
public interface Repository<T> {
/**
* Get all element which respect the filter
* @param filter
* @return List of result
*/
public ArrayList<T> readAll(T filter);