Skip to content

Instantly share code, notes, and snippets.

View smpnjn's full-sized avatar
🥶

Johnny smpnjn

🥶
View GitHub Profile
let propertyId = '<<ENTER YOUR PROPERTY ID HERE>>';
// Get the day 31 days ago
let today = new Date().getTime() - (60 * 60 * 24 * 31 * 1000);
// Get the day, month and year
let day = new Date(today).getDate();
let month = new Date(today).getMonth() + 1;
let year = new Date(today).getFullYear();
// Put it in Google's date format
let dayFormat = `${year}-${month}-${day}`;
import { BetaAnalyticsDataClient } from '@google-analytics/data';
// Creates a client.
const analyticsDataClient = new BetaAnalyticsDataClient({
keyFile: './key.json'
});
const sendNotifications = async function() {
const allSubscriptions = await Subscription.Subscription.find();
allSubscriptions.forEach(function(item) {
let ourMessage = JSON.stringify({
'title' : req.body.titles[0].title,
'body' : req.body.description
});
webpush.sendNotification(item.subscriptionEl, ourMessage).catch(error => {
// Service Worker Notifications
const publicVapidKey = '<<<Public Vapid Key>>>';
const privateVapidKey = '<<<Private Vapid Key>>>';
webpush.setVapidDetails('mailto:someEmail@emailSite.com', publicVapidKey, privateVapidKey);
app.post('/subscribe', jsonParser, async function(req, res) {
try {
let hash = objectHash(req.body);
let subscription = req.body;
npm i web-push -g
web-push generate-vapid-keys
const vapidKey = '<<Your Public Vapid Key>>';
document.getElementById('subscribe').addEventListener('click', async function(e) {
const registration = await navigator.serviceWorker.register('worker.js', {scope: '/'});
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array(vapidKey)
});
await fetch('/subscribe', {
method: 'POST',
for f in $(find /link/to/your/directory/goes/here -name '*.png' -or -name '*.jpg' -or -name '*.jpeg'); do cwebp -q 60 $f -o ${f%.*}.webp; done
<picture>
<source srcset="241220204.webp" type="image/webp" />
<img src="241220204.png" alt="Some alt text goes here" />
</picture>
void main() {
// We need to adjust the size of the effect to the screen resolution
vec2 res = (gl_FragCoord.xy + 100.) / (u_resolution.xy * u_scale);
// Then we access the colors we defined in JS
vec3 highColor = rgb(u_highColor.r, u_highColor.g, u_highColor.b);
vec3 lowColor = rgb(u_lowColor.r, u_lowColor.g, u_lowColor.b);
vec3 color = vec3(0.0);
// Then we do one run through of FBM using various variables we defined
@smpnjn
smpnjn / buttons.js
Last active December 21, 2020 12:25
// Please see Github or Codepen for the full code, this is only an example
document.querySelectorAll('.button').forEach(function(item) {
const elWidth = (parseFloat(window.getComputedStyle(item).width) + parseFloat(window.getComputedStyle(item).paddingLeft) * 2) + 200;
const elHeight = (parseFloat(window.getComputedStyle(item).height) + parseFloat(window.getComputedStyle(item).paddingTop) * 2) + 200;
// Set sizes and set scene/camera
renderer.setSize( elWidth, elHeight );
document.body.appendChild( renderer.domElement )
renderer.setPixelRatio( elWidth/elHeight );