Skip to content

Instantly share code, notes, and snippets.

View selbekk's full-sized avatar
👨
Working dad

Kristofer Giltvedt Selbekk selbekk

👨
Working dad
View GitHub Profile
@selbekk
selbekk / i18n.ts
Created April 12, 2023 20:06
A simple i18n feature for next.js
import { useRouter } from "next/router";
/** The supported languages as enums */
export enum Language {
English = "en",
Norwegian = "no",
}
export type LanguageObject = {
[key in Language]: string | React.ReactNode;
};
@selbekk
selbekk / gist:c171c0e09b2d9e002ee5e1c30f9e2769
Last active March 24, 2023 06:42
Meghan Trainor's "All about that rebase"
(Verse 1)
Yeah, it's pretty clear, I ain't no Git rookie
But I can merge it, merge it, like I'm supposed to do
'Cause I got that repo that all the devs chase
All the right branches and all the right bases
(Pre-Chorus)
I see the dev team working that commit race
We know that merge ain't the only way to save face
If you got Git skills, skills
@selbekk
selbekk / types.d.ts
Created April 3, 2022 19:12
Types for OpenGraph.ninja API
type Response = {
hostname: string;
requestUrl: string;
title: string;
description: string;
image?: {
url: string;
alt?: string;
};
details: Details;
@selbekk
selbekk / server.js
Created August 18, 2017 12:39
Super simple server side rendering with React and styled-components
const express = require('express');
require('babel-register')({
ignore: /\/(build|node_modules|.svg)\//,
presets: ['env', 'react-app']
});
const universal = require('./universal');
const app = express();
@selbekk
selbekk / code-snippets.json
Created July 29, 2020 10:50
My VSCode snippets
{
"Create a useState block": {
"prefix": ["useState", "us"],
"body": [
"const [${1:state}, set${1/(.*)/${1:/capitalize}/}] = React.useState(${2:initialState})"
],
"description": "Create a regular useState hook"
},
"Create a useEffect block": {
"prefix": ["useEffect", "ue"],
@selbekk
selbekk / Main.elm
Created January 2, 2020 22:47
Dad joke app in Elm
module Main exposing (..)
import Browser
import Html exposing (..)
import Html.Attributes as A
import Html.Events as Events
import Http
main =
@selbekk
selbekk / image-optimizer.js
Created August 24, 2018 09:42
An image optimizer in JS
import Pica from 'pica';
const getImageFromFile = file =>
new Promise(resolve => {
const reader = new FileReader();
const image = new Image();
reader.onload = async fileReaderEvent => {
image.onload = () => resolve(image);
image.src = await fileReaderEvent.target.result;
};
@selbekk
selbekk / webpack.config.js
Last active August 1, 2018 09:42
webpack and less - webpack.config.js
const path = require('path');
const config = {
// First, let's define an entry point for webpack to start its crawling.
entry: './src/index.js',
// Second, we define where the files webpack produce, are placed
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
@selbekk
selbekk / webpack.config.js
Last active August 1, 2018 09:42
webpack and less - webpack.config.js
const path = require('path');
const config = {
// First, let's define an entry point for webpack to start its crawling.
entry: './src/index.js',
// Second, we define where the files webpack produce, are placed
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
@selbekk
selbekk / webpack.config.js
Last active August 1, 2018 09:42
webpack and less -webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const config = {
// First, let's define an entry point for webpack to start its crawling.
entry: './src/index.js',
// Second, we define where the files webpack produce, are placed
output: {