This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class C | |
def initialize | |
@x = 0 | |
end | |
def f xs | |
if @x < 10 | |
xs << @x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[][0] | |
# => nil | |
[][0,0] | |
# => [] | |
[][1] | |
# => nil | |
[][1,0] | |
# ==> nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless true | |
x = 4 | |
end | |
p x | |
p y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C | |
private | |
def m | |
:private | |
end | |
end | |
> c = C.new | |
> c.public_send :send, :m | |
==> :private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |