Skip to content

Instantly share code, notes, and snippets.

View _document.js
import Document, { Head, Main, NextScript } from 'next/document';
// Import styled components ServerStyleSheet
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document {
static getInitialProps({ renderPage, req }) {
// Step 1: Create an instance of ServerStyleSheet
const sheet = new ServerStyleSheet();
Atinux / async-foreach.js
Last active May 31, 2023 03:29
JavaScript: async/await with forEach()
View async-foreach.js
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
View makeEl-2.js
function makeElement(type, text) {
const el = document.createElement(type);
const textNode = document.createTextNode(text);
return el;
const h1 = (text) => makeElement(`h1`, text);
View ffmpeg-compress
ffmpeg -i data/video.mp4 -vcodec h264 -b:v 1000k -acodec mp2 data/output.mp4
gaearon / connect.js
Last active April 26, 2023 02:22
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
View node_prompt_es6_promises.js
'use strict';
export default function (question) {
var rl = require('readline');
var r = rl.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
return new Promise((resolve, error) => {
codegenin / dob.html
Created October 7, 2015 10:57
Months and Days Select List
View dob.html
<!-- Month dropdown -->
<select name="month" id="month" onchange="" size="1">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
linhmtran168 / pre-commit-eslint
Last active February 27, 2023 18:05
Pre-commit hook to check for Javascript using ESLint
View pre-commit-eslint
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
lukehedger / ffmpeg-compress-mp4
Last active May 27, 2023 05:12
Compress mp4 using FFMPEG
View ffmpeg-compress-mp4
$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
dergachev /
Last active May 31, 2023 13:08
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF


To capture the video (filesize: 19MB), using the free "QuickTime Player" application: