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 / 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 / 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})
{-# 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 / 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() ->
@sumerman
sumerman / MVStateStorage.h
Created September 4, 2011 10:00
Intent of this code is to guide protected concurrent access to collection of states.
#import <Foundation/Foundation.h>
typedef id (^MVGetterBlock)(void);
typedef void (^MVSetterBlock)(id);
typedef id (^MVStateOpBlock)(id);
typedef NSOperation * (^MVOpSetupBlock)(MVGetterBlock, MVSetterBlock);
@interface MVStateStorage : NSObject {
__block NSMutableDictionary *data;
@sumerman
sumerman / NSInvocationOperation+multipleObject.m
Created June 1, 2011 07:25
initWithTarget:selector:objects: (multiple objects, until nil) cathegory for NSInvocationOperation
@interface NSInvocationOperation (mutipleObject)
- (id)initWithTarget:(id)target selector:(SEL) objects:(id)first, ...;
@end
@implementation NSInvocationOperation (multipleObjects)
- (id)initWithTarget:(id)target selector:(SEL)sel objects:(id)first, ... {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSMethodSignature *signature = [target methodSignatureForSelector:sel];
@sumerman
sumerman / refal_matching.hs
Created May 25, 2011 12:38
Refal-expression mathcing implementation for one of CS courses. Comments in russian.
-- | Задание практикума №2
-- Вариант №2 "Отождествление Рефал-выражений"
module Main where
import Debug.Trace
import Data.Maybe
import Control.Monad
import Text.ParserCombinators.Parsec as Parsec
-- * Вспомогательные функции и типы
@sumerman
sumerman / cpp_meta_type_enc_n_conv.cpp
Created April 29, 2011 16:47
Type encoding and conversion of encoded types through metaprogramming
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class Cast {
private:
struct BigType {
-module(head_srv).
-compile(export_all).
%-export([start/1, benchmark/1, console_start/0, loop/1]).
-include("jsonerl/jsonerl.hrl").
-record(command, {action, error, login, desc}).
-record(logic_state, {ies = none}).
-define(INTERNAL_TIMEOUT, 10000).
-define(LISTEN_PORT, 6070).
@sumerman
sumerman / static_dispatch_tmpr.cpp
Created February 15, 2011 12:11
Static dispatch with C++ templates
#include <cstdlib>
#include <iostream>
using namespace std;
struct Functor {
inline int operator () (int i, char c) {
return i+c;
}
};