Begin a new Kumite
Search
About
  • Filter by Language:
  • Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.

    You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.

    A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.

The watcher part isn't needed. All you have to do is write the tests themeselves.

Recent Moves:

MongoDB
NoSQL
Databases
Information Systems

Security permissions were tighted up, so had to add /tmp/ to the mongoid config file path.

Code
Diff
  • require 'mongoid'
    File.open('/tmp/mongoid.yml', 'w') do |file|
      file.write <<-CONFIG
    development:
      sessions:
        default:
          database: mongoid
          hosts:
            - localhost:27017
    CONFIG
    end
    fork { `mongod` }
    sleep 1.5 # need to find a better way to wait for mongo to startup
    
    ENV['RACK_ENV'] = 'development'
    Mongoid.load!('/tmp/mongoid.yml')
    
    class User
      include Mongoid::Document
      field :name
    end
  • 11
    require 'mongoid'
    
    2
    File.open('mongoid.yml', 'w') do |file|
    
    2+
    File.open('/tmp/mongoid.yml', 'w') do |file|
    
    33
      file.write <<-CONFIG
    
    44
    development:
    
    55
      sessions:
    
    66
        default:
    
    77
          database: mongoid
    
    88
          hosts:
    
    99
            - localhost:27017
    
    1010
    CONFIG
    
    1111
    end
    
    1212
    fork { `mongod` }
    
    13
    sleep 1 # need to find a better way to wait for mongo to startup
    
    13+
    sleep 1.5 # need to find a better way to wait for mongo to startup
    
    1414
    1515
    ENV['RACK_ENV'] = 'development'
    
    16
    Mongoid.load!('mongoid.yml')
    
    16+
    Mongoid.load!('/tmp/mongoid.yml')
    
    1717
    1818
    class User
    
    1919
      include Mongoid::Document
    
    2020
      field :name
    
    2121
    end
    

Recent Moves:

Code
Diff
  • fn main() {
        println!("All we are in rust in the wind...");
    }
  • 1
    println "hello, world"
    
    1+
    fn main() {
    
    2+
        println!("All we are in rust in the wind...");
    
    3+
    }
    
Code
Diff
  • class Fridge
      def initialize
        @items = {}
      end
      
      def add(item, amount = 1)
        @items[item] ||= 0
        @items[item] += amount
      end
      
      def serve(item, amount = 1)
        _amount = [amount, inventory(item)].min
        add(item, _amount * -1)
        
        _amount.times do
          puts "One #{item} coming right up!"
        end
        
        (amount - _amount).times do
          puts "We're all out of #{item}"
        end
      end
      
      def inventory(item = nil)
         if item
           @items[item]
         else
           @items.values.reduce(0) {|s, v| s + v} 
         end
      end
    end
    
    ## examples:
    
    fridge = Fridge.new
    
    fridge.add :beer, 6
    fridge.add :pudding, 8
    fridge.add :salsa
    fridge.add :soda
    fridge.add :eggs
    fridge.add :steak
    
    puts "There are #{fridge.inventory} items in the fridge"
    puts "#{fridge.inventory(:beer)} of those are beers"
    
    fridge.serve(:beer, 7)
    fridge.serve(:steak)
    
    puts "There are #{fridge.inventory} items in the fridge"
    puts "#{fridge.inventory(:beer)} of those are beers"
  • 1
    Proc = fun(Y, Items) ->
    
    2
    	receive
    
    3
        {Sender, Item} when is_pid(Sender) -> 
    
    4
        	case dict:find(Item, Items) of
    
    5
           {ok, Value} ->
    
    6
              NewCount = Value - 1,
    
    7
            	io:format("One ~p coming right up!~n", [Item]),
    
    8
           		Sender ! Item,
    
    9
              Y(Y, dict:store(Item, NewCount, Items));
    
    10
          	_ -> 
    
    11
            	io:format("We're all out of ~p~n", [Item]),
    
    12
              Y(Y, Items)
    
    13
          end;
    
    14
          
    
    15
        {count, Item} ->
    
    16
            case dict:find(Item, Items) of
    
    17
              {ok, Value} -> io:format("~p: ~p~n", [Item, Value]);
    
    18
               _ -> io:format("We're all out of ~p~n", [Item])
    
    19
            end,
    
    20
            Y(Y, Items);
    
    21
            
    
    22
        {Item, Count} when is_atom(Item) andalso is_integer(Count) -> 
    
    23
        	io:format("~p added.~n", [Item]),
    
    24
          NewCount = case dict:find(Item, Items) of
    
    25
            {ok, Value} -> Value + Count;
    
    26
          	_ -> Count
    
    27
          end,
    
    28
          Y(Y, dict:store(Item, NewCount, Items));
    
    29
          
    
    30
        count ->
    
    31
          io:format("~p~n", [dict:to_list(Items)]),
    
    32
          Y(Y, Items);
    
    33
          
    
    34
        Item when is_atom(Item) -> 
    
    35
        	io:format("~p added.~n", [Item]),
    
    36
          NewCount = case dict:find(Item, Items) of
    
    37
            {ok, Value} -> Value + 1;
    
    38
          	_ -> 0
    
    39
          end,
    
    40
          Y(Y, dict:store(Item, NewCount, Items));
    
    41
          
    
    42
        _ -> io:format("Killing Fridge...")
    
    1+
    class Fridge
    
    2+
      def initialize
    
    3+
        @items = {}
    
    4343
      end
    
    44
    end,
    
    5+
      
    
    6+
      def add(item, amount = 1)
    
    7+
        @items[item] ||= 0
    
    8+
        @items[item] += amount
    
    9+
      end
    
    10+
      
    
    11+
      def serve(item, amount = 1)
    
    12+
        _amount = [amount, inventory(item)].min
    
    13+
        add(item, _amount * -1)
    
    14+
        
    
    15+
        _amount.times do
    
    16+
          puts "One #{item} coming right up!"
    
    17+
        end
    
    18+
        
    
    19+
        (amount - _amount).times do
    
    20+
          puts "We're all out of #{item}"
    
    21+
        end
    
    22+
      end
    
    23+
      
    
    24+
      def inventory(item = nil)
    
    25+
         if item
    
    26+
           @items[item]
    
    27+
         else
    
    28+
           @items.values.reduce(0) {|s, v| s + v} 
    
    29+
         end
    
    30+
      end
    
    31+
    end
    
    32+
    33+
    ## examples:
    
    34+
    35+
    fridge = Fridge.new
    
    36+
    37+
    fridge.add :beer, 6
    
    38+
    fridge.add :pudding, 8
    
    39+
    fridge.add :salsa
    
    40+
    fridge.add :soda
    
    41+
    fridge.add :eggs
    
    42+
    fridge.add :steak
    
    4545
    46
    Pid = spawn(fun() -> Proc(Proc, dict:new()) end),
    
    44+
    puts "There are #{fridge.inventory} items in the fridge"
    
    45+
    puts "#{fridge.inventory(:beer)} of those are beers"
    
    4747
    48
    Pid ! {beer, 6},
    
    49
    Pid ! {pudding, 8},
    
    50
    Pid ! salsa,
    
    51
    Pid ! soda,
    
    52
    Pid ! eggs,
    
    53
    Pid ! steak,
    
    54
    55
    Pid ! count,
    
    56
    Pid ! {count, beer},
    
    57
    Pid ! {self(), beer},
    
    58
    Pid ! {count, beer},
    
    47+
    fridge.serve(:beer, 7)
    
    48+
    fridge.serve(:steak)
    
    5959
    60
    init:stop().
    
    50+
    puts "There are #{fridge.inventory} items in the fridge"
    
    51+
    puts "#{fridge.inventory(:beer)} of those are beers"
    

Recent Moves:

Code
Diff
  • Proc = fun (Index) -> 
    	timer:sleep(10),
    	io:format("~p~n", [Index])
    end,
    
    [spawn(fun() -> Proc(X) end) || X <- lists:seq(1, 40)],
    
    init:stop().
  • 1
    Proc = fun () -> 
    
    2
    	io:format("Hello Process.~n")
    
    1+
    Proc = fun (Index) -> 
    
    2+
    	timer:sleep(10),
    
    3+
    	io:format("~p~n", [Index])
    
    33
    end,
    
    44
    5
    Pid = spawn(Proc),
    
    6
    7
    io:format(" Hello's Pid: ~p~n", [Pid]),
    
    6+
    [spawn(fun() -> Proc(X) end) || X <- lists:seq(1, 40)],
    
    88
    99
    init:stop().
    

Recent Moves: