Skip to content

Instantly share code, notes, and snippets.

function isNakedDay() {
const now = new Date();
const year = now.getFullYear();
const start = new Date(year, 3, 24, -14, 0, 0).getTime() / 1000;
const end = new Date(year, 3, 24, 36, 0, 0).getTime() / 1000;
const z = now.getTimezoneOffset() * 60;
const currentTime = now.getTime() / 1000 - z;
return currentTime >= start && currentTime <= end;
}
@macdonst
macdonst / page-layout.mjs
Created February 9, 2024 14:05
Slotted Layout Component
export default function PageLaout ({ html, state }) {
const { attrs = {} } = state
const { mobileBreakpoint = '40rem', desktopBreakpoint = '60rem' } = attrs
return html`
<style>
:host {
min-height: 100vh;
display: grid;
grid-template-areas:
'header'
const path = require('path')
const { readFileSync } = require('fs')
exports.handler = async function http (req) {
let here = path.dirname('.')
let postsFilePath = path.join(here, 'rss.xml.br')
let posts = readFileSync(postsFilePath, 'binary')
console.log(posts.length)
@macdonst
macdonst / sent-toot.mjs
Created February 5, 2023 18:05
Post a message to Mastodon
import Meg from 'megalodon'
const { default: generator } = Meg
// switch to your mastodon server
const BASE_URL = 'https://mastodon.online/'
const access_token = process.env.MASTODON_TOKEN
export async function handler (event) {
const {title, link, description} = JSON.parse(event.Records[0].Sns.Message)
function owenv() {
bold=$(tput bold)
normal=$(tput sgr0)
switches=""
space=$1
case "$space" in
"cloudshell")
host=runtime.adobe.io
key=<api key>
@macdonst
macdonst / wolfram.js
Created September 4, 2018 13:01
MS Azure Function to ask Wolfram Alpha a question
const fetch = require('node-fetch');
const credentials = require('./credentials');
module.exports = async function(context, req) {
if (req.query.searchTerm || (req.body && req.body.searchTerm)) {
const searchTerm = req.query.searchTerm ||
req.body.searchTerm;
let url = `http://api.wolframalpha.com/v2/query?input=${searchTerm}&appid=${
credentials.wolfram
}`;
@macdonst
macdonst / translate.js
Created September 4, 2018 13:01
MS Azure Function to call Google Translate
const fetch = require('node-fetch');
const credentials = require('./credentials');
module.exports = async function(context, req) {
if (req.query.searchTerm || (req.body && req.body.searchTerm)) {
const searchTerm = req.query.searchTerm ||
req.body.searchTerm;
let url = `https://www.googleapis.com/language/translate/v2?key=${
credentials.google
}&source=en&target=fr&q=${searchTerm}`;
@macdonst
macdonst / server.js
Last active September 4, 2018 12:59
Node server using Hapi.js
'use strict';
const Hapi = require('hapi');
const Joi = require('joi');
const fetch = require('node-fetch');
const credentials = require('./credentials');
const server = Hapi.server({
host: '0.0.0.0',
port: 8000
const leftPad = require('left-pad');
function main(args) {
const name = args.name || 'World';
return { payload: `Hello, ${leftPad(name, 30, ".")}!` };
}
global.main = main;
function main(args) {
return { payload: 'Hello world' };
}
global.main = main;