Skip to content

Instantly share code, notes, and snippets.

View MegaMinxCoding's full-sized avatar
💪
Always ready for more!

Felix Schober MegaMinxCoding

💪
Always ready for more!
View GitHub Profile
@MegaMinxCoding
MegaMinxCoding / CalendarWeek.js
Created January 14, 2023 19:16
Output the calendar week of a date
function calendarWeek(d) {
// Copy date so don't modify original
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
// Set to nearest Thursday: current date + 4 - current day number
// Make Sunday's day number 7
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7));
// Get first day of year
var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
// Calculate full weeks to nearest Thursday
var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7);
@MegaMinxCoding
MegaMinxCoding / Emailvalidation.js
Created January 14, 2023 19:08
JS Email Validation Regex
function ValidateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
@MegaMinxCoding
MegaMinxCoding / date_of_next_monday.js
Last active January 11, 2023 21:43
Get the date of the next monday from a given date string.
/**
* Searches for the next possible monday and returns it. To change the desired weekday - change line 7 "days.xxxx".
*/
const days = {
// "sunday": 0, // << if sunday is first day of week
"monday": 1,
"tuesday": 2,
"wednesday": 3,
"thursday": 4,
"friday": 5,
@MegaMinxCoding
MegaMinxCoding / toIsoString.js
Last active January 15, 2023 13:11
Create an actual ISO string referring to the local TZ
function toIsoString(date_param) {
if (date_param === undefined || date_param === null)return ''
if(!((date_param instanceof Date) || (typeof date_param ==="string"))) throw new Error(`Illegal Argument of type ${typeof date_param} on method toIsoString! Expected date or string.`)
let date = new Date(date_param)
var tzo = -date.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function (num) {
return (num < 10 ? '0' : '') + num
@MegaMinxCoding
MegaMinxCoding / create_docker_secrets.py
Created December 21, 2022 14:37
Create Docker Secrets (on the underlying os)
import os
#avoid the character >"< in your passwords
pwds = """
my-secret1: value1
my-secret2: value2
""".split("\n")
for line in pwds:
if not line: continue