Skip to content

Instantly share code, notes, and snippets.

View sumerman's full-sized avatar
🔮
DATABASE, DATABASE, JUST LIVING IN A DATABASE

Valery Meleshkin sumerman

🔮
DATABASE, DATABASE, JUST LIVING IN A DATABASE
View GitHub Profile
@sumerman
sumerman / port_inspector.erl
Created September 22, 2011 18:54
This escript determines which Erlang process is listening upon given network port
#!/usr/bin/env escript
%%! -name port_inspector
-module(port_inspector).
-export([inspect/0, main/1]).
%%
%% Info Collection Routines
%%
inspect() ->
{-# LANGUAGE BangPatterns #-}
import Data.Maybe
import Data.Array
import Data.Int
data Relation = G | L | N deriving (Show, Enum, Ord, Eq, Bounded)
data SCond = Any | F !Relation !Int64 deriving (Show, Ord, Eq)
key (Any, n) = (-1, -1, n)
@sumerman
sumerman / gist:1652914
Created January 21, 2012 14:22
iTunes Replace Items
(*
Please note: this is my ad-hoc script and it possibly contains bugs and strange behaviour.
It's also may be convenient to consolidate iTunes library after usage.
*)
on dedup(aList)
set res to {}
repeat with i from 1 to (length of aList)
set cur to item i of aList
if {cur} is not in res then set res to (res & {cur})
@sumerman
sumerman / match_spec_from_record.erl
Created May 12, 2012 10:11
Matchspec from record
-module(match_spec_from_record).
-export([hooks_for_scope/2]).
-record(hooks, {
scope :: atom(),
pid :: pid(),
pre :: mfa(),
post :: mfa()
@sumerman
sumerman / brackets.hs
Created May 27, 2012 09:07
Solution for a classic balanced-parens problem
{-
Bal ::= (Bal)Bal | [Bal]Bal | ""
-}
import Control.Monad
brackets = [('[',']'), ('(',')')]
isObr b = elem b (map fst brackets)
isCoBr b1 b2 = elem (b1,b2) brackets || elem (b2,b1) brackets
@sumerman
sumerman / config_srv.erl
Created May 28, 2012 16:00
Primitive config distribution server
-module(sp_config_srv).
-behaviour(gen_server).
-define(NODEUP_PAUSE, 100).
%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------
-export([
@sumerman
sumerman / pdscope.erl
Created September 3, 2012 10:02
Thoughts on safe Erlang PD usage to deal with short-living state (instead PTs like 'SeqBind')
-module(pdscope).
-export([pput/1, pget/0, pdscope/1, example/0]).
pput(X) ->
erlang:put(?MODULE, X).
pget() ->
erlang:get(?MODULE).
pdscope(Scope, F) ->
@sumerman
sumerman / cowboy_config.erl
Created September 25, 2012 11:59
Sample cowboy (0.6.x) config(s)
cowboy_config() ->
{ok, App} = application:get_application(),
Disp = [
{'_', [
{[<<"combiners">>, <<"test">>], combiner_test_src, []},
{[<<"combiners">>, <<"list">>], combiners_list, []},
{[<<"combiners">>, <<"info">>, comb_name], combiner_info, []},
{[<<"combiners">>, '...'], cowboy_http_static, [
{directory, {priv_dir, App, []}},
{mimetypes, [
@sumerman
sumerman / IntSet.hs
Created October 8, 2012 21:26
Scala class hierarchies vs Haskell algebraic-style vs Scala match
data IntSet = Empty
| Node { val :: Int,
left :: IntSet,
right :: IntSet } deriving Show
incl Empty x = Node x Empty Empty
incl node x | x < val node = node { left = incl (left node) x }
| x > val node = node { right = incl (right node) x }
| otherwise = node
@sumerman
sumerman / macro_src.scm
Created October 10, 2012 12:14
Scheme macro WTF
(define-syntax class
(syntax-rules (extends rmethods method)
((_ rmethods () r) `r)
((_ rmethods ((method (name arg1 ...) body ...) . methods) r)
(class rmethods methods ((name . ,(lambda (self arg1 ...) body ...)) . r)))
((_ header (extends parent) body ...)
(define header
(define methods (class rmethods (body ...) ()))
(make-dispatcher-self (extends (make-dict methods) parent))))
((_ header body ...)