Skip to content

Instantly share code, notes, and snippets.

View supki's full-sized avatar
🇸🇴
🤝 🏳️‍🌈

Matvey Aksenov supki

🇸🇴
🤝 🏳️‍🌈
  • Gorgoroth, Mordor
  • 14:25 (UTC)
View GitHub Profile
doWork :: IO ()
doWork = do
forkIO sender
forkIO receiver
worker
where
receiver = scrobbler $
announce . rmap (Successes :: [Track] -> Successes Track) deserialize . receive (PortNumber 7447)
sender = scrobbler $
send "localhost" (PortNumber 4774) . serialize . candidate
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package nats-0.1 ... linking ... done.
Loading package semigroups-0.9 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package comonad-3.0.2 ... linking ... done.
-- | Look for player state changes over time
candidate :: Wire Error Y.MPD Int64 Change
candidate = mkStateM NotPlaying $ \_dt (t, s) ->
Y.stState `fmap` Y.status >>= \s' -> case (s, s') of
-- If we were not playing and are not playing now there is no candidate to send
(NotPlaying, Y.Stopped) -> return (Left NoCandidate, NotPlaying)
(NotPlaying, Y.Paused) -> return (Left NoCandidate, NotPlaying)
-- If we started playing just now there is a candidate to send
(NotPlaying, Y.Playing) -> do
Just song <- Y.currentSong
@supki
supki / pemis.rb
Last active December 17, 2015 01:19
WAT
#!/usr/bin/env ruby
class C
def initialize
@x = 0
end
def f xs
if @x < 10
xs << @x
[][0]
# => nil
[][0,0]
# => []
[][1]
# => nil
[][1,0]
# ==> nil
@supki
supki / pemis.rb
Created April 16, 2013 14:35
WAT
unless true
x = 4
end
p x
p y
@supki
supki / pemis.hs
Last active December 16, 2015 05:59
M
instance (Enum a, Num a) => Num [a] where
(*) = liftA2 (*)
fromInteger n = [1..fromInteger n]
instance (Enum a, Real a) => Real [a] where
instance Enum [a] where
instance Integral a => Integral [a] where
mod = liftA2 mod
@supki
supki / pemis.rb
Created April 11, 2013 18:59
Wat
class C
private
def m
:private
end
end
> c = C.new
> c.public_send :send, :m
==> :private
@supki
supki / pemis.rb
Last active December 16, 2015 01:19
ncurses-based list
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'curses'
# Prepare curses and cleanup after application is finished
def with_curses
Curses.noecho # Do not print input keys
Curses.curs_set 0 # Remove cursor
Curses.init_screen
@supki
supki / pemi.rb
Last active December 15, 2015 22:19
M
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
vpn_name = "pemi"
Object.send :define_method, :status do |&block|
if system "/etc/init.d/openvpn.#{vpn_name} status > /dev/null"
block[:green, "OK"]
else