Skip to content

Instantly share code, notes, and snippets.

@productioncoder
productioncoder / index.js
Last active October 13, 2023 18:45
Session-based authentication in express.js
const express = require('express');
const session = require('express-session');
const redis = require('redis');
const connectRedis = require('connect-redis');
const app = express();
// if you run behind a proxy (e.g. nginx)
// app.set('trust proxy', 1);
@productioncoder
productioncoder / AddComment.js
Last active November 26, 2021 23:42
Youtube AddComment component
import React from 'react';
import './AddComment.scss';
import {Form, Image, TextArea} from "semantic-ui-react";
export function AddComment() {
return (
<div className='add-comment'>
<Image className='user-image' src='http://via.placeholder.com/48x48' circular/>
<Form>
<Form.TextArea control={TextArea} autoHeight placeholder='Add a public comment' />
@productioncoder
productioncoder / App.js
Last active December 12, 2020 08:43
Navigating between Home and Watch component
import React, {Component} from 'react';
import {Home} from './containers/Home/Home';
import {AppLayout} from './components/AppLayout/AppLayout';
import {Route, Switch} from 'react-router-dom';
import {Watch} from './containers/Watch/Watch';
class App extends Component {
render() {
return (
<AppLayout>
@productioncoder
productioncoder / SideBarItem.unit.test.js
Last active December 9, 2020 12:30
SideBarItem snapshot testing
import React from 'react';
import {shallow} from 'enzyme';
import {SideBarItem} from '../SideBarItem';
describe('SideBarItem', () => {
test('renders empty SideBarItem', () => {
const wrapper = shallow(
<SideBarItem/>
);
expect(wrapper).toMatchSnapshot();
@productioncoder
productioncoder / setup-scss.sh
Last active November 3, 2019 10:58
Installing dependencies for SCSS preprocessor
yarn add node-sass
@productioncoder
productioncoder / App.js
Last active November 3, 2019 10:56
Cleanup App.js
import React, { Component } from 'react';
class App extends Component {
render() {
return (
<div>Hello World</div>
);
}
}
@productioncoder
productioncoder / scaffold-react-app.sh
Last active November 3, 2019 10:55
Scaffold a React app using create-react-app
npx create-react-app youtube-react
@productioncoder
productioncoder / setting-up-git-repo.sh
Last active November 3, 2019 10:54
Initialize and setup a git repo for a project created with create-react-app
cd youtube-react
git init
# connect your local repo to the repo on Github
git remote add origin git@github.com:<YOUR_REPO_NAME>.git
# add all files that create-react-app has created to the repository
git add -A
git commit -m "initial commit"
git push -u origin master
@productioncoder
productioncoder / WatchContent.js
Last active March 3, 2019 10:00
Youtube in React: pull in total amount of comments for a specific video
/* ... */
import React from 'react';
import {Video} from '../../../components/Video/Video';
import {VideoMetadata} from '../../../components/VideoMetadata/VideoMetadata';
import {VideoInfoBox} from '../../../components/VideoInfoBox/VideoInfoBox';
import {Comments} from '../../Comments/Comments';
import {RelatedVideos} from '../../../components/RelatedVideos/RelatedVideos';
import './WatchContent.scss';
import {getAmountComments, getRelatedVideos, getVideoById} from '../../../store/reducers/videos';
import {connect} from 'react-redux';
@productioncoder
productioncoder / video.js
Last active February 28, 2019 19:46
Youtube video watcher saga
import * as api from '../api/youtube-api';
import {fork, take, takeEvery, call, all, put} from 'redux-saga/effects';
import {fetchEntity} from './index';
export const fetchVideoCategories = fetchEntity.bind(null, api.buildVideoCategoriesRequest, videoActions.categories);
export function* watchVideoCategories() {
yield takeEvery(videoActions.VIDEO_CATEGORIES[REQUEST], fetchVideoCategories);
}