Skip to content

Instantly share code, notes, and snippets.

View betandr's full-sized avatar
🦄
Vague, but exciting...

Beth Anderson betandr

🦄
Vague, but exciting...
View GitHub Profile
@betandr
betandr / main.go
Last active March 4, 2024 01:34
Fitbit Export Weight Data to CSV
// Converts the data created by Fitbit export from the output JSON
// to comma-separated values.
// go run main.go > weight.csv
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
@betandr
betandr / semver.go
Created September 27, 2022 10:22
Semver
package main
import (
"flag"
"fmt"
"github.com/Masterminds/semver/v3"
)
var vFlag = flag.String("version", "0.1", "version to check")
@betandr
betandr / extract_hashtags.python
Last active February 27, 2022 06:58
Extract hashtags in Python to a set
import re
def extract_hash_tags(s):
return set([re.sub(r"#+", "#", k) for k in set([re.sub(r"(\W+)$", "", j, flags = re.UNICODE) for j in set([i for i in text.split() if i.startswith("#")])])])
tweet = "There are a #few #hashtags in #this text but #only a #few"
print extract_hash_tags(tweet)
@betandr
betandr / indices.go
Created February 11, 2022 15:48
Return indices of two numbers summed matching a target
// Given an array of integers that is already sorted in ascending
// order find two numbers such that they add up to a specific target number.
//
// The function twoSum should return indices of the two numbers such that
// they add up to the target where index1 must be less than index2.
package main
import (
"errors"
"fmt"
@betandr
betandr / dijkstra.py
Last active November 15, 2021 20:43
Dijkstra's Shortest Path Algorithm in Python
from decimal import Decimal
class Node:
def __init__(self, label):
self.label = label
class Edge:
def __init__(self, to_node, length):
self.to_node = to_node
self.length = length
@betandr
betandr / generics.go2
Last active June 3, 2021 15:09
Go 2 Generics
// Go 2 Playground: https://go2goplay.golang.org/
//
// Or to install the go2go tool:
// git clone https://go.googlesource.com/go goroot
// cd ./goroot
// git checkout dev.go2go
// cd ./src
// CGO_ENABLED=0 ./all.bash
// export PATH=/path/to/your/goroot/bin:$PATH
//
@betandr
betandr / tor.md
Last active December 27, 2020 16:18
Creating a Tor Server on GCP

Set up a Tor Server on Debian

Install and Configure Apache

sudo apt-get update
sudo apt-get install -y apache2

sudo vi /etc/apache2/ports.conf:

@betandr
betandr / main.go
Last active August 6, 2020 13:56
Sum a tree using nil pointer receivers
package main
import "fmt"
type node struct {
v int
l *node
r *node
}
@betandr
betandr / done_channel.go
Created July 8, 2020 15:43
Go "done-channel" pattern
package main
import (
"fmt"
"time"
)
// multiples uses a done channel to shut down
func multiples(i int) (chan int, chan struct{}) {
out := make(chan int)
@betandr
betandr / errors.go
Last active July 8, 2020 13:56
An interface is only considered nil if it is not associated with an underlying value, even a nil value.
package main
import "fmt"
type Error struct {
Message string
}
func (e *Error) Error() string {
return "an error occured"