Skip to content

Instantly share code, notes, and snippets.

View adregan's full-sized avatar
🛶
My other car is a canoe

Duncan Regan adregan

🛶
My other car is a canoe
View GitHub Profile
optimalChargeDischarge←{
⍝ ⍵ is a list of numbers
⍝ returns an array of 3 values (charge, discharge, revenue)
⎕IO←0 ⍝ zero based indexing is required
⍝ create table of differences between values
diffs←∘.(-⍨)⍨⍵ ⍝ flip subtraction as we are interested in the difference from left to right
mask←∘.<⍨⍳≢⍵ ⍝ Create a mask including only the upper right corner (excluding diagonal)
⍝ The upper right corner represents the differences that move forward in time
@adregan
adregan / auth.js
Last active March 30, 2023 19:21
Authentication issues
const AUTH_URL = 'https://smartweather.weatherflow.com/authorize.html'
export const toAuthUrl = ({
clientId: client_id,
codeChallenge: code_challenge,
}) => {
const params = {
response_type: 'code',
redirect_uri: '<REDIRECT_URL>',
code_challenge_method: 'S256',
@adregan
adregan / day10.py
Last active December 11, 2021 00:32
import re
from functools import partial
stripPairs = partial(re.sub, "\(\)|\[\]|{}|<>", "")
def untilStable(f, x):
if ((y := f(x)) == x): return x
else: return untilStable(f, y)
navs = [
⌊/+/(|(⍳1+⌈/)∘.-⊢)in
⌊/+/((+/(1∘+⍤⍳⊢))⍤0⊢)(|(⍳1+⌈/)∘.-⊢)in
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body, html {
height: 100%;
margin: 0;
width: 100%;
@adregan
adregan / rides.json
Last active December 30, 2020 13:06
{"count": 20, "fitness_disciplines": [{"id": "walking", "name": "Walking"}, {"id": "strength", "name": "Strength"}, {"id": "cycling", "name": "Cycling"}, {"id": "stretching", "name": "Stretching"}, {"id": "running", "name": "Running"}, {"id": "beyond_the_ride", "name": "Floor"}, {"id": "circuit", "name": "Bootcamp"}, {"id": "yoga", "name": "Yoga"}, {"id": "meditation", "name": "Meditation"}, {"id": "cardio", "name": "Cardio"}], "rides": [{"scheduled_start_time": 1565883000, "rating": 0, "difficulty_rating_avg": 0.0, "equipment_tags": [], "difficulty_rating_count": 0, "captions": [], "title": "30 min Power Zone Ride", "is_explicit": false, "live_stream_id": "e571d20a9efc4e34a75a8bb3924acfd7-live", "origin_locale": "en-US", "difficulty_estimate": null, "content_format": "video", "location": "nyc", "original_air_time": 1565882340, "has_closed_captions": false, "pedaling_duration": 1800, "sample_vod_stream_url": null, "extra_images": [], "series_id": "9fde039566054ea499130bed1c289eb3", "studio_peloton_id": "7812b
function fixup
set -lx current_branch (git rev-parse --abbrev-ref HEAD)
set -lx commits (git log --oneline $current_branch...origin/master)[-1..1]
set -lx len (count $commits)
printf "Fixup: Which commit would you like to fixup? \n\n"
for i in (seq $len)
printf "$i) $commits[$i]\n"
end
function nand
set -lx nand_path "/Users/duncan/projects/nand2tetris/tools"
set -lx programs (ls $nand_path | rg "sh")
printf "Nand2Tetris: Which Program would you like to run? \n\n"
set -lx len (count $programs)
for i in (seq (count $programs))
printf "$i) $programs[$i]\n"
end
@adregan
adregan / README.md
Created January 26, 2019 17:30
SCRIPT-8
import React from 'react';
import styled from 'styled-components';
const createGetPosition = end => index => {
if (index === 0) {
return 'flex-start'
} else if (index === end) {
return 'flex-end'
} else {
return 'center'