Skip to content

Instantly share code, notes, and snippets.

Avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
@danbst
danbst / hask5.lhs
Last active Oct 2, 2015
Console Tetris
View hask5.lhs
ТЕТРІС 0.0.0.12
Реалізація класичного тетріса (з урізаними можливостями), з виводом у консоль.
Урізано: відображення наступної фігури та рахунку
клавіша прискореного падіння фігури
рівні та зміна швидкостей
Код переписано багато разів, з кожним разом він ставав все кращим та кращим.
> {-# LANGUAGE TemplateHaskell #-}
@danbst
danbst / cursor.hs
Last active Jul 19, 2018
Netwire - console cursor moving
View cursor.hs
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' ()
View tetris-core.hs
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 Dec 11, 2015
Example of time and keyboard usage in netwire. Displays bouncing text and quit when 'q' pressed
View netwire-flying-word.hs
{-# 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
View hasm-revised-addressmode.hs
{-#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 Dec 20, 2015
download file with http-streams and io-streams (with progressbar)
View gist:6044816
{-# 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 Aug 1, 2013
List USB devices' configurations in human readable format (similar to ls-usb)
View gist:6129341
{-# 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 Sep 1, 2013
configuration.nix
View gist:6404568
# 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 Oct 14, 2013
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.
View byteStringStream.hs
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 Oct 24, 2013
Generate keypresses with my Synth's sustain pedal. Requires `xdotool` in %PATH%
View sustain-vim.hs
import System.USB
( InterfaceDesc(interfaceEndpoints, interfaceNumber),
EndpointDesc(endpointAddress),
DeviceDesc(deviceProductId, deviceVendorId),
Device,
Ctx,
ConfigDesc(configInterfaces),
withDeviceHandle,
withDetachedKernelDriver,
withClaimedInterface,