public static void main(String[] args) {

    Sql2o sql2o = new Sql2o("jdbc:mysql://192.168.2.11:3306/db_school", "admin", "admin");

    String ipAddress = Optional.ofNullable(System.getenv("OPENSHIFT_DIY_IP")).orElse("0.0.0.0");
    int ipPort =
        Integer.parseInt(Optional.ofNullable(System.getenv("OPENSHIFT_DIY_PORT")).orElse("8008"));

    ipAddress(ipAddress);
    port(ipPort);

    new StudentController(new StudentService(sql2o));
    new SchoolClassController(new SchoolClassService(sql2o));
    new SchoolTimeTableController(new SchoolTimeTableService(sql2o));
  }
Example #2
0
    public static void main(String[] args) {

        port(Integer.valueOf(System.getenv("PORT")));

        get("/", (request, response) -> {

            // Create a rest client
            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

            // Get the main account (The one we used to authenticate the client)
            Account mainAccount = client.getAccount();

            // Get all accounts including sub accounts
            AccountList accountList = client.getAccounts();

            // All lists implement an iterable interface, you can use the foreach
            // syntax on them
            for (Account a : accountList) {
                System.out.println(a.getFriendlyName());
            }

            // Send an sms (using the new messages endpoint)
            MessageFactory messageFactory = mainAccount.getMessageFactory();
            List<NameValuePair> messageParams = new ArrayList<NameValuePair>();
            messageParams.add(new BasicNameValuePair("To", "+19172164313; // Replace with a valid phone number
            messageParams.add(new BasicNameValuePair("From", "+19142054512")); // Replace with a valid phone
            // number in your account
            messageParams.add(new BasicNameValuePair("Body", "Hello from Fabian Patino"));
            messageFactory.create(messageParams);

            return "Hello From Fabian Patino";
        });
  public static void main(String[] args) {

    port(Integer.valueOf(System.getenv("PORT")));
    staticFileLocation("/public");

    // get("/hello", (req, res) -> "Hello World");

    // get("/hello", (req, res) -> {
    //   RelativisticModel.select();

    //   String energy = System.getenv().get("ENERGY");

    //   Amount<Mass> m = Amount.valueOf(energy).to(KILOGRAM);
    //   return "E=mc^2: " + energy + " = " + m.toString();
    // });

    // get("/", (request, response) -> {
    //         Map<String, Object> attributes = new HashMap<>();
    //         attributes.put("message", "Hello World!");

    //         return new ModelAndView(attributes, "index.ftl");
    //     }, new FreeMarkerEngine());

    get(
        "/db",
        (req, res) -> {
          Connection connection = null;
          Map<String, Object> attributes = new HashMap<>();
          try {
            connection = DatabaseUrl.extract().getConnection();

            Statement stmt = connection.createStatement();
            stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)");
            stmt.executeUpdate("INSERT INTO ticks VALUES (now())");
            ResultSet rs = stmt.executeQuery("SELECT tick FROM ticks");

            ArrayList<String> output = new ArrayList<String>();
            while (rs.next()) {
              output.add("Read from DB: " + rs.getTimestamp("tick"));
            }

            attributes.put("results", output);
            return new ModelAndView(attributes, "db.ftl");
          } catch (Exception e) {
            attributes.put("message", "There was an error: " + e);
            return new ModelAndView(attributes, "error.ftl");
          } finally {
            if (connection != null)
              try {
                connection.close();
              } catch (SQLException e) {
              }
          }
        },
        new FreeMarkerEngine());
  }
Example #4
0
  public static void main(String[] args) {
    String layout = "templates/layout.vtl";

    get(
        "/",
        (request, response) -> {
          Map<String, Object> model = new HashMap<String, Object>();
          model.put("template", "templates/home.vtl");
          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    get(
        "/detector",
        (request, response) -> {
          Map<String, Object> model = new HashMap<String, Object>();
          model.put("template", "templates/detector.vtl");

          // word variable userInputtedWord
          // grab which word is entered in the form
          // String userInputtedWord = request.queryParams("word");
          // Integer wordScore = getWordScore(userInputtedWord);
          // model.put("wordScore", wordScore);
          // model.put("word", userInputtedWord);
          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    Console myConsole = System.console();
    Random randomGenerator = new Random();
    // Random randomNum = new Random();
    ArrayList<String> computerOptions = new ArrayList<String>();
    {
      {
        computerOptions.add("rock");
        computerOptions.add("paper");
        computerOptions.add("scissors");
      }
    }
    ;
    // double brace initialization

    String computerStringOptions[] = new String[computerOptions.size()];
    String array[] = new String[computerOptions.size()];
    for (int i = 0; i < computerOptions.size(); i++) {
      array[i] = computerOptions.get(i);
    }

    // random number between 0 and 2
    int computerRandom = randomGenerator.nextInt(3);
    // array of moves: move name, beaten by
    String computerInput = computerStringOptions[computerRandom];
    String[][] moves = {
      {
        "rock", "paper",
      },
      {
        "scissors", "rock",
      },
      {
        "paper", "scissors",
      },
    };
    System.out.println(computerInput);
  }