Skip to content

Instantly share code, notes, and snippets.

View TCotton's full-sized avatar
🎯
Focusing

Andrew Walpole TCotton

🎯
Focusing
View GitHub Profile
@TCotton
TCotton / briggs.hs
Created October 26, 2025 17:04
Use of every and superimpose
d3
$ every 4 ( superimpose
( slice 2 (fast "2" "[1 2 3 4]" ) -- re-slice give variation of slight glitch
. (|+| gain "0.1") -- slightly louder
. ( # sound "bd*4") -- different sound from the bDrums
))
$ every 2 ( superimpose
( (|+| gain "-0.2") -- slightly quieter
. (0.25 <~) -- delay by 1/4 cycle
. (slice 4 (fast "2" "[1 3 2 4]")) -- re-slice + rearrange
let spread1 = (spread ($) [jux rev, rev])
spread2 = spread ($) [density 2, rev, slow 2, striate 3, (# speed "0.8")]
juxrev = jux rev
revEffect = rev
palindrom = palindrome
fadeOut = range 1 0 $ slow 16 saw
in d4 $ stack [(
slow 2
$ chop 32
$ sound "piano_c"
@TCotton
TCotton / demo.hs
Last active September 19, 2025 17:19
Example of TidalCycle and as used on the YouTube demonstraton
cps (120/60/4)
-- drum patterns in do block
do
let drumz1 = every 4 (|> sound "drum")
$ sound "[drum <dr:2>] drum *2"
# gain 0.7
# orbit 0 -- routed to audiochannel 1-2
let drumz2 = sound "[drum <dr:1>] drum [drum <techno:5>] drum /2"
@TCotton
TCotton / tidalCycle-example
Created September 10, 2025 14:56
TidalCycle example
setcps (120/60/4)
-- drum patterns in do block
do
let drumz1 = every 4 (|> sound "drum")
$ sound "[drum <dr:2>] drum *2"
# gain 0.6
# orbit 0
let drumz2 = sound "[drum <dr:1>] drum [drum <techno:5>] drum /2"
@TCotton
TCotton / typescript-autocomplete.ts
Created August 19, 2025 07:26
typescript autocomplete
type AutoComplete =
| 'astring'
| 'bstring'
| 'cstring'
| (string & {})
@TCotton
TCotton / not-enum.ts
Created August 19, 2025 05:55
Better TypeScript ENUMs
const LOG_LEVEL = {
DEBUG: "DEBUG",
WARNING: "WARNING",
ERROR: "ERROR",
} as const
type ObjectValues <T> = T[keyof T];
type LogLevel = ObjectValues<typeof LOG_LEVEL>
@TCotton
TCotton / hook.js
Created May 17, 2021 10:55
Stale data invalidation
const swr = new Map;
const useSWR = (path, fetcher, cache) => {
let [data, update] = useState(null);
if (!swr.has(path) || swr.get(path) !== cache) {
fetcher(path).then(update, () => update(new Error(path)));
swr.set(path, cache);
}
const isError = data instanceof Error;
return {
@TCotton
TCotton / reduxsaga.js
Created May 17, 2021 10:49
Redux saga example
// customer
import { put, call } from 'redux-saga/effects';
const fetch = (url, data) =>
window.fetch(url, {
body: JSON.stringify(data),
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' }
@TCotton
TCotton / redux.js
Created December 8, 2020 16:17
Redux / Saga one
// customer
import { put, call } from 'redux-saga/effects';
const fetch = (url, data) =>
window.fetch(url, {
body: JSON.stringify(data),
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' }
@TCotton
TCotton / chapter_one.js
Created November 20, 2020 20:55
chapter one - react test
import React from 'react';
export const Appointment = ({customer: { firstName }}) => <div>{firstName}</div>;
import React from 'react';
import ReactDOM from 'react-dom'
import { Appointment } from '../src/Appointment';
let container;
let component;
const render = component => ReactDOM.render(component, container);
describe("Appointment", () => {