Skip to content

Instantly share code, notes, and snippets.

View danbst's full-sized avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
@danbst
danbst / hask5.lhs
Last active October 2, 2015 17:08
Console Tetris
ТЕТРІС 0.0.0.12
Реалізація класичного тетріса (з урізаними можливостями), з виводом у консоль.
Урізано: відображення наступної фігури та рахунку
клавіша прискореного падіння фігури
рівні та зміна швидкостей
Код переписано багато разів, з кожним разом він ставав все кращим та кращим.
> {-# LANGUAGE TemplateHaskell #-}
@danbst
danbst / cursor.hs
Last active July 19, 2018 16:57
Netwire - console cursor moving
import Control.Wire
import Prelude hiding ((.), id)
import System.Console.ANSI
import Data.Maybe
import Control.Applicative ((<$>))
control whenInhibited whenProduced wire = loop wire clockSession
where
loop w' session' = do
(mx, w, session) <- stepSession w' session' ()
type Timer = ( Rational -- ^ start time
, Rational) -- ^ interval
createTimer :: Rational -- ^ interval
-> IO Timer
createTimer interval =
(\x -> (x, interval)) . toRational . utctDayTime <$> getCurrentTime
updateTimer :: Timer -> IO (Timer, Bool)
updateTimer (time, interval) =
@danbst
danbst / netwire-flying-word.hs
Last active December 11, 2015 23:28
Example of time and keyboard usage in netwire. Displays bouncing text and quit when 'q' pressed
{-# LANGUAGE Arrows #-}
import Control.Wire
import Prelude hiding ((.), id)
import System.Console.ANSI
import Data.Maybe
import Control.Arrow
import Control.Monad.Trans.State
import Control.Monad.Trans
import Data.Time.Clock
{-#LANGUAGE GADTs, DataKinds, KindSignatures #-}
import Data.Word
import Data.Int
import Numeric
import Data.Bits
import Data.Binary.Put (putWord32le, putWord16le, runPut)
import Data.ByteString.Lazy (unpack)
import qualified Data.ByteString as B
@danbst
danbst / gist:6044816
Last active December 20, 2015 00:49
download file with http-streams and io-streams (with progressbar)
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C8
import qualified System.IO.Streams.Combinators as SC
import Network.Socket (withSocketsDo)
import System.IO.Streams (InputStream, OutputStream, ReadTooShortException)
import Network.Http.Client
import qualified System.IO.Streams as S
import Data.Maybe
import Control.Exception (bracket)
@danbst
danbst / gist:6129341
Created August 1, 2013 07:58
List USB devices' configurations in human readable format (similar to ls-usb)
{-# LANGUAGE ScopedTypeVariables #-}
import System.USB
import Control.Monad (forM_, when)
import Data.Vector (toList, Vector)
import Control.Exception
import Text.PrettyPrint
import Control.Arrow hiding ((<+>))
import qualified Data.ByteString as BS
import Numeric
@danbst
danbst / gist:6404568
Created September 1, 2013 13:46
configuration.nix
# the system. Help is available in the configuration.nix(5) man page
# or the NixOS manual available on virtual console 8 (Alt+F8).
{ config, pkgs, ... }:
{
require =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
@danbst
danbst / byteStringStream.hs
Created October 14, 2013 23:15
Based upon http://www.reddit.com/r/haskell/comments/1o4m98/feedback_wanted_trying_to_write_a_good_receive/ Task is: read one line from a stream of ByteString chars. Done with explicit recursion and pipes (and with their ByteString.Builder versions). Included Criterion benchmarks.
import qualified Data.ByteString.Char8 as B
import Criterion.Main
import Data.IORef
import Data.Vector
import Data.ByteString.Char8 (ByteString)
import Control.Monad (forever)
import Pipes
import qualified Pipes.Prelude as P
import Data.Char (intToDigit)
import qualified Data.ByteString.Builder as Builder
@danbst
danbst / sustain-vim.hs
Created October 24, 2013 21:38
Generate keypresses with my Synth's sustain pedal. Requires `xdotool` in %PATH%
import System.USB
( InterfaceDesc(interfaceEndpoints, interfaceNumber),
EndpointDesc(endpointAddress),
DeviceDesc(deviceProductId, deviceVendorId),
Device,
Ctx,
ConfigDesc(configInterfaces),
withDeviceHandle,
withDetachedKernelDriver,
withClaimedInterface,