Skip to content

Instantly share code, notes, and snippets.

View alex-ilin's full-sized avatar
🏠
Working from home

Alexander Ilin alex-ilin

🏠
Working from home
View GitHub Profile
@alex-ilin
alex-ilin / ask.factor
Created May 24, 2017 21:43
Use GetSaveFileName to ask user for a file name (the Save As dialog)
! Copyright (C) 2017 Alexander Ilin.
USING: accessors alien alien.c-types alien.libraries
alien.syntax classes.struct destructors kernel libc math
sequences strings windows windows.types ;
IN: ask
CONSTANT: OFN_OVERWRITEPROMPT 2
STRUCT: OPENFILENAME
@alex-ilin
alex-ilin / inspector.factor
Last active June 10, 2017 20:49
Greater memory footprint due to `keys` and `map`
: first-column-width ( table model -- width )
value>> dup sequence? [
length 1 - 1array
] [
make-mirror keys
] if [ unparse-short ] map
over renderer>> column-titles first suffix
row-column-widths supremum ;
: <inspector-table> ( model -- table )
@alex-ilin
alex-ilin / inspector.factor
Last active June 9, 2017 00:12
More complicated code, but no intermediate arrays
: first-column-width ( table model -- width )
[
[ font>> dup ] keep
renderer>> column-titles first cell-dim nip +
] dip
value>> dup sequence? [
length 1 - unparse-short swapd cell-dim nip + max
] [
make-mirror [
! font prev key value

Keybase proof

I hereby claim:

  • I am alex-ilin on github.
  • I am alexilin (https://keybase.io/alexilin) on keybase.
  • I have a public key ASAnt7XgurD0YSBk1FyuVgR55Wbdqa5zQkVc1a7vOeMGPQo

To claim this, I am signing this object:

@alex-ilin
alex-ilin / ExceptionWarning.fs
Created August 16, 2022 14:41
F# Warning FS0049 when catching an exception class
type SitAction = { Rest: int }
type StandAction = { Rest: int }
type Action =
| Stand of StandAction
| Sit of SitAction
let lastStandIndex (x: Action list) : int option =
try
x |> List.tryFindIndex (function
| Stand _ -> true