Skip to content

Instantly share code, notes, and snippets.

@woat
woat / fn.go
Last active May 28, 2020 03:23
package main
import (
"fmt"
"net/http"
)
func fn(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
fmt.Fprintf(w, "Hello " + q.Get("name"))
@woat
woat / 0_side-effect-imports-golang
Last active April 1, 2020 08:33
side effect import golang
/*
WARNING: This product can expose you to chemicals including abestos,
which is known to the State of California to cause cancer and birth
defects or other reproductive harm.
For more information go to www.P65Warnings.ca.gov.
*/
const a = [4,4,0,0,2,3,1,2,2]
let i = 0
let mostFreqK = 0
while (i < a.length) {
if (a[i] < 0) {
i++
continue
}
https://golang.org/pkg/sort/#Slice
@woat
woat / vue2ghpages.js
Created April 26, 2018 22:49
Vue to GH-Pages
// config/index.js
dev: {
// ...
assetsPublicPath: './',
// ...
},
build: {
// ...
assetsPublicPath: './',
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 id="lilpump"></h1>
<script>
const url = "PUT THE URL HERE"
fetch(url)
.then(response => response.json())
/*
First we must call the API.
We can do that by using the built-in ES6 function called fetch.
Fetch simply takes an end point (in this case, the URL that is in quotes).
*/
fetch('https://jsonplaceholder.typicode.com/users')
/*
Now remember what I said about an API's response?
It usually spits out JSON which is close to a regular object.
But not quite.
fetch('https://jsonplaceholder.typicode.com/users')
.then(API_Response => API_Response.json())
.then(data => console.log(data))
{
"name": "Mario",
"age": 22,
"brother": "Luigi",
"food": "Mushroom"
}
const Person = {
name: "Mario",
age: "22",
brother: "Luigi",
food: "Mushrooms"
}