Skip to content

Instantly share code, notes, and snippets.

View SebastianUdden's full-sized avatar
:octocat:
const jsNr1 = softwareEatsWorld => webEatsSoftware => javaScriptRulesWeb => true

Sebastian Uddén SebastianUdden

:octocat:
const jsNr1 = softwareEatsWorld => webEatsSoftware => javaScriptRulesWeb => true
View GitHub Profile
@SebastianUdden
SebastianUdden / stack-with-grid.jsx
Last active April 19, 2022 10:53
Stack with grid
import React from "react";
import styled from "styled-components";
const Stack = styled.div`
display: grid;
grid-template-rows: 1fr;
grid-template-columns: 1fr;
background-color: #444;
padding: 50px;
// Functional component
const Input = forwardRef(function Input(props, ref) {
return <input ref={ref} {...props} />;
});
// HOC component
const Comp = ({focused, forwardedRef, ...rest}) => <input className={classnames(styles.comp, focused && styles.focused)} ref={forwardedRef} />);
const EnhancedComp = compose(
withState('focused', 'setFocused', false),
const getLeadingZero = number => (number < 10 ? `0${number}` : number)
export const formatDate = dateString => {
const dateTime = new Date(dateString)
const year = dateTime.getFullYear()
const month = getLeadingZero(dateTime.getMonth() + 1)
const day = getLeadingZero(dateTime.getDate())
const hours = getLeadingZero(dateTime.getHours())
const minutes = getLeadingZero(dateTime.getMinutes())
return { date: `${year}-${month}-${day}`, time: `${hours}:${minutes}` }

Create a notifications server

In order to handle push notifications we'll need a client that can recieve notifications and a server that can push notifications. These instructions will help setup a barebones notifications server.

Initial setup

Create the folder notifications-server, go into it and setup an empty git repository, then install express and web-push as a base for our barebones server.

mkdir notifications-server
cd notifications-server

Create a notifications client

In order to handle push notifications we'll need a client that can recieve notifications and a server that can push notifications. These instructions will help setup a barebones notifications client.

Folder

Create a folder called notifications-client in your repositories folder

Initiate

Go to gists overview

Web development prerequisites

In order to efficiently develop new web pages and be able to use your creativity on the web fully, there are a few handy tools that should first be aquired:

For Mac users

  1. Go to https://www.iterm2.com/ and download iTerm, a great customizeable terminal
  2. Go to https://code.visualstudio.com/ and download VS Code, a powerful and customizeable code editor
  3. Go to https://nodejs.org/ and install the LTS version of Node, in short node is basically an environment for javascript to be run on the server side.
@SebastianUdden
SebastianUdden / preload-small-image-before-original.md
Last active December 6, 2020 09:41
Preload small image before the original

Go to gists overview

Preload a smaller image

After adding an image as background to your page you may find that it's required to be a high resolution in order to not look pixelated on big screens. This will unfortunately mean you get a clunky 90:s feeling with the image loading from top to bottom for users on 3G or worse connections. In order to avoid this we can create a compressed pixelated version of the image to show when the user enters the page, then swap the images once the big image is finished loading. Here's how:

How to test the issue

  1. Use Chrome because it's awesome (otherwise google how to do this in other browsers)
  2. Run your project locally or go to the published version
  3. Open Chrome DevTools with CMD+Option+I on Mac or CTRL+Option+I on Windows
@SebastianUdden
SebastianUdden / add-a-full-screen-background-image.md
Last active December 6, 2020 09:41
Add a full-screen background image
@SebastianUdden
SebastianUdden / make-react-container-full-widht-and-height.md
Last active July 30, 2025 14:29
Make your React app full width and height