Skip to content

Instantly share code, notes, and snippets.

View SKempin's full-sized avatar

Stephen Kempin SKempin

View GitHub Profile
@slikts
slikts / context-vs-redux-2020.md
Last active March 6, 2022 20:41
Up to date answer about when to use React context or Redux (Redux Toolkit)

nelabs.dev

React context vs Redux in 2020

The [React docs][condoc] give some example use cases for context:

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

The common property of these use cases is that data like the current theme doesn't change often and needs to be shared deep down the component tree, which would be cumbersome with "[prop drilling][drill]". Something else that needs to be shared everywhere is the application state when using a "single source of truth" pattern, so it would follow that the context API would help with that as well, but there's a catch: components that use context will rerender every time that the provided value changes, so sharing the whole application state through context would cause excessive render lifecycles.

@Alezco
Alezco / index.js
Last active August 31, 2022 20:29
Puppeteer in Google Cloud Functions
const puppeteer = require('puppeteer');
const PUPPETEER_OPTIONS = {
headless: true,
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--timeout=30000',
'--no-first-run',
const fs = require('fs');
const nodemailer = require('nodemailer');
const sendmail = (todaydate) => {
let filename = `geckoboard_${todaydate}.jpg`;
nodemailer.createTestAccount((err, account) => {
let transporter = nodemailer.createTransport({
host: env.EMAIL_HOST, // smtp host
port: 25,
@maciejmatu
maciejmatu / email-response.js
Created May 3, 2018 21:01
Lambda function I use for email auto-response with Netlify forms.
require("dotenv").config(); // read .env file if present.
const nodemailer = require("nodemailer");
const createHtmlMail = require("./modules/mail-template"); // this function returns html email code
exports.handler = function(event, context, callback) {
const user = process.env.MAIL_USER; // some@mail.com
const pass = process.env.MAIL_PASSWORD; // 42isthecoolestnumber
let transporter = nodemailer.createTransport({
const puppeteer = require('puppeteer');
const firebase = require('firebase');
if(!firebase.apps.length) {
let config = {
apiKey: "xxxxxxxxxxxxxxxxxxxxx",
authDomain: "xxxxxxxxxxxxxxxxxxxxxxxx",
databaseURL: "xxxxxxxxxxxxxxxxxxxxx",
projectId: "xxxxxxxxx",
storageBucket: "xxxxxxxxxxxxxxxxxxxx",
import React, { PureComponent } from 'react';
import { View, Text, NetInfo, Dimensions, StyleSheet } from 'react-native';
const { width } = Dimensions.get('window');
function MiniOfflineSign() {
return (
<View style={styles.offlineContainer}>
<Text style={styles.offlineText}>No Internet Connection</Text>
</View>
@blairanderson
blairanderson / conv.sh
Last active December 20, 2021 17:57
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage:
const puppeteer = require('puppeteer');
const nodemailer = require('nodemailer');
class Webpage {
static async generatePDF(url) {
const browser = await puppeteer.launch({ headless: true }); // Puppeteer can only generate pdf in headless mode.
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle', networkIdleTimeout: 5000 }); // Adjust network idle as required.
const pdfConfig = {
format: 'A4',
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active May 20, 2024 12:02
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example