Skip to content

Instantly share code, notes, and snippets.

View Heimdell's full-sized avatar
🔨
Right tool for the right job

Андреев Кирилл Heimdell

🔨
Right tool for the right job
  • Ульяновск
View GitHub Profile
@Heimdell
Heimdell / gist:4058067
Created November 12, 2012 08:01
Тезисы
Система типов: если есть нечто, что можно представить структурой и выразить через типы - do it.
> newtype End = End (Request -> Maybe Request)
> newtype Node = Node (Request -> Maybe Request)
> Node granny // Node mom = Node (mom <=< granny)
> Node mom /> End son = End (son <=< mom)
> End left \/ End right = End (left `orelse` right)
@Heimdell
Heimdell / gist:4060534
Created November 12, 2012 17:02
Router mark 2
{-# LANGUAGE RecordWildCards #-}
import Control.Monad
{-
Later, `Class {..}` will autobind all attributes to their names
in the field of visibility
-}
data Structure = Class { name :: String
, abilities :: Structure
@Heimdell
Heimdell / gist:4065418
Created November 13, 2012 12:02
Strip your spaces!
import System.Environment
import System.IO
import System.Directory
import Data.String.Utils
import Control.Monad
main = do places <- getArgs
let place = if places == []
@Heimdell
Heimdell / TaskGen.hs
Created November 28, 2012 12:21
Vim-tasks generator
{-# Language RecordWildCards #-}
module TaskGen where
import Control.Monad
data Task = Task { combos :: [String]
, description :: String
, actions :: [String]
@Heimdell
Heimdell / Parser.hs
Created December 4, 2012 14:25
Parsec analogue (too dumb to learn parsec, I'd better write my own, mwahaha)
{-# LANGUAGE FunctionalDependencies,
FlexibleInstances #-}
module Parser where
import Control.Monad
newtype Parser e s a = Parser { runParser :: s -> Either (Error e s) (a, s) }
data Error a b = Error a String b deriving Show
@Heimdell
Heimdell / llist.erl
Created December 14, 2012 09:42
Lazy list generator in erlang.
-module (llist).
-compile(export_all).
unfold(X, F) ->
case F(X) of
{ok, X1} -> [X1 | fun() -> unfold(X1, F) end];
false -> []
end.
@Heimdell
Heimdell / flash_helper.rb
Created December 25, 2012 10:40
Flash helper library
module FlashHelper
[:success, :info].each do |kind|
define_method "flash_#{kind}" do |options = {}|
msg = options[:message] || kind
flash_notice message: msg, kind: kind, now: options[:now]
end
end
def flash_error(options = {})
@Heimdell
Heimdell / Adapter.hs
Last active December 11, 2015 03:48
Homework db
module Adapter where
import qualified Data.Map as Map
_create :: Ord k => k -> v -> Map k v -> Map k v
_create = Map.insert
_update :: Ord k => k -> v -> Map k v -> Map k v
_update = Map.insert
@Heimdell
Heimdell / retry.c
Last active December 11, 2015 15:38
Do it again.
int main(int argc, char *argv[]) {
int count = 10, silent = 0;
char * command = 0;
char letter;
while ((letter = getopt_long(argc, argv, "n:c:s")) != -1) {
switch (letter) {
case 'n':
count = atoi(optarg);
break;
@Heimdell
Heimdell / GrepDefs.hs
Last active December 12, 2015 01:28
Because I'm not the master of awk & sed, and they cannot into fs structure. Run it from the root of the railsapp, it will rebuild routes-like thing from tests. The method-from-controller parser is comin' soon.
import Data.List
import System.Environment
import System.IO
import System.Directory
import Data.String.Utils hiding (join)
import Control.Monad
import System.FilePath.Posix