Skip to content

Instantly share code, notes, and snippets.

@horsfallnathan
horsfallnathan / pub_sub.go
Created July 16, 2022 11:16
A pub/sub implementation in golang
package main
import (
"context"
"fmt"
"math/rand"
"time"
)
type Subscriber struct {
@horsfallnathan
horsfallnathan / class_delegation.py
Created August 12, 2021 03:50
Example of class delegation
# Source: https://stackoverflow.com/a/26467767
class Parent(object):
def __init__(self, name, number):
self.name = name
self.number = number
def scream(self):
print('pparent')
@horsfallnathan
horsfallnathan / pyServer.py
Created September 8, 2020 10:27
Simple python httpserver
#!/usr/bin/env python3
import http.server as httpserver
class CORSHTTPRequestHandler(httpserver.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
@horsfallnathan
horsfallnathan / extract.md
Last active August 20, 2020 08:44
Get jest testing help

I have a simple Node application that takes form data from a website and saves to a Google sheets document. Wrote this some time back and now I am trying to write tests for it.

I have the submit function which is called when the client visits the '/submit' post route. Its content are:

// submit.routes.js

function Submit(req, res, next) {
  const { data, token } = req.body;
  const url = `https://www.google.com/recaptcha/api/siteverify?secret=${secret_key}&response=${token}`;
@horsfallnathan
horsfallnathan / scssSnippets.md
Created May 25, 2020 19:18
SCSS snippets I always forget

Vertical centering with absolute positioning

.container{
    position:relative;
}
.content{
    position:absolute;
 top:50%;
function useTranslation() {
// here I make locale default to the defaultLocale value
const { locale = defaultLocale } = useContext(LocaleContext);
function t(key) {
const pathArr = [locale, ...key.split(".")];
const translation = pathArr.reduce((obj, path) => {
return (obj || {})[path];
}, dict);
console.log(translation);
const dict = {
en: {
welcome: "welcome to my page",
menu: {
about: "About Me"
}
},
de: {
welcome: "wilkommen bei meinem seite",
menu: {
import React, { useState, useEffect } from "react";
import "./App.css";
import SVGFile from "./svgFile";
function App() {
const [inputValue1, setInputValue1] = useState("");
const [calculatedRate, setCalculatedRate] = useState(0);
const handleChange = e => {
e.preventDefault();
setInputValue1(e.target.value);
import React from "react";
export default function SVGFile() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xlink="http://www.w3.org/1999/xlink"
version="1.1"
id="Layer_1"
x="0px"
import React from "react";
export default function SVGFile() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xlink="http://www.w3.org/1999/xlink"
version="1.1"
id="Layer_1"
x="0px"