Skip to content

Instantly share code, notes, and snippets.

View speters33w's full-sized avatar

Stephan Peters speters33w

  • Greene, Pennsylvania, USA
  • 08:57 (UTC -04:00)
View GitHub Profile
@speters33w
speters33w / backupmysql.bat
Last active March 4, 2024 21:52
A Windows batch file to demonstrate backing up MySQL databases. An insecure method for example only, not for production.
@echo off
:: To run the batch file, run CMD as administrator,
:: cd to the directory the file is in and enter
:: backupmysql.bat <type the user> <type the user password>
:: 7-Zip installed in default location is a dependency.
:: Use command line arguments as login and password.
set dbUser=%1
set dbPassword=%2
@speters33w
speters33w / TunnelThroughTheStacks.java
Created November 3, 2023 03:34
A corny old-school text-adventure using Java Stacks
import java.util.Scanner;
import java.util.Stack;
public class TunnelThroughTheStacks {
public static void main(String[] args) {
System.out.println("You find yourself alone in a dark tunnel. Water trickles beneath your feet." +
"How you got here, you don't know." +
"Is this a dream? You must go somewhere to get out of this tunnel!\n");
Scanner scanner = new Scanner(System.in);
int counter = 1;
@speters33w
speters33w / GridBagLayoutExample.java
Created October 27, 2023 01:54
An Example of the Grid Bag Layout in Java
/* Modified from Listing 10-1 in
The Definitive Guide to Java Swing
by John Zukowski.
*/
import java.awt.*;
import javax.swing.*;
public class GridBagLayoutExample {
private static final Insets insets = new Insets(0, 0, 0, 0);
@speters33w
speters33w / DogHuman.java
Created October 10, 2023 01:26
A silly inheritance and polymorphism example.
public class DogHuman extends SuperHuman {
public DogHuman(String name, int age) {
super(name, age);
}
@Override
public String greet() {
return "Woof woof, woof woof, woof woof, woof woof, woof woof";
}
@speters33w
speters33w / ArraysSample.java
Last active September 15, 2023 01:42
Simple example of converting an Arraylist to a String array and String array to an ArrayList and "adding" an element to a String array
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ArraysSample {
public static void main(String[] args) {
List<String> list = new ArrayList<>(); // Create an ArrayList of Strings
list.add("CSU"); // Add a String to the ArrayList
list.add("Global"); // Add a String to the ArrayList
System.out.printf("%s%n", list.toString()); // Print the ArrayList [CSU, Global]
@speters33w
speters33w / Periodic Table of Elements.csv
Last active August 31, 2023 19:34 — forked from robertwb/Periodic Table of Elements.csv
Multiple additions and corrections.
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 28 columns, instead of 7. in line 5.
AtomicNumber,Element,Symbol,AtomicMass,NumberOfNeutrons,NumberOfProtons,NumberOfElectrons,Period,Group,Phase,Radioactive,Natural,Metal,Nonmetal,Metalloid,Type,AtomicRadius,Electronegativity,ionizationEnergy,Density,MeltingPoint,BoilingPoint,stableIsotopes,Discoverer,Year,SpecificHeat,NumberOfShells,NumberOfValence
1,Hydrogen,H,1.008,0,1,1,1,1,Gas,,yes,,yes,,Non-Metal,120,2.20,13.5984,0.000090,13.81,20.28,2,Henry Cavendish,1766,14.304,1,1
2,Helium,He,4.003,2,2,2,1,18,Gas,,yes,,yes,,Noble Gas,140,,24.5874,0.000179,0.95,4.22,2,Pierre Janssen - Norman Lockyer and Edward Frankland,1868,5.193,1,2
3,Lithium,Li,7.000,4,3,3,2,1,Solid,,yes,yes,,,Alkali Metal,182,0.98,5.3917,0.534000,453.65,1615.00,2,Johan August Arfvedson - isolated Robert Bunsen and Augustus Mathhiesen,1817,3.582,2,1
4,Beryllium,Be,9.012,5,4,4,2,2,Solid,,yes,yes,,,Alkaline Earth Metal,153,1.57,9.3227,1.850000,1560.00,2744.00,1,Nicholas Louis Vauquelin - isolated Friedrich Wöhler and Antoine A. Bussy [independently],1797,1.825,2,2
5,Boron,B,10.810,6,5,
@speters33w
speters33w / DivisibleByThree.java
Created September 19, 2022 02:12
My answer to mooc.fi java Programming exercise 2_26: Divisible by three
/*
Write a method public static void divisibleByThreeInRange(int beginning, int end)
that prints all the numbers divisible by three in the given range.
The numbers are to be printed in order from the smallest to the greatest.
public static void main(String[] args) {
divisibleByThreeInRange(3, 6);
}
Sample output
@speters33w
speters33w / RepeatingBreakingAndRemembering.java
Created September 19, 2022 01:20
My solution to Helsinki mooc.fi java Programming exercise: 2_20 Repeating, breaking and remembering
import java.util.ArrayList;
import java.util.Scanner;
public class RepeatingBreakingAndRemembering {
public static void main(String[] args) {
// This exercise is worth five exercise points, and it is
// gradually extended part by part.
@speters33w
speters33w / CurlDownload.java
Created September 19, 2022 00:46
wget replacement, allows command line download using curl with the format: download https://central.github.com/setup.msi
import java.io.FileWriter;
import java.io.IOException;
/**
* Creates a temporary batch file to run curl to download files.
* uses the url from args for the command.
* This file must be compiled in a class (c:\batch\CurlDownload.class)
* to work with the download.bat file.
*/
public class CurlDownload {
@speters33w
speters33w / Security.java
Last active September 5, 2022 22:00
Security - My solution to the SoloLearn "Security" code coach, allows for more than one thief
import java.util.Random;
import java.util.Scanner;
public class Security {
public static void main(String[] args) {
//runServerTests();
randomFloor();
}
/**