Skip to content

Instantly share code, notes, and snippets.

Avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
View mapM_unpack.hs
Main.mapM_Unpack (f :: Word8 -> m ()) (PS payload rb1_a1Tf offset length) ->
let {
>> :: m () -> m () -> m ()
>> = GHC.Base.>> @ m $dMonad_a1E5 @ () @ () }
in
letrec {
loop :: Addr# -> Int# -> m () -> GHC.Prim.State# GHC.Prim.RealWorld -> (# GHC.Prim.State# GHC.Prim.RealWorld, m () #)
loop addr index default_m world ->
case index of
(-1) -> (# world, default_m #)
View mapM_indexed_reverse.hs
Main.mapM_IndexReverse = (f :: GHC.Word.Word8 -> m ()) (PS payload rb1_a1UY offset length) ->
let return :: m ()
return = GHC.Base.return @ m $dMonad_a1Dq @ () GHC.Tuple.()
>> :: m () -> m () -> m ()
>> = GHC.Base.>> @ m $dMonad_a1Dq @ () @ ()
in
letrec {
loop :: Int# -> m ()
loop index ->
case index of
@danbst
danbst / brainfuck.hs
Last active Aug 29, 2015
Simple BF interpreter in 38 lines - check http://ideone.com/aLrtPu for online test
View brainfuck.hs
{-# LANGUAGE MultiWayIf, BangPatterns #-}
import Data.Word
import Data.Char
data Tape = Tape { negatives :: [Word8], currentTape :: !Word8, positives :: [Word8] }
mkTape = Tape (repeat 0) 0 (repeat 0)
shiftLeft (Tape (x:left) curr right) = Tape left x (curr:right)
shiftRight (Tape left curr (x:right)) = Tape (curr:left) x right
View gist:470f7e23a14cab4e6e3e
module OpenGLUtils where
import Data.ByteString ( ByteString(..) )
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BSU
import Graphics.UI.GLUT
import Graphics.Rendering.OpenGL (($=))
import qualified Graphics.Rendering.OpenGL as GL
import qualified Codec.BMP as BMP
import Foreign.ForeignPtr
@danbst
danbst / alex-monad-template.x
Last active Aug 29, 2015
Template file for monadic Alex lexer. Inclues better error message, basic token type and lexer
View alex-monad-template.x
{
module AlexMonadicTemplate (main) where
}
%wrapper "monad"
tokens :-
<0> . { mkL LDummy }
<0> $white ;
{
@danbst
danbst / curl-in-mingw.sh
Created Feb 18, 2015
How to curl in MinGW without curl
View curl-in-mingw.sh
#!/bin/bash
function curlMingw {
local address="$1"
perl -e "use LWP::UserAgent;" -e "my \$ua = LWP::UserAgent->new;" -e "my \$req = HTTP::Request->new(GET => \"$address\");" -e "my \$resp = \$ua->request(\$req);" -e "print \$resp->decoded_content;"
}
@danbst
danbst / python-qscintilla.nix
Created Jul 19, 2015
Attempt to package python-qscintilla
View python-qscintilla.nix
qscintilla-qt4 = stdenv.mkDerivation rec {
name = "qscintilla-qt4-${version}";
version = pkgs.qscintilla.version;
disabled = isPy3k || isPyPy;
src = pkgs.qscintilla.src;
buildInputs = [ pkgs.python ];
propagatedBuildInputs = [ pkgs.pyqt4 pkgs.qscintilla pkgs.qt4 ];
@danbst
danbst / hask5.lhs
Last active Oct 2, 2015
Console Tetris
View hask5.lhs
ТЕТРІС 0.0.0.12
Реалізація класичного тетріса (з урізаними можливостями), з виводом у консоль.
Урізано: відображення наступної фігури та рахунку
клавіша прискореного падіння фігури
рівні та зміна швидкостей
Код переписано багато разів, з кожним разом він ставав все кращим та кращим.
> {-# LANGUAGE TemplateHaskell #-}
View bothclicks.cpp
#include <iostream>
#include <string>
#include <utility>
#include <conio.h>
#include <chrono>
#include <thread>
#include "react/Domain.h"
#include "react/Event.h"
#include "react/Observer.h"
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) =