SQL Saturday

This is a short post but the problems were still pretty fun!

Types of Triangles:

Given the table of triangles, sides find if a triangle is possible. If so then find the type of triangle that exists.

Triangle


The PADS

An OCCUPATIONS table that contains the following records:

Generate the following two result sets:

  1. Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
  2. Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:

Creating your first .net app

I recently have been looking at more things to dive into and decided to try out .net. LinkedIn has 32,000 listings for .net positions in the U.S. so that also further peaked my interest. If you don’t know much about .net in broad strokes it is an open source platform that allows you to reach multiple platforms.

Screen Shot 2018-02-07 at 1.55.24 PM.png

I will be working off the Microsoft tutorials for most of the .net stuff I will be doing. If you haven’t used any of their documentation before it’s pretty awesome.

Install .Net SDK

Once installed go into your documents folder to create your first appScreen Shot 2018-02-07 at 5.36.10 PM.png.

 

 

 

After this is successful you can ls the directory to see the new app.

Screen Shot 2018-02-07 at 5.36.42 PM.png

 

 

Cd into the myApp directory.

Screen Shot 2018-02-07 at 6.03.14 PM.png

 

 

This is a very basic .net application. The commands for the Hello World output comes from the program.cs file found within the myApp folder. carbon.png

Next week I will be making a more complex .net project to share with you all! See you next time.

SQL Saturday

SQL Saturday

Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.

SELECT DISTINCT CITY

FROM STATION

WHERE City like “A%” or City like “E%” or City like “I%” or City like “O%” or City like”U%”;

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.

SELECT DISTINCT CITY
FROM STATION
WHERE City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u";

Query the list of CITY names from STATION which has vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.

SELECT DISTINCT CITY
FROM STATION
WHERE City like "A%" AND (City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u") or
      City like "E%" AND (City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u") or 
      City like "I%" AND (City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u") or 
      City like "O%" AND (City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u") or 
      City like"U%" AND (City like "%a" or City like "%e" or City like "%i" or City like "%o" or City like"%u");

Query the list of CITY names from STATION that does not start with vowels. Your result cannot contain duplicates.

SELECT DISTINCT CITY
FROM STATION
WHERE City NOT like "A%" AND City NOT like "E%" AND City NOT like "I%" AND City NOT like "O%" AND City NOT like"U%";

Query the list of CITY names from STATION that does not end with vowels. Your result cannot contain duplicates.

SELECT DISTINCT CITY
FROM STATION
WHERE City NOT like "%a" AND City NOT like "%e" AND City NOT like "%i" AND City NOT like "%o" AND City NOT like"%u";

Fun with Select Queries

Query all columns for all American cities in CITY with populations larger than 100000. The CountryCode for America is USA. Input Format The CITY table is described as follows:

Screen Shot 2018-01-27 at 9.53.29 AM.png

SELECT * /*Selects all columns from table*/
FROM CITY /*selects table named city */
 /*only if the population is over100000 and the country is in the USA*/
WHERE POPULATION > 100000 AND COUNTRYCODE = 'USA';

Query the names of all American cities in CITY with populations larger than 120000. The CountryCode for America is USA.

SELECT NAME /*Selects NAME column from table*/
FROM CITY /*selects table named city */
/*only if the population is over 120000 and the country is in the USA*/
WHERE POPULATION > 120000 AND COUNTRYCODE = 'USA';

Query all columns (attributes) for every row in the CITY table.

SELECT * /*Selects all columns from table*/
FROM CITY; /*selects table named city */

Query all columns for a city in CITY with the ID 1661.

SELECT * /*Selects all columns from table*/
From CITY /*selects table named city */
WHERE ID = 1661; /*only if the city has an id of 1661 */

Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.

SELECT * /*Selects all columns from table*/
FROM CITY/*selects table named city */
WHERE COUNTRYCODE = 'JPN'; /*only if the country is in the japan*/

Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.

SELECT NAME /*Selects NAME column from table*/
FROM CITY/*selects table named city */
WHERE COUNTRYCODE = 'JPN'; /*only if the country is Japan*/

Query a list of CITY and STATE from the STATION table.

Screen Shot 2018-01-27 at 10.12.18 AM.png
SELECT CITY, STATE /*Selects the city and state columns from table*/
FROM STATION; /*reads from table*/

Query a list of CITY names from STATION with even ID numbers only. You may print the results in any order, but must exclude duplicates from your answer.
SELECT DISTINCT CITY /*selects distinct city name from a table */
FROM STATION /*uses table called station*/
WHERE (ID%2) = 0; /*only if the id is even*/

Let  be the number of CITY entries in STATION, and let  be the number of distinct CITY names in STATION; query the value of  from STATION. In other words, find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

/*selects city count and distinct city name from a table and finds diff*/
SELECT COUNT(CITY) - COUNT( DISTINCT CITY) FROM STATION;

Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.

/*selects city name and string len from a table */
SELECT CITY, LENGTH(CITY)
/*selects from table named station */
FROM STATION
/*if the string len is the minimum */
WHERE LENGTH(CITY) = (SELECT MIN(LENGTH(CITY)) FROM STATION )
/*orders in alpha by city name */
ORDER BY CITY
/*takes only one from the list*/
LIMIT 1;

/*selects city name and string len from a table */
SELECT CITY, LENGTH(CITY)
/*selects from table named station */
FROM STATION 
/*if the string len is the maximum */
WHERE LENGTH(CITY) = (SELECT MAX(LENGTH(CITY)) FROM STATION)
/*orders in alpha by city name */
ORDER BY CITY
/*takes only one from the list*/
LIMIT 1;

 

Simple StopWatch

StopWatch by Developer Austin.

Screen Shot 2018-01-17 at 3.35.50 PM.png

This was my first actual published application for the Android Play Store and I loved the process! My goal for this project was to create a simple application and to try to learn as much as possible.

I used Android O to create and release so it is not available to everyone.

Download Page: https://play.google.com/store/apps/details?id=com.amsuarez.stopwatch

Application Design

Layout

Screen Shot 2018-01-17 at 3.38.32 PM.png
For this application, I used the constraint layout, Chronometer, ListView, and two Buttons. I went with a listview since it is easy to set constraints regardless of the device size. The chronometer seemed like a logical choice over Date since it had methods for starting and stopping. The start and stop buttons I placed at the bottom and placed colors so that it is easy to discern the differences at a glance.

Code

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Chronometer;
import android.os.SystemClock;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
   private Chronometer stopwatch;
   private List<String> timeList;
   private ListView timeElapsedList;
   private boolean timerStart = false;
   private ArrayAdapter<String> listAdapter;
   private int lapCount = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //sets up layout
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // setting stopwatch to chronometer
        stopwatch = findViewById(R.id.timeElapsed);

        //setting up listview
        timeList = new ArrayList<String>();
        timeElapsedList = (ListView) findViewById(R.id.timeListView);
        listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, timeList);
        // DataBind ListView with items from ArrayAdapter
        timeElapsedList.setAdapter(listAdapter);
    }

    public void startButton(View view) {
        // resets the start time
        stopwatch.setBase(SystemClock.elapsedRealtime());
        // starts the chronometer
        stopwatch.start();
        timerStart = true;
    }

    public void stopButton(View view) {
        stopwatch.stop();
        // if the start was pressed prior then stop process begins
        if (timerStart) {
            lapCount++;
            timeList.add("Lap " + lapCount + ": " +stopwatch.getText().toString());
            listAdapter.notifyDataSetChanged();
            stopwatch.setBase(SystemClock.elapsedRealtime());
            timerStart = false;
        }
    }

This was the first time I used the chronometer, I was originally going to use a Date variable but soon ran into some trouble. Using a Date variable I could measure the exact time elapsed; however, creating a visual transition of the time elapsed on the UI was difficult. I then picked the chronometer and my code was able to slim down since the methods the widget had been just what I needed.

Porting to the Store:

This was fairly easy to launch to the market since it did not use location or any other information from the user. In the future, I would like dive deeper into the Beta and Alpha testing processes in the Play Console.

Conclusion:

It was a fun simple project and I am definitely excited to do more projects like this!

If you are reading this and have any suggestions please message or comment. 😀

General Topics 👨🏽‍💻

I am starting pages with general topics these will have more content then general web posts. The pages can be found on the sidebar of the blog and so far include topics like algorithms and Data Structures. Android Dev and other topics will soon follow! 🙂

Super AI Bros. ep.101

Last night I decided to take create a Mario AI. Yeah, I know it’s been done plenty of times, but hey, I program because of its fun! I am using an emulator to test my AI since making my own version of Mario, although incredibly fun, is something I don’t have time for. This project is mostly for me to dive deeper into python and ai. The goal will eventually be to create a more general AI so to play most 80s emulated 2d side scrollers.

A few things that I first learned:

How to use selenium to automate opening the chrome.

I also am learning how to automate key presses with python and seeing exactly how it interacts with the physics of this emulator.

project link: github.com/amsuarez01/marioai