Skip to content

Instantly share code, notes, and snippets.

@pmwhite
pmwhite / KeyWatchTextBox.cs
Created May 20, 2015 19:27
A textbox that fires an event whenever a specified key is pressed.
using System;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
class KeyWatchTextBox : TextBox
{
public event EventHandler WatchKeyPressed;
[<CompiledName("Scan")>]
let scan<'T,'State> f (z:'State) (source : seq<'T>) =
checkNonNull "source" source
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
seq { let zref = ref z
yield !zref
use ie = source.GetEnumerator()
while ie.MoveNext() do
zref := f.Invoke(!zref, ie.Current)
yield !zref }
@pmwhite
pmwhite / HalfBakedGenericDataStructure.idr
Last active November 22, 2015 20:14
An attempt to make a combination between an extensible record and extensible union types with idris.
module Main
import Data.Vect
-- I'm modelling this after Edwin Brady's extensible records snippet - http://lpaste.net/104020
-- I tried to make a corresponding extensible union type.
-- It ended up morphing into a type that has a parameter that specifies how many
-- fields can be filled. In my head, this type should consume (subsume?) both
-- types.
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
using System.Threading;
namespace Air1SongTracker
{
struct Item
#include <vector>
struct SensorRange {
int first;
int last;
}
// Find the first and the last sensors that see something
SensorRange activeSensorRange(vector<bool> sensorData) {
@pmwhite
pmwhite / macaulay.cpp
Last active May 29, 2017 16:56
Macaulay something
#include <iostream>
using namespace std;
class Pascal {
public:
int row;
int column;
int value;
Pascal(int v, int r, int c) : value(v), row(r), column(c) { }
@pmwhite
pmwhite / fsfuncs.md
Created July 21, 2017 18:10
How F# functions work

How F# functions work.

Functions in functional programming take some time to get used to, but I want to try to simplify it a little.

Expressions

In functional programming, nearly everything is an expression. Although you must eventually do something, generally you should try to isolate those parts by themselves.

In a language like Java, if is a statement:

@pmwhite
pmwhite / curry.js
Created July 22, 2017 01:30
javascript curryiing
function plus(x) {
return function(y) {
return x + y;
};
}
addFive = plus(5);
addFive(4); // 9
addFive(3); // 8
@pmwhite
pmwhite / configuration.nix
Created January 31, 2018 19:46
NixOS configuration
{ config, pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = "mordor"; # Define your hostname.
@pmwhite
pmwhite / glob.txt
Created January 31, 2018 20:11
Why is normal vim here?
/home/philip λ>readlink -f $(which vim)
/nix/store/qi7n9xamd2gw2hzq5z3izj7mxskqylyy-vim-8.0.1150/bin/vim
/home/philip λ>readlink -f $(which test-vim)
/nix/store/sdzmghl3rjl51kc2vc2a7jw0n0kafqd0-test-vim/bin/test-vim
/home/philip λ>nix-env -e vim
/home/philip λ>readlink -f $(which vim)
/nix/store/qi7n9xamd2gw2hzq5z3izj7mxskqylyy-vim-8.0.1150/bin/vim
/home/philip λ>