Ad

Error displaying in prolog.

Code
Diff
  • add(A, B, R) :- 
        number(A)
        , number(B)
        , R is A + B 
        +2 %wrong part to show formatting tricks
        .
    • add(A, B, R) :- R is A + B.
    • add(A, B, R) :-
    • number(A)
    • , number(B)
    • , R is A + B
    • +2 %wrong part to show formatting tricks
    • .

This Kumite is created to test JQuery support on Codewars.

var jsdom = require("jsdom/lib/old-api.js");

jsdom.env(
    '<!DOCTYPE html><p>Hello world</p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a>', ["http://code.jquery.com/jquery.js"],
    function(err, window) {
        console.log(window.document.querySelector("p").textContent);
        var $ = window.$;

        $.getJSON('https://www.codewars.com/users/Javatlacati', null, function(data) {
            console.log(data);
        }).error(function(e) {
            console.log("first attempt failed\n" + JSON.stringify(e));
        });



        var name = "kazk";
        var url = "http://anyorigin.com/go?url=" + encodeURIComponent("https://www.codewars.com/users/") + name + "&callback=?";
        $.get(url, function(response) {
            console.log(response);
        }).error(function(e) {
            console.log("second attempt failed\n" + JSON.stringify(e));
        });
        console.log("contents of a.the-link:", window.$("a.the-link").text());
    }
);
Code
Diff
  • SELECT * FROM current_catalog
    • SELECT current_database();
    • SELECT * FROM current_catalog

Do you know where you are?
You had a massive hangover and don't rememeber where are you.
Use your system to know info about your enviroment.

SQL

Retrieve the current database

SELECT current_database();
// add the values "codewars" to the websites array
var websites = ['codears'];

That's a simple threading test using JavaFX. It currently has troubles due to codewars JVM runner.

import java.util.concurrent.atomic.AtomicInteger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;

/** Created by Javatlacati on 08/02/2017. */
public class Aciago extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage primaryStage) throws Exception {
    Thread miHilo =
        new Thread(
            new Runnable() {
              final AtomicInteger i = new AtomicInteger(0);

              @Override
              public void run() {
                System.out.println("Corriendo");
                while (true) {
                  Platform.runLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          System.out.println(i.getAndIncrement() + " ola soi un hilo :v");
                        }
                      });

                  try {
                    if (i.get() < 4) {
                      System.out.println("anuma me voi a dormir");
                      Thread.sleep(1000);
                    } else {
                      throw new InterruptedException("#PosMeMuero");
                    }
                  } catch (InterruptedException ex) {
                    System.err.println("#ToyMorido");
                    Platform.exit();
                    System.out.println("JavaFx is dead");
                    break;
                  }
                }
              }
            });

    miHilo.setName("soy el mapa soy el mapa soy el mapa soy el mapa soy el mapa!");
    miHilo.setDaemon(false);
    miHilo.start();
  }
}

Any help is welcome :)

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Javatlacati on 07/02/2017.
 */
public class ThreadIssueSolution extends ScheduledThreadPoolExecutor {
    public boolean isUsable=true;
    public ThreadIssueSolution() {
        super(1);
    }

    @Override
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
        return super.scheduleAtFixedRate(wrapRunnable(command), initialDelay, period, unit);
    }

    @Override
    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
        return super.scheduleWithFixedDelay(wrapRunnable(command), initialDelay, delay, unit);
    }

    private Runnable wrapRunnable(Runnable command) {
        return new LogOnExceptionRunnable(command);
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
//        super.afterExecute(r, t);
        if(!(t == null && r == null)){
            throw new ArithmeticException("ooops");
        }
    }

    private class LogOnExceptionRunnable implements Runnable {
        private Runnable theRunnable;

        public LogOnExceptionRunnable(Runnable theRunnable) {
            super();
            this.theRunnable = theRunnable;
        }

        @Override
        public void run() {
            try {
                theRunnable.run();
            } catch (Throwable e) {
               System.err.println("error ejecutando: " + theRunnable + ". no seguirá corriendo!");
                //e.printStackTrace();
                // and re throw it so that the Executor also gets this error so that it can do what it would
                // usually do
                throw new RuntimeException(e);
            }
        }
    }
}

Shows how to use bash kta and how to create simple tests

echo Hello Bash!
JavatlacatiFailed Tests

Kotlin

Kotlin Hello World modified to show some language features

/**
 * Created by Javatlacati on 26/10/2016.
 */
object LambdaKotlin {
    @JvmStatic
    fun main(args: Array<String>) {
        val arr=arrayOf("hola","mundo","cruel")
        arr.forEach {
            println(it)
        }
    }
}
Code
Diff
  • #include <string>
    #include <stdio.h>
    
    int Main()
    {
      int arg1, arg2, add, sub, mul, quo, rem ;
    
        printf( "Enter two integer numbers : " );
        scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
    
        /* Perform Addition, Subtraction, Multiplication & Division */
        __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
        __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
        __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
    
        __asm__ ( "movl $0x0, %%edx;"
                  "movl %2, %%eax;"
                  "movl %3, %%ebx;"
                   "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
    
        printf( "%d + %d = %d\n", arg1, arg2, add );
        printf( "%d - %d = %d\n", arg1, arg2, sub );
        printf( "%d * %d = %d\n", arg1, arg2, mul );
        printf( "%d / %d = %d\n", arg1, arg2, quo );
        printf( "%d %% %d = %d\n", arg1, arg2, rem );
    
        return 0 ;
    }
    • int main()
    • {
    • printf("%d\n", test());
    • }
    • #include <string>
    • #include <stdio.h>
    • int test()
    • int Main()
    • {
    • __asm__("movl $1337, %eax");
    • int arg1, arg2, add, sub, mul, quo, rem ;
    • printf( "Enter two integer numbers : " );
    • scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
    • /* Perform Addition, Subtraction, Multiplication & Division */
    • __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "movl $0x0, %%edx;"
    • "movl %2, %%eax;"
    • "movl %3, %%ebx;"
    • "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
    • printf( "%d + %d = %d\n", arg1, arg2, add );
    • printf( "%d - %d = %d\n", arg1, arg2, sub );
    • printf( "%d * %d = %d\n", arg1, arg2, mul );
    • printf( "%d / %d = %d\n", arg1, arg2, quo );
    • printf( "%d %% %d = %d\n", arg1, arg2, rem );
    • return 0 ;
    • }
Fundamentals

Easy sample of how to run a hello world and use basic test.

Code
Diff
  • #include <iostream>
    #include <string>
    
    int helloCplusplus(){
      std::string str = "Hello, C++!";
      std::cout << str << '\n';
      return 0;
    }
    • System.Console.WriteLine("Hello, C#!");
    • #include <iostream>
    • #include <string>
    • int helloCplusplus(){
    • std::string str = "Hello, C++!";
    • std::cout << str << '\n';
    • return 0;
    • }
Testing

Code from the official page

class MyTestCase extends GroovyTestCase {

    void testAssertions() {
        assertTrue(1 == 1)
        assertEquals("test", "test")

        def x = "42"
        assertNotNull "x must not be null", x
        assertNull null

        assertSame x, x
    }

}
Code
Diff
  • defmodule Solution do
      def sum(a, b) do
        a + b
      end
    end
    • sum = fn a, b -> a + b end
    • defmodule Solution do
    • def sum(a, b) do
    • a + b
    • end
    • end
Code
Diff
  • sum = fn a, b -> a + b end
    • sum = fn(a, b) -> a + b end
    • sum.(2,3)
    • sum = fn a, b -> a + b end
Loading more items...