Snippets created by Kit Eason
Wimbledon special!
Tennis scoring system (at the game level). Includes some pattern-matching examples including 'when' guards.
4 people like this
Posted: 10 months ago by Kit EasonFinding matching pairs in two sequences
Here's a function which takes a comparator function and two sequences, and returns tuples consisting of an item from each sequence, where the comparator function returns true for those two items. This is a small part of my wider project to generate guitar chord shapes. One of the requirements there is to take a list of 'wanted' notes for a chord, and a list of 'available' notes within a range of frets and to combine them into an actual set of frettings. That's what led to tryFindFirstPair and hence to findPairs.
1 people like this
Posted: 9 months ago by Kit EasonHer name is Cherry; we've just met
Third cut of a guitar chord shape generator. Given a fretted instrument with a particular tuning (eg. 6 string guitar tuned EADGBE), the generator will produce the frettings necessary to play any specified chord. This is not done from a chord library, but algorithmically (hence should work with whacky tunings). This version doesn't fully respect the limitations of the human hand beyond specifying a maximum 'stretch' of a few frets, so some of the shapes generated would need a friend to help play them! This will be dealt with in a future version. This third version contains improved handling of differing tunings and instruments (eg. DADGAD; banjo) but still doesn't check for unplayable shapes.
7 people like this
Posted: 9 months ago by Kit EasonMixed number
A function to calculate 'mixed numbers' - eg. 1 1/8.
2 people like this
Posted: 5 months ago by Kit EasonBetween operators
A couple of operators for 'between, inclusive' and 'between, exclusive'.
6 people like this
Posted: 5 months ago by Kit EasonTidy up text using composed functions
Some simple functions to tidy up text and quote it, so that it's suitable to go into a CSV.
0 people like this
Posted: 5 months ago by Kit EasonTidy up text using composed functions
Some simple functions to tidy up text and quote it, so that it's suitable to go into a CSV.
1 people like this
Posted: 5 months ago by Kit EasonCalculate left margins
Take some text and work out where the left margins are, returning the most common margin settings first. Useful for processing somewhat messy text items like movie scripts. Left margins are defined by leading spaces. Tabs must be expanded before calling.
3 people like this
Posted: 4 months ago by Kit EasonFast inverse square root
This is an implementation of the famous 'magic number' method of rapidly calculating (inverse) square roots. (See http://en.wikipedia.org/wiki/Fast_inverse_square_root.) In practice, this version is no faster in F# than using 1./sqrt(x). I've posted it as an example of how you can get down-and-dirty with the bits in F# if you need to.
0 people like this
Posted: 4 months ago by Kit EasonGenerate a repeating infinite sequence
A little function which generates an infinite sequence consisting of repeats of items from some shorter sequence.
1 people like this
Posted: 3 months ago by Kit Eason
Curve difference by sum-of-squares
An operator to compare two curves by the sum-of-squares-of-differences method.
1 people like this
Posted: 3 months ago by Kit EasonDiscrete Fréchet Distance
Compute the Discrete Fréchet Distance between two arrays (which may be of different lengths). Based on the 1994 algorithm by Thomas Eiter and Heikki Mannila. Not extensively tested, so use at your peril! (This version with some small fixes.)
0 people like this
Posted: 3 months ago by Kit EasonTransform a sequence into a sequence-of-sequences
Take a sequence and make it into a sequence of sequences, where the inner sequences are of a specified length. (The last inner sequence may be shorter.) Useful, for instance, for rending sequences into two-way HTML grids.
0 people like this
Posted: 2 months ago by Kit EasonTake a sample of a sequence
Take a sample of a specified length from a sequence. The sample is guaranteed to be of the requested size (unless there are too few elements in the original sequence). Sample items will be taken at equal intervals, with possibly a shorter interval at the end if the sequence length is not evenly divisible by the sample size.
0 people like this
Posted: 2 months ago by Kit EasonHigher-Order Functions for Excel
Some of the standard higher-order functions (like Seq.map, Seq.iter, Seq.filter) but implemented for Excel interop. Effortlessly iterate across ranges of cells, reading them, updating them or formatting them. NB. Type-information won't be displayed correctly on fssnip (Office not installed on server presumably), so to get this working paste the code into VS, make yourself a spreadsheet with a range called 'MyRange' and use FSI to explore.
5 people like this
Posted: 2 months ago by Kit EasonHow many words can you spell on a calculator?
We all know about BOOBIES - but how many other dictionary words can you spell upside-down on a calculator?
2 people like this
Posted: 2 months ago by Kit EasonHow many lines of code does your project contain?
A simple way to count the non-blank, non-comment lines in your code. (Doesn't use project files to identify source; just a wildcard. Doesn't support multi-line comments.)
2 people like this
Posted: 2 months ago by Kit EasonPoll a file until it is quiet
One of the problems with using FileSystemWatcher to detect new files and process them is that it tells you when the file starts being created, not when it finishes. Use this little function to poll the file until it stops being written to.
2 people like this
Posted: 2 months ago by Kit EasonWhat word is most like the word "turtle"?
A while ago I posted a snippet to calculate the 'Discrete Fréchet Distance' between two curves. If we treat a word as a 'curve' by giving each letter an index (with similar-sounding letters having closer indices) we can compare words by the Fréchet distance between them! An alternative to edit-distance...
2 people like this
Posted: 1 months ago by Kit Eason