Skip to content

Instantly share code, notes, and snippets.

func add(x, y int) int {
return x + y
}
func TestAddingExample(t *testing.T) {
result := add(3, 2)
if result != 5 {
t.Error("3 plus 2 is 5 but i got", result)
}
}
type LatLong struct{
Lat float64
Long float64
}
func (l LatLong) Generate(rand *rand.Rand, size int) reflect.Value{
randomLatLong := LatLong{
Lat: rand.Float64(),
Long: rand.Float64(),
}
@quii
quii / blah.go
Created August 4, 2018 20:16
Dependencies
package main
import (
"net/http"
"fmt"
)
type MessageGetter interface {
GetMessage() string
}
address_book = {
"Chris" => "chris@james.com",
"Ruth" => "ruth@baker.com",
"Pepper" => "pepper@pot.com"
}
givers = address_book.keys.shuffle
receivers = givers.rotate(1)
givers_receivers = givers.zip(receivers)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chris James, London - Software Engineer</title>
<meta charset="UTF-8"/>
<meta name="description" content="Chris James, London - Software Engineer" lang="en"/>
<meta name="viewport" content="width=device-width, minimumscale=
1.0, maximum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="{{.CSSPath}}">
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/rss" />
# frozen_string_literal: true
require_relative './setup_test_database'
ENV['RACK_ENV'] = 'test'
ENV['ENVIRONMENT'] = 'test'
# Bring in the contents of the `app.rb` file
require File.join(File.dirname(__FILE__), '..', 'app.rb')
@quii
quii / stitcher.go
Created February 14, 2020 11:29
stitcher
func Stitcher(w http.ResponseWriter, r *http.Request) {
urls := r.URL.Query()["url"]
if len(urls) == 0 {
http.Error(w, "please provide a url querystring value", http.StatusBadRequest)
return
}
for _, url := range urls {
res, _ := http.Get(url)
@quii
quii / stitcher.go
Created February 14, 2020 11:34
concurrent stitcher
func Stitcher(w http.ResponseWriter, r *http.Request) {
urls := r.URL.Query()["url"]
if len(urls) == 0 {
http.Error(w, "please provide a url querystring value", http.StatusBadRequest)
return
}
bodies := make(chan io.ReadCloser, len(urls))
@quii
quii / stitcher_test.go
Created February 14, 2020 11:47
stitcher tests
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
)