Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tmck-code/tmck-code.github.io
Browse files Browse the repository at this point in the history
  • Loading branch information
tmck-code committed Dec 10, 2024
2 parents 13adba9 + 9845b7e commit 2ebeef8
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 32 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ my blog

---

### [20241128 Comparing Lists or Matrices](articles/20241128_comparing_lists_or_matrices/20241128_comparing_lists_or_matrices.md)

> _Functional approaches to compare sequences in Python_
### [20240829 Using JQ with style](articles/20240829_using_jq_with_style/20240829_using_jq_with_style.md)

> _Colour/theme configuration for jq_
Expand Down
49 changes: 31 additions & 18 deletions articles/20220718-csgo-surf/20220718-csgo-surf.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,47 @@ I load this file when playing surf on public online servers (e.g. [Surf Heaven A

> _see [my toggle keybind article](../20240126_cs_surf_-_toggle_all_saveloc_keybinds/20240126_cs_surf_-_toggle_all_saveloc_keybinds.md) for an explanation of how the CFG toggle keybind works!_
- `_surf_online.cfg_`
- _`surf_online.cfg`_
```java
// macros ---------------------------------------

// saveloc (bind by default)
exec surf_saveloc_on.cfg;
alias saveloc_on "exec surf_saveloc_on.cfg; alias saveloc_toggle saveloc_off";
alias saveloc_off "exec surf_saveloc_off.cfg; alias saveloc_toggle saveloc_on";
alias saveloc_toggle "saveloc_off";

// hud visibility (on by default)
alias hud_off "cl_draw_only_deathnotices 1; alias hud_toggle hud_on";
alias hud_on "cl_draw_only_deathnotices 0; alias hud_toggle hud_off";
alias hud_toggle "hud_off"

// keybinds -------------------------------------

// turnbinds
bind mouse1 +left; // turn left with left mouse click
bind mouse2 +right; // turn right with right mouse click

// stage teleports
bind t "say !r"; // teleport to start of map
bind u "say !rs"; // teleport to start of stage
bind t "say !rs"; // teleport to start of map
bind z "say !r"; // teleport to start of stage

// saveloc (bind by default)
exec surf_saveloc_on.cfg;
alias saveloc_on "alias saveloc saveloc_off; exec surf_saveloc_on.cfg";
alias saveloc_off "alias saveloc saveloc_on; exec surf_saveloc_off.cfg";
alias saveloc "saveloc_off";
// toggle saveloc
bind . "saveloc";

alias "hud_toggle" "hud_off"
alias "hud_off" "cl_draw_only_deathnotices 1; alias hud_toggle hud_on";
alias "hud_on" "cl_draw_only_deathnotices 0; alias hud_toggle hud_off";
bind l "hud_toggle"
// toggles
bind . "saveloc_toggle"; // toggle saveloc
bind l "hud_toggle" // toggle hud visibility

// info/debug commands
bind 5 "say !tier" // show current map info
bind 6 "say !pb" // show personal best time

// map voting
bind , "say !nominate" // nominate next map
bind h "say /rtv" // trigger vote for next map

// force window to 1440p resolution
mat_setvideomode 2560 1440 1
```
- `_surf_saveloc_on.cfg_`
- _`surf_saveloc_on.cfg`_
```java
// This file contains all SurfTimer saveloc keybinds

Expand All @@ -79,7 +92,7 @@ I load this file when playing surf on public online servers (e.g. [Surf Heaven A

say "saveloc enabled";
```
- `_surf_saveloc_off.cfg_`
- _`surf_saveloc_off.cfg`_
```java
// This file _disables_ all SurfTimer saveloc keybinds

Expand All @@ -97,4 +110,4 @@ I load this file when playing surf on public online servers (e.g. [Surf Heaven A
unbind s;

say "saveloc disabled";
```
```
41 changes: 27 additions & 14 deletions articles/20220718-csgo-surf/surf_online.cfg
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
// macros ---------------------------------------

// saveloc (bind by default)
exec surf_saveloc_on.cfg;
alias saveloc_on "exec surf_saveloc_on.cfg; alias saveloc_toggle saveloc_off";
alias saveloc_off "exec surf_saveloc_off.cfg; alias saveloc_toggle saveloc_on";
alias saveloc_toggle "saveloc_off";

// hud visibility (on by default)
alias hud_off "cl_draw_only_deathnotices 1; alias hud_toggle hud_on";
alias hud_on "cl_draw_only_deathnotices 0; alias hud_toggle hud_off";
alias hud_toggle "hud_off"

// keybinds -------------------------------------

// turnbinds
bind mouse1 +left; // turn left with left mouse click
bind mouse2 +right; // turn right with right mouse click

// stage teleports
bind t "say !r"; // teleport to start of map
bind u "say !rs"; // teleport to start of stage
bind t "say !rs"; // teleport to start of map
bind z "say !r"; // teleport to start of stage

// saveloc (bind by default)
exec surf_saveloc_on.cfg;
alias saveloc_on "alias saveloc saveloc_off; exec surf_saveloc_on.cfg";
alias saveloc_off "alias saveloc saveloc_on; exec surf_saveloc_off.cfg";
alias saveloc "saveloc_off";
// toggle saveloc
bind . "saveloc";

alias "hud_toggle" "hud_off"
alias "hud_off" "cl_draw_only_deathnotices 1; alias hud_toggle hud_on";
alias "hud_on" "cl_draw_only_deathnotices 0; alias hud_toggle hud_off";
bind l "hud_toggle"
// toggles
bind . "saveloc_toggle"; // toggle saveloc
bind l "hud_toggle" // toggle hud visibility

// info/debug commands
bind 5 "say !tier" // show current map info
bind 6 "say !pb" // show personal best time

// map voting
bind , "say !nominate" // nominate next map
bind h "say /rtv" // trigger vote for next map

// force window to 1440p resolution
mat_setvideomode 2560 1440 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 20241128 Comparing Lists or Matrices

Recently I needed to compare matrices (or "lists of lists"), counting the number of different items. I challenged myself to
use the standard library instead of numpy.

---

These matrices have 2 differing values:

```python
m1 = [(0,0),
(0,1),]

m2 = [(0,1),
(0,0),]
```

Firstly, it would be easiest (for me) if I somehow transformed each matrix into a single sneuence of numbers.
This can be done using `chain` from the `itertools` standard library tools, which is one of my favourite and probably overused hacks.

```python
from itertools import chain

list(chain.from_iterable(m1))
# [0, 0, 0, 1]

list(chain.from_iterable(m2))
# [0, 1, 0, 0]
```

Using `zip`, we can iterate through both lists and compare each pair of elements:

```python
list(zip(
chain.from_iterable(m1),
chain.from_iterable(m2)
))
# [(0, 0), (0, 1), (0, 0), (1, 0)]
```

Next, we need to compare each pair of elements, and I thought of using the `operator` functions, as there is `ne` which could be used to compare elements.

The documentation for `ne` is:

> `ne(a, b, /)` *Same as a != b.*
I want to avoid using a lambda as it is both icky and slow, e.g.

```python
list(map(
lambda x: x[0]==x[1],
zip(
chain.from_iterable(m1),
chain.from_iterable(m2)
)
))
# [True, False, True, False]
```

I can use `starmap` to take each pair, and pass it to `operator.eq` as `*args` (hence the name "starmap"! very cool 😎)

```python
from itertools import starmap

list(starmap(
operator.ne,
zip(
chain.from_iterable(m1),
chain.from_iterable(m2)
)
))
# [True, False, True, False]
```

And finally, `sum` can be used to count the number of `True`/truthy results

```python
sum(starmap(
operator.ne,
zip(
chain.from_iterable(m1),
chain.from_iterable(m2)
)
))
# 2
```

> *Note: counting identical elements could be done easily by using `operator.eq` instead of `operator.ne`*

0 comments on commit 2ebeef8

Please sign in to comment.