Skip to content

Instantly share code, notes, and snippets.

View danbst's full-sized avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
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 #)
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 August 29, 2015 14:00
Simple BF interpreter in 38 lines - check http://ideone.com/aLrtPu for online test
{-# 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
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 August 29, 2015 14:03
Template file for monadic Alex lexer. Inclues better error message, basic token type and lexer
{
module AlexMonadicTemplate (main) where
}
%wrapper "monad"
tokens :-
<0> . { mkL LDummy }
<0> $white ;
{
@danbst
danbst / curl-in-mingw.sh
Created February 18, 2015 15:40
How to curl in MinGW without curl
#!/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 July 19, 2015 17:34
Attempt to package python-qscintilla
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 October 2, 2015 17:08
Console Tetris
ТЕТРІС 0.0.0.12
Реалізація класичного тетріса (з урізаними можливостями), з виводом у консоль.
Урізано: відображення наступної фігури та рахунку
клавіша прискореного падіння фігури
рівні та зміна швидкостей
Код переписано багато разів, з кожним разом він ставав все кращим та кращим.
> {-# LANGUAGE TemplateHaskell #-}
#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"
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) =