Skip to content

Instantly share code, notes, and snippets.

View jamhed's full-sized avatar

Roman Galeev jamhed

View GitHub Profile
#!/bin/sh
echo """а-б A
аб C
а-б C""" | sort
locale | grep LANG=
@jamhed
jamhed / dia.erl
Created September 13, 2016 19:22
dia
-module(dia).
-export_type([uid/0, gid/0]).
-export([uid/0, uid/1, gid/0, gid/1]).
-export([parse_uid/1, do_weird_thing/2, user_uid/1]).
-type uid() :: {uid}.
-type gid() :: {gid}.
-record(user, {
uid = dia:uid() :: uid(),
get_bindings() ->
get_bindings(kz_config:get(amqp, use_federation)).
get_bindings([_Federation=true]) ->
[{'notifications', [{'restrict_to', ?RESTRICT_TO}, 'federate']}, {'self', []}];
get_bindings(_) ->
[{'notifications', [{'restrict_to', ?RESTRICT_TO}]}, {'self', []}].
if_true(true, Action) -> Action;
if_true(false, _) -> no_such_tile.
check_tile_exists(ExistsAction, Seat, Tile, Seats) ->
#desk_seat{ hand=Hand } = lists:nth(Seat, Seats),
if_true(deck:member(Tile, Hand), ExistsAction).
wait_for_discard({check_discard_possible, Seat, Tile}, S=#state{seat=Seat, seats=Seats}) ->
wait_for_discard({check_tile_exists(discard, Seat, Tile, Seats), Seat, Tile}, S);
map_spec_field(state, false) -> '$1';
map_spec_field(_, false) -> '_';
map_spec_field(F, {F, V}) -> V.
make_match_spec(Props) ->
lists:foldl(
fun
(F, Tuple) ->
erlang:append_element(Tuple, map_spec_field(F, lists:keyfind(F, 1, Props)))
end, {game}, record_info(fields, game)).
setup_sync() ->
sync:go(),
{ok, Comet} = wf:comet(fun() -> reload() end),
sync:onsync(fun(_) -> Comet ! {self(), reload} end).
reload() ->
receive
{_, reload} ->
wf:wire( "location.reload()" ),
wf:flush()
@jamhed
jamhed / gist:6941790
Created October 11, 2013 20:46
This is the way to test web-appication with phantom-js.
UAJQ = require("UA/JQ.coffee")
ua = new UAJQ
test_create_update_delete = (ua, name) ->
ua.then "click new", ->
@click "#0", ".ui-dialog-title"
ua.then "create #{name}", ->
@text "input[name=name]", "test"
package smsw::Table;
use Dancer ':syntax';
use Dancer::Plugin::Scoped;
our $VERSION = '0.1';
use strict;
sub my_template ($$$) {
my ($prefix, $file, $args) = @_;
$args->{lib}->{nbsp} = sub { $_[0] =~ s/\s+/ /g; $_[0] };
$args->{lib}->{row} = sub { join '', map { join('', '<', $_[0],'>',$_,'</',$_[0],'>') } @{$_[1]} };