-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.html
274 lines (274 loc) · 13.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!--
TODO
- testing React perfomance with and without global state (and with immer) and with Recoil. Test with 1000s of x, y coordinate boxes
- can your type system do this? TypeScript
- ORM critiques, SQLAlchemy and preventing magic objects leaking out + can your ORM do this?
- typed lambda calculus
- ask someone about where 1 + 1 = 2 is a proof - https://math.stackexchange.com/questions/4410936/does-a-particular-statement-in-lambda-calculus-count-as-a-proof
-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>leontrolski - index</title>
<style>
body {margin: 5% auto; background: #fff7f7; color: #444444; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.8; max-width: 63%;}
@media screen and (max-width: 800px) {body {font-size: 14px; line-height: 1.6rem; max-width: 90%;}}
code {background: #f0f0f0;}
a {border-bottom: 1px solid #444444; color: #444444; text-decoration: none;}
a:hover {border-bottom: 0;}
</style>
<link rel="alternate" type="application/rss+xml" title="Subscribe to Leon Trolski" href="https://leontrolski.github.io/leontrolski.rss"/>
</head>
<body>
<a><img style="height:2em" src="pic.png"/></a>
<p>
I'm <b>Oliver Russell</b>, a Python dev (amongst other things) based in London, reach me at ojhrussell[at]gmail.com, subscribe via <a href="https://leontrolski.github.io/leontrolski.rss">rss</a>, read my <a href="oliver-russell-cv.pdf">CV</a>.
</p>
<br>
<p>
✨ New! ✨
<ul>
<li>Stop using <a href="fixtures.html">pytest fixtures</a></li>
<li><a href="grammar.html">Changing and compiling</a> the cpython interpreter</li>
<li>Fast and simple <a href="https://github.com/leontrolski/ocdiff">side-by-side diffs</a> for Python</li>
<li><a href="pglockpy.html">Postgres locks explorer</a></li>
</ul>
</p>
<br>
<div>
<div><code><a href="#database-tips">Database tips</a></code></div>
<div><code><a href="#minimal-versions">Minimal versions</a></code></div>
<div><code><a href="#cs-essentials">Computer science essentials</a></code></div>
<div><code><a href="#stop">Stop doing things</a></code></div>
<div><code><a href="#high-level">High level programming thoughts</a></code></div>
<div><code><a href="#coding-bits-and-bobs">Python/Javscript bits and bobs</a></code></div>
<div><code><a href="#what-ifs">What ifs</a></code></div>
<div><code><a href="#cycling">Cycling</a></code></div>
<div><code><a href="#other">Other</a></code></div>
<div><code><a href="#gists">Github gists/stars</a></code></div>
<div><code><a href="#projects">Github projects</a></code></div>
<div><code><a href="#game">Blocks game</a></code></div>
</div>
<br>
<p id="database-tips">
Handy <b>database tips</b>. <em>According to Google, these are way more interesting than anything else here</em>.
<ul>
<li>SQLAlchemy relationship loading techniques with examples <a href="sqlalchemy-relationships.html">for v1</a>, <a href="sqlalchemy-relationships-2.html">for v2</a></li>
<li>Everyone should use <a href="postgres-advisory-locks.html">Postgres advisory locks</a>!</li>
<li>Most of the time, you can use <a href="postgres-as-queue.html">Postgres as a queue</a></li>
<li>Don't get bitten by missing <a href="foreign-key-indexes.html">foreign key indexes</a></li>
<li>Postgres <a href="pglockpy.html">locks explorer</a></li>
<li><a href="unorder.html">Weeding</a> out flakey database tests</li>
</ul>
</p>
<br>
<p id="minimal-versions">
A series of posts where I reimplement a <b>minimal version</b> of something to demonstrate how it works.
<ul>
<li><a href="33-line-react.html">33 line React</a>-like library, and <a href="33-line-react-thoughts.html">followup</a>, also a <a href="96-line-react-jsx.html">96 line React with JSX</a></li>
<li>Use TSX whilst <a href="no-npm.html">avoiding npm hell</a> on small projects</li>
<li>Ever wondered what the hell is going on with your <code>pandas.DataFrame</code>, check <a href="fake-data-frame.html">this</a> out</li>
</ul>
</p>
<br>
<p id="cs-essentials">
Weenie posts reducing some <b>computer science</b> concept down to its essentials. <em>There are many different takes on these topics scattered across the internet.</em>
<ul>
<li>Tips for tricky <a href="leet.html">leet code</a> style questions in interviews</li>
<li>What does <a href="covariance.html">covariant</a> mean?</li>
<li>Sudoku <a href="constraint-sudoku.html">solving</a> using a custom backtracking constraint solver</li>
<li><a href="lambda-calculus.html">Lambda calculus</a> in modern JavaScript</li>
<li>Reach OO/closure <a href="poor-mans-object.html">nirvana</a></li>
<li>Weenie <a href="weenie-lisp.html">LISP</a> parser</li>
<li>Then a smol <a href="pratt-example.html">Pratt parser</a></li>
</ul>
</p>
<br>
<p id="stop">
<b>Stop</b> doing things.
<ul>
<li><a href="cmd-click-manifesto.html">The CMD-click manifesto</a></li>
<li>Stop doing <a href="mostly-pointless.html">OO so much</a></li>
<li>Stop using <a href="sane-config.html">mad config</a></li>
<li>Stop using <a href="fixtures.html">pytest fixtures</a></li>
</ul>
</p>
<br>
<p id="high-level">
<b>High level</b> thoughts on professional programming.
<ul>
<li>Monolith? Microservices? <a href="manipleservices.html">Manipleservices</a></li>
<li>Test categorisation <a href="test-zen.html">Zen</a></li>
</ul>
</p>
<br>
<p id="coding-bits-and-bobs">
<b>Python/JavaScript/TypeScript</b> and bobs.
<ul>
<li>UpSet plots are <a href="upset.html">useful</a></li>
<li>Using <a href="typeis.html">TypeIs</a> in Python</li>
<li>mypyc is <a href="mypyc-quick.html">quick</a></li>
<li>Useful <a href="pytest-helpful.html">pytest</a> plugins</li>
<li><a href="strongly-typed-http.html">Strongly type</a> your Web 1.0 interfaces</li>
<li>Python <a href="virtualenvs-for-node-devs.html">virtualenvs</a> for Node devs</li>
<li>A <a href="recursing-with-yield.html">tiny</a> bit about recursing with the yield statement</li>
<li>I can never remember how to <a href="git-bisect.html">git bisect</a>, or <a href="git-rebase-diff.html">git diff after a rebase</a></li>
<li><a href="semi-isomorphic.html">Evolving</a> backend → frontend rendered Python/JS apps with dnjs</li>
<li><a href="grammar.html">Changing and compiling</a> the cpython interpreter</li>
</ul>
</p>
<br>
<p id="what-ifs">
<b>What-ifs</b>.
<ul>
<li>What if we'd had <a href="dom-syntax.html">nice html-in-js syntax</a> from the beginning?</li>
<li>Can we add syntax to <a href="alter.html">contain mutations</a></li>
<li><a href="contrair-articles.html">Contrair articles</a> countering certain premises</li>
<li>A piece about potential <a href="nested-sql.html">nested SQL queries</a></li>
</ul>
</p>
<br>
<p id="cycling">
<b>Cycling</b>.
<ul>
<li><a href="cycling-in-london.html">Guide for n00bs</a> cycling in London</li>
<li><a href="cycling.html">Day trips</a> from Central London</li>
<li><a href="rail-map.html">Rail travel times</a> from Central London</li>
<li><a href="swimming.html">Wild swimming</a> from Central London</li>
</ul>
</p>
<br>
<p id="other">
<b>Other junk</b>.
<ul>
<li>I played some <a href="https://www.youtube.com/watch?v=bAYo9wrLYN8">double bass</a></li>
<li><a href="consciousness.html">Summary</a> of the book "Consciousness and the Social Brain"</li>
<li>Karl Popper essay - <a href="popper-reality.html">Ideal and reality in society</a></li>
<li>Check out my weird <a href="https://soundcloud.com/leontrolski">music</a></li>
<li>My <a href="thermostat.html">dream thermostat</a></li>
</ul>
</p>
<br>
<p id="gists">
<b>Github gists/stars</b>.
<ul>
<li>Random <a href="https://gist.github.com/leontrolski">gists</a></li>
<li>Useful <a href="my-stars.html">stars</a></li>
</ul>
</p>
<br>
<p id="projects">
Here are some of my <b>projects</b>, none of them are particularly prod-ready, just things that have scratched various itches over the years.
<ul>
<li><a href="https://stepping.site">stepping</a> - incremental view maintenance for application developers</li>
<li><a href="https://github.com/leontrolski/ocdiff">ocdiff</a> - fast and simple side-by-side diffs for Python</li>
<li><a href="https://github.com/leontrolski/pgtestdbpy">pgtestdbpy</a> - use Postgres TEMPLATE dbs in tests</li>
<li><a href="https://github.com/leontrolski/isjsonschemasubset">isjsonschemasubset</a> - does what it says on the tin</li>
<li><a href="https://github.com/leontrolski/sqlski">sqlski</a> - Postgres-side nesting of data for Python</li>
<li><a href="https://github.com/leontrolski/dnjs">dnjs</a> - a Python interpreter for a useful subset of JS</li>
<li><a href="https://github.com/leontrolski/immerframe">immerframe</a> - a neat way to make deep immutable changes in Python with structural sharing</li>
<li><a href="https://github.com/leontrolski/towpath">towpath</a> - a js library using proxies to attach paths to values in a nested structure</li>
<li><a href="https://github.com/leontrolski/dawdle">dawdle</a> - a very half-baked DSL showing how a neat relational language <em>could</em> look like</li>
<li><a href="https://github.com/leontrolski/fussball">fussball</a> - a Bayesian-ly founded table-football scoreboard (would work for ping-pong too)</li>
</ul>
</p>
<br>
<br>
<p id="game">Below is a minimalist blocks game, see the page source to see how it works!</p>
<div id="blocks"></div>
<style>
.row {display: flex;}
.block {width:100px;height:50px;float:left;background-color:red;}
</style>
<script src="33-line-react.js"></script>
<script>
var width = 8
var height = 8
var possibleColours = ['b', 'y', 'r', 'g']
var colourMap = {
b: 'blue',
y: 'yellow',
r: 'red',
g: 'green',
e: 'gray', // empty
}
var emptyCell = {colour: 'e', isEmpty: true}
function randomCell(){
return {
colour: possibleColours[Math.floor(Math.random() * possibleColours.length)],
isEmpty: false,
}
}
// state
var grid = [...Array(height)].map(_=>[...Array(width)].map(randomCell))
var numberOfClicks = 0
// grid->grid functions
function doUntilIdempotent(grid, f){
var repeat = 0
while (repeat < 1000){ // arbitrarily large
var newGrid = f(grid)
if(JSON.stringify(newGrid) === JSON.stringify(grid)) return grid
grid = newGrid
repeat += 1
}
throw 'grid never converges'
}
function forCells(grid, f){
return grid.map((row, i)=>row.map(
(cell, j)=>Object.assign({}, cell, f(cell, i, j))))
}
function removeCell(grid, emptyI, emptyJ){
return forCells(grid, (cell, i, j)=>(
i === emptyI && j === emptyJ? {isEmpty: true} : {}))
}
function adjacentCells(grid, i, j){
var adjacents = []
if(i < grid.length - 1) adjacents.push(grid[i+1][j])
if(i > 0) adjacents.push(grid[i-1][j])
if(j < grid[0].length - 1) adjacents.push(grid[i][j+1])
if(j > 0) adjacents.push(grid[i][j-1])
return adjacents
}
function emptyAdjacentCells(grid){
return forCells(grid, (cell, i, j)=>({
isEmpty: cell.isEmpty || adjacentCells(grid, i, j).some(
adjacent=>adjacent.isEmpty && adjacent.colour === cell.colour)
}))
}
function belowCell(grid, i, j){
return i === grid.length - 1? {isEmpty: false} : grid[i+1][j]
}
function aboveCell(grid, i, j){
return i === 0? emptyCell : grid[i-1][j]
}
function shiftIntoEmpty(grid){
return forCells(grid, (cell, i, j)=>{
if(cell.isEmpty) return aboveCell(grid, i, j)
if(belowCell(grid, i, j).isEmpty) return emptyCell
return cell
})
}
var chain = (...fs)=>fs.reduce((a,b)=>x=>b(a(x)))
// mutates state
function setGrid(emptyI, emptyJ){
numberOfClicks += 1
grid = chain(
grid=>removeCell(grid, emptyI, emptyJ),
grid=>doUntilIdempotent(grid, emptyAdjacentCells),
grid=>doUntilIdempotent(grid, shiftIntoEmpty),
)(grid)
render()
}
// UI
var View = ()=>m('',
m('h1', `clicks: ${numberOfClicks}`),
grid.every(row=>row.every(cell=>cell.isEmpty)) // game over?
? m('marquee', m('h1', 'congrats!'))
: grid.map((row, i)=>m('.row', row.map((cell, j)=>
m('.block', {
style: `background-color: ${colourMap[cell.colour]};`,
onclick: cell.isEmpty? _=>_ : _=>setGrid(i, j)
})))))
render = ()=>m.render(document.getElementById('blocks'), {children: [View()]})
render()
</script>
</body>