Skip to content

Instantly share code, notes, and snippets.

View kaydell's full-sized avatar

Kaydell Leavitt kaydell

  • Self
  • Layton, Utah, USA
View GitHub Profile
@kaydell
kaydell / RunAppleScriptInShell.m
Last active December 20, 2015 20:19
Running AppleScripts, from Cocoa by calling the command-line tool, osascript
// This method executes an AppleScript given the source-code, using the command-line tool called osascript
// Note that this is a demo and doesn't do any error-checking yet such as for AppleScript syntax errors
// and AppleScript runtime errors.
+ (void)execute:(NSString *)source
{
@try {
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/osascript"];
NSString *arguments = [NSString stringWithFormat:@"-e %@", source];
[task setArguments:[NSArray arrayWithObjects:arguments, nil]];
import java.util.Scanner;
public class AverageThreeInts {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inputs = 2;
int[] values = new int[3];
@kaydell
kaydell / JScrollPaneStudy.java
Last active December 23, 2015 01:29
This is a study of getting scroll bars to work in Java's Swing API, using a JScrollPane
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
/**
* This class is a study in learning how to get scroll bars to work for a JList using a JScrollPane.
@kaydell
kaydell / BackgroundImageJFrame
Created September 14, 2013 20:10
An example of setting a background image in a Java Swing JFrame
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.io.File;
/**
* This class is a demo of a background image in a JFrame.
*
* This code was derived from the following source:
@kaydell
kaydell / ForLoopIndexDemo.java
Last active December 23, 2015 02:19
This program is a demonstration of how to correctly declare loop variables for for-loops.
/**
* This class is a demo of how to implement for-loops correctly, declaring the loop variables
* inside of the for-loops, to limit their scope so that the loop variables can't be used outside
* of the loop where the values are too big to be valid array indexes and an ArrayIndexOutOfBoundsException
* is thrown.
*
* @author kaydell
*
*/
public class ForLoopIndexDemo {
@kaydell
kaydell / MessageDialog.java
Last active December 23, 2015 06:59
This is a first Swing window in the tutorial
package lesson01.joptionpane;
import javax.swing.JOptionPane;
public class MessageDialog {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "This is a message dialog");
}
@kaydell
kaydell / BlueJUnitTesting.java
Last active December 23, 2015 17:00
BlueJ JUnit Test Generation
package images;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
@kaydell
kaydell / Matrix.java
Last active December 23, 2015 22:29
Example Java Code for a Matrix which is a two-dimensional array.
/**
* This class demonstrates how to write code that can process a matrix (i.e. a two-dimensional array)
* Note that the method printMatrix will print any two-dimensional array of ints
*
* @author kaydell
*
* Copyright, 2013, Kaydell Leavitt, All Rights Reserved
*
* {link http://simple.wikipedia.org/wiki/Matrix_%28mathematics%29}
*
@kaydell
kaydell / SwingGUIDemo.java
Created September 25, 2013 20:20
Using Multiple Threads With a Swing GUI
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* This class is an example of how to correctly startup a GUI interface
*
* From Oracle's Java Tutorial:
* http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
*
@kaydell
kaydell / python_or_java.py
Last active December 24, 2015 08:49
This gist is a sample of Python code that demonstrates a simpler, easier syntax for beginning programming students to learn more easily. Consider teaching Python for introductory courses, and teaching Java to more advanced students in a more advanced course.
"""
This Python source file demonstrates how Python for-loops
and the main() method are easier for students to understand
than Java is.
About Python: http://www.python.org/about/
Free Python Download: http://www.python.org/download/
It is worth considering teaching beginning students Python
and teach Java in more advanced courses.