Skip to content

Instantly share code, notes, and snippets.

View emwadde's full-sized avatar

M Waheed emwadde

  • Ministry of Education
  • Earth
  • X @emwadde
View GitHub Profile
@emwadde
emwadde / default.conf
Created January 14, 2024 09:49
nginx default config
server {
listen 80 default_server;
server_name _;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /health {
@emwadde
emwadde / dev-console-save.js
Last active December 2, 2023 04:13
console.save to save json to file from browser console
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
@emwadde
emwadde / webscrap-text.js
Last active July 14, 2022 08:37
Using browser console as a webscrapping tool
var fetchText = async (url) => {
return new Promise((resolve, reject) => {
fetch(url)
.then(response => {
if(response.status == 200) return response.text();
throw new Error(response.statusText)
})
.then(html => {
let parser = new DOMParser();
let doc = parser.parseFromString(html, 'text/html');
//scrapped from wikipedia: https://en.wikipedia.org/wiki/List_of_islands_of_the_Maldives
// var islands = [];
// document.querySelectorAll(".mw-headline").forEach(el => {
// if (el.textContent.match(/\(.+\)/)) {
// [...el.parentElement.nextElementSibling.nextElementSibling.children].forEach(li => {
// islands.push({ atoll: el.textContent, island: li.children[0].title })
// })
// }
// })
@emwadde
emwadde / yt-links.js
Last active September 12, 2020 20:41
Get YouTube vide direct links in Nodejs
@emwadde
emwadde / slugify-string.js
Last active October 19, 2020 20:46
Codes for JS environments (mostly app-script and nodejs)
//can be used as ArrayFunction in google sheets + appscript
function slugify(input) {
if (input.map) { // Test whether input is an array.
return input.map(slugify); // Recurse over array if so.
} else {
let slug = '';
slug = input.toLowerCase();
slug = slug.replace(/[^\w\s-]/g, '');
slug = slug.replace(/\s+/g, '-');
return slug;