Skip to content

Instantly share code, notes, and snippets.

View kashmervil's full-sized avatar

Aleksandr Kirsanov kashmervil

  • JetBrains
  • Amsterdam
View GitHub Profile
data Eval a
instance Monad Eval
runEval :: Eval a -> a
rpar :: a -> Eval a
rseq :: a -> Eval a
type Strategy a = a -> Eval a
rseq :: Strategy a
rpar :: Strategy a
r0 :: Strategy a
r0 x = return x
rdeepseq :: NFData a = > Strategy a
rdeepseq x = rseq ( deep x )
@kashmervil
kashmervil / debianSnippet.fs
Last active December 19, 2015 23:59
just a scratch for processing strings in file
open System
open System.IO
open Mono.Unix
open System.Reactive
open System.Reactive.Linq
open System.Reactive.Subjects
let Filestream = new Mono.Unix.StdioFileStream("/home/alex/testFile",FileAccess.Read)
//testFile is output for 'history' command in Shell
@kashmervil
kashmervil / dict.pl
Last active December 26, 2015 11:29
#!/usr/bin/perl
$counter = 0;
$max_sub = "";
while (<>) {
next if length $_ <= $counter + 1;
chomp;
my $tmp_str = substr $_, 0, $counter;
for $letter (split //,(substr $_, $counter, -1)) {
$tmp_str = $tmp_str . $letter;
module Program
open System
open System.Collections.Generic
open System.Reactive.Linq
open Trik
let log s = printfn "%s" s
type Distance = Far | Middle | Near
let resolve_rule name pat body =
let to_id (`PArg pn) = pn in
let filtered_pat = List.filter is_PArg pat in
if (List.length pat) = (List.length filtered_pat)
then `FRule (name >$ (List.map to_id filtered_pat) >= body)
else `DPGRule (name, [`PCtr ("AllArgs", pat)], body)
let button = new Button("/dev/input/event0")
let isUpPressed = ref false // Или любая интересующая кнопка
button.ToObservable().Add((:=) isUpPressed << (=) (ButtonEventCode.Up, true))
let event = new Event<int>()
let evp = event.Publish
let rand() = System.Random().Next(100)
evp.Add(printfn "event raised with %d")
let rec loop() = async {
event.Trigger <| rand()
System.Threading.Thread.Sleep(3000)
printfn "Thread number %A" System.Threading.Thread.CurrentThread.ManagedThreadId
return! loop()
}
open System.Windows.Forms
open System.Reactive.Linq
let form = new Form(TopMost = true, Visible = true, Text = "Priv")
let event = form.MouseMove
event|> Observable.filter (fun x -> (x.X > 100) && (x.Y > 100))
|> Observable.add (fun x -> printfn "x = %d y = %d" x.X x.Y)
Application.Run(form)
open System
[<RequireQualifiedAccessAttribute>]
module Observable =
let Create(subscription) = { new IObservable<'T> with
member x.Subscribe observer = subscription observer}
let DistinctUntilChanged(sequence: IObservable<'T> when 'T: comparison) =
let prev = ref None