Skip to content

Instantly share code, notes, and snippets.

@Battleroid
Battleroid / Iterate.rb
Last active December 16, 2015 00:18
Learning bits and bobs of Ruby.
#!/usr/bin/ruby
names = ["Spooky", "Elise", "Cinder", "Checkers", "Peaches"]
for x in 0...names.length
if names[x] == "Elise"
print names[x], " is a dog\n"
else
print names[x], "\n"
end
end
@Battleroid
Battleroid / Mapping-file.cpp
Last active December 16, 2015 06:19
Simple exercise for myself to find out how to use maps properly, adding elements to it, and then displaying the contents. Love the fact that the output is alphabetized already! This is simply cool as shit. Second part is a revision that gets words from space delimited file and then adds items to the map.
#include <iostream>
#include <vector>
#include <map>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
// split space delimited string and return vector
vector<string> makeList(string input) {
@Battleroid
Battleroid / Encrypt.java
Created April 19, 2013 23:03
Types of ROT for java, one is ROT9 for letters. Other is for numbers (?).
import java.util.Scanner;
public class Encrypt {
public static void main(String[] args) {
// Lower a-z: 97-122; Higher A-Z: 65-90; Numbers 48-57 (0-9)
Scanner input = new Scanner(System.in);
System.out.printf("Encrypt:\t\t");
// nextLine is crucial, without it, it will only read the first word, not the entire string (including spaces)
String phrase = input.nextLine();
@Battleroid
Battleroid / BufferBuilder.java
Created April 19, 2013 23:04
Old class exercise for a class to count words, letters, recognized words from a simple array, reverse, and letter/vowel usage.
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;
public class BufferBuilder {
public static void main(String[] args) {
// Initialize variables
String defaultParagraph = "Welcome to the Fall 2012 semester. We are learning object oriented programming in CSCI 1302.";
// Call methods
@Battleroid
Battleroid / SimpleWordProcessor.java
Last active December 16, 2015 10:58
Another old class exercise of which does ROT encryption & decryption, counts makeup, and etc.
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SimpleWordProcessor {
public static void main(String[] args) {
String phrase = "Welcome to the Fall 2012 Semester. We are learning Object-Oriented Programming in CSCI 1302.";
@Battleroid
Battleroid / DataStreams.java
Last active December 16, 2015 10:58
Old class exercise for counting words, prepositions, articles, and etc from the State of the Union address (2011). Quite a bit of comments...
package Union;
import java.io.*;
import java.util.*;
import java.util.regex.*;
// need method for counting [tT]he, need to replace word counting method with more efficient counter (see countPreps)
public class DataStreams {
public static void main(String[] args) throws IOException {
@Battleroid
Battleroid / WordChecker.java
Created April 19, 2013 23:14
Old class exercise. Used GUI and user defined dictionary to check for incorrect words against a sentence.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.*;
@Battleroid
Battleroid / GUI.java
Created April 19, 2013 23:16
Old class exercise/sample for file I/O.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUI extends JFrame {
JTextArea textToFile;
GUIFileIO fileWriter;
@Battleroid
Battleroid / TextEditor.java
Last active December 16, 2015 10:58
Old experimentation with GUI in java.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class TextEditor extends JFrame {
public TextEditor() {
@Battleroid
Battleroid / OutputGUI.java
Created April 19, 2013 23:17
Old class sample exercise.
import javax.swing.*;
public class OutputGUI extends JPanel{
private String message = "Hello";
private JTextArea outMessage = new JTextArea(message, 20, 50);
public OutputGUI(){
outMessage.setWrapStyleWord(true);