Skip to content

Instantly share code, notes, and snippets.

View danbst's full-sized avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
module Images where
import Data.ByteString ( ByteString(..) )
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BSU
import Graphics.UI.GLUT
import qualified Graphics.Rendering.OpenGL.GL as GL
import qualified Codec.BMP as BMP
import Foreign.ForeignPtr
import Foreign.Ptr
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 ];
#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"
@danbst
danbst / entropy.hs
Created February 8, 2016 13:08
Entropy of a list
import Data.Char
import Data.Map (Map)
import qualified Data.Map as Map
entropy :: (Ord a) => [a] -> Float
entropy dta =
let freqmap = Map.fromListWith (+) $ zip dta (repeat 1)
modifier = 1.0 / fromIntegral (length dta)
freqs = Map.map (\v -> fromIntegral v * modifier) freqmap