Skip to content

Instantly share code, notes, and snippets.

View fwojciec's full-sized avatar

Filip Wojciechowski fwojciec

View GitHub Profile
@fwojciec
fwojciec / go-web-workshop_s02-e2.go
Last active July 23, 2018 10:49
My solution to "Exercise Hello, Handler" from Section 02 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section02/README.md
package main
import (
"fmt"
"log"
"net/http"
)
@fwojciec
fwojciec / go-web-workshop_s02-e3.go
Last active July 23, 2018 10:48
My solution to "Exercise Hello, {you}" from Section 02 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section02/README.md
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
@fwojciec
fwojciec / go-web-workshop_s03-e1.go
Created July 23, 2018 11:12
My solution to "Exercise Hello, parameter" from Section 03 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section03/README.md
// this version is able to handle multiple parameters with the same name
package main
import (
"fmt"
"log"
"net/http"
@fwojciec
fwojciec / go-web-workshop_s03-e2.go
Created July 23, 2018 12:02
My solution to "Exercise Hello, body" from Section 03 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section03/README.md
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
@fwojciec
fwojciec / go-web-workshop_s03-e3.go
Last active July 23, 2018 12:41
My solution to "Exercise better errors" from Section 03 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section03/README.md
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
@fwojciec
fwojciec / go-web-workshop_s03-e4.go
Created July 23, 2018 12:41
My solution to "Exercise status codes with http.Error" from Section 03 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section03/README.md
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
@fwojciec
fwojciec / go-web-workshop_s03-e5.go
Last active July 23, 2018 17:44
My solution to "Exercise Setting headers only once + optional + super optional" from Section 03 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section03/README.md
// Found these very helpful in the context of this exercise (optional tasks):
// 1. https://blog.questionable.services/article/custom-handlers-avoiding-globals/
// 2. https://blog.questionable.services/article/http-handler-error-handling-revisited/
package main
import (
"errors"
@fwojciec
fwojciec / index.tsx
Created September 3, 2019 12:59
How to build a multilingual website in Next.js #1
// pages/index.tsx
import React from 'react'
import Head from 'next/head'
import { getInitialLocale } from '../translations/getInitialLocale'
import { useRouter } from 'next/dist/client/router'
const Index: React.FC = () => {
const router = useRouter()
React.useEffect(() => {
@fwojciec
fwojciec / getInitialLocale.ts
Created September 3, 2019 13:02
How to build a multilingual website in Next.js #2
// translations/getInitialLocale.ts
import { defaultLocale } from './config'
import { Locale, isLocale } from './types'
export function getInitialLocale(): Locale {
// preference from the previous session
const localSetting = localStorage.getItem('locale')
if (localSetting && isLocale(localSetting)) {
return localSetting
@fwojciec
fwojciec / types.ts
Last active September 3, 2019 13:36
How to build a multilingual website in Next.js #3
// translations/types.ts (excerpt)
export function isLocale(tested: string): tested is Locale {
return locales.some(locale => locale === tested)
}