Skip to content

Instantly share code, notes, and snippets.

@pulcheri
pulcheri / lzw.hs
Created July 14, 2016 15:41 — forked from abesto/lzw.hs
Haskell LZW compression
-- Could use a few rounds of cleanup...
import Data.Char
import Data.List
dictionary :: [String]
dictionary = [[chr c] | c <- [0 .. 127]]
prefixes :: [String] -> String -> [(Int, String)]
prefixes xs y = [(i, xs !! i) | i <- [0 .. (length xs) -1], xs !! i `isPrefixOf` y]
@pulcheri
pulcheri / Cyrillic words regex.clj
Last active July 14, 2016 12:52
Clojure snippets
;; regex to match cyrillic words
;; регулярное выражение для кириллического текста
(defn get-words [text] (re-seq #"[\p{IsCyrillic}\p{N}]+" text))
(def my-text "Переходите сюда, chere Helene, [милая Элен,] – сказала Анна Павловна красавице княжне, которая сидела поодаль, составляя центр другого кружка.")
(println (get-words my-text))
; (Переходите сюда милая Элен сказала Анна Павловна красавице княжне которая сидела поодаль составляя центр другого кружка)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
window.WebSocket = window.WebSocket || window.MozWebSocket;
var websocket = new WebSocket('ws://127.0.0.1:9000',
@pulcheri
pulcheri / testarrows.scm
Created June 30, 2016 19:43 — forked from carloscm/testarrows.scm
-> ->> -<> -<>> for S7 Scheme
; -> ->> -<> -<>> for S7 Scheme
; inspired by https://github.com/nightfly19/cl-arrows and https://github.com/rplevy/swiss-arrows
(require stuff.scm)
; using: any? while
; replace those with your favorite scheme alternatives
; direct translation from https://github.com/nightfly19/cl-arrows
(define (arrow-proto handler initial-form forms)
(let ((output-form initial-form)
{-# LANGUAGE OverloadedStrings #-}
module SimpleThings where
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
import Data.Aeson
import qualified Data.Aeson as A
-- | sum type containing all possible payloads
@pulcheri
pulcheri / ThreadPool.hs
Created June 24, 2016 16:50 — forked from NicolasT/ThreadPool.hs
Haskell worker threadpool using STM
{-# LANGUAGE CPP, FlexibleContexts, BangPatterns #-}
module Control.Concurrent.ThreadPool (
createPool
, destroyPool
, withPool
, pushWork
, popResult
, popResult'
@pulcheri
pulcheri / ecldemo.c
Created June 24, 2016 16:48 — forked from vwood/ecldemo.c
Example of ECL in a C program.
/*
Example of a C program embedding ECL with callbacks to C functions.
Compiled via: gcc ecldemo.c -lecl
*/
#include <stdio.h>
#include <stdlib.h>
#include "ecl/ecl.h"
#define DEFUN(name,fun,args) \
cl_def_c_function(c_string_to_object(name), \
-- solution to Haskell kata
-- https://www.codewars.com/kumite/new?group_id=5463fbb024b6c287a0000016&review_id=5463fbb024b6c287a0000014
module IPv4 where
import Data.List (intercalate)
import Data.Word (Word32)
import Data.Int (Int32)
import Data.Bits ((.&.), shiftR)
type IPString = String
// Not quite as bad as https://twitter.com/ivansafrin/status/457248037157740544 but still hairy.
#include <memory>
#include <type_traits>
#include <iostream>
template <typename Creator, typename Destructor, typename... Arguments>
auto make_resource(Creator c, Destructor d, Arguments &&... args) {
using value_t = typename std::decay<decltype(*c(std::forward<Arguments>(args)...))>::type;
using ptr_t = std::unique_ptr<value_t, void (*)(value_t *)>;
import Random
import Mouse
import Graphics.Collage exposing (toForm, move, collage)
import Graphics.Element exposing (show)
import List exposing (..)
import Time
type Fruit = Apple | Orange | Banana | Melon | Guava
-- For module global declarations, it is often helpful to