Skip to content

Instantly share code, notes, and snippets.

View rblaze's full-sized avatar

Andrey Sverdlichenko rblaze

View GitHub Profile
readMore <- atomically $ do
closing <- readTVar $ acClosing state
if not closing then return False
else do
inflight <- readTVar $ acInFlight state
return $ inflight /= 0
saveVector :: String -> Vector a -> IO ()
saveVector name vec =
withFile name WriteMode $ \h -> do
let (ptr, len) = U.unsafeToForeignPtr0 vec
withForeignPtr ptr $ \p -> hPutBuf h p (len * sizeOf (0 :: a))
loadVector :: String -> IO Vector a
loadVector name =
withFile name ReadMode $ \h -> do
len <- liftM fromIntegral $ hFileSize h
@rblaze
rblaze / VV.hs
Last active December 18, 2015 23:59
{-# LANGUAGE ScopedTypeVariables #-}
module VV where
import Control.Monad
import Foreign.ForeignPtr.Safe
import Foreign.Storable
import System.IO
import qualified Data.Vector.Storable as U
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
type Coloring = U.Vector Word32
type Links = V.Vector (U.Vector Int)
colors :: Coloring
links :: Links
allColors, deadColors :: U.Vector Color
@rblaze
rblaze / results
Created August 26, 2013 08:22
Чтение текстового файла
$ ls -l test.txt
-rw-rw-r-- 1 blaze blaze 69979380 Aug 26 12:08 test.txt
$ wc -l test.txt
8994700 test.txt
Strict Data.Bytestring + decodeUtf8 -- 5 секунд
Strict Data.Text.IO -- 7 секунд
Lazy Data.Bytestring + decodeUtf8 -- 10 секунд
Lazy Data.Text.IO -- 12 секунд
import XMonad
import XMonad.Config.Gnome
import XMonad.Util.EZConfig
import XMonad.Hooks.ManageHelpers (isFullscreen,doFullFloat)
import qualified XMonad.StackSet as W
myWorkspaces = ["1","2","3","4","5","6","7","8","9"]
main = xmonad $ gnomeConfig
@rblaze
rblaze / test.hs
Created September 30, 2013 13:41
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Exception
import System.Exit
main :: IO ()
main = do
r <- catch (do
let [r, _] = ['a']
@rblaze
rblaze / gist:6954192
Created October 12, 2013 19:57
Сериализация данных и ночные кошмары
0 : 0 0 0 0 0 0 0 0 0
1 : 1 0 0 0 0 0 0 0 0
12 : 12 0 0 0 0 0 0 0 0
123 : 81 23 0 0 0 0 0 0 0
1234 : 92 34 0 0 0 0 0 0 0
12345 : c1 45 23 0 0 0 0 0 0
123456 : d2 56 34 0 0 0 0 0 0
1234567 : e1 23 67 45 0 0 0 0 0
12345678 : f0 78 56 34 12 0 0 0 0
123456789 : f1 89 67 45 23 0 0 0 0
@rblaze
rblaze / cheat.fs
Last active August 29, 2015 14:00
Minesweeper cheater
type Field = array<bool>
let rec printField xsize (field : Field) =
let printLine i = Array.sub field (i * xsize) xsize |> Array.map (fun v -> if v then 'X' else '.')
[for n in 0 .. field.Length / xsize - 1 -> System.String(printLine n)]
let genField size (g : System.Random) = Array.init size (fun _ -> g.Next(100) < 20)
let hasMine xsize (field : Field) (x, y) = field.[y * xsize + x]
@rblaze
rblaze / aestest.cpp
Last active August 29, 2015 14:03
AES perf test
#define CHECK(x) \
do { \
NTSTATUS __l_status = (x); \
if (! BCRYPT_SUCCESS(__l_status)) { \
printf("ERROR: `%s` returned %x\n", #x, __l_status); \
return 1; \
} \
} while (0)
UCHAR masterSecret[128];