Skip to content

Instantly share code, notes, and snippets.

@taboularasa
taboularasa / parsexml.py
Created March 27, 2009 06:34
parse an opml file and print out a txt file with one feed url per line
import sys
from elementtree.ElementTree import ElementTree
f = open('feeds.txt', 'w')
root = ElementTree(file=sys.argv[1])
#Create an iterator
thisIter = root.getiterator()
#Iterate
for element in thisIter:
for n in element.items():
if n[0] == 'xmlUrl':
@taboularasa
taboularasa / Moveable.java
Created April 2, 2009 17:58
Week 1 from DMA 152BC: Objects and Interfaces
interface Moveable {
int moveX(int x);
int moveY(int y);
}
@taboularasa
taboularasa / DefineThingable.java
Created April 8, 2009 20:28
Week 2 from DMA 152BC: Define Thingable
Thingable thing;
void setup() {
thing = createThingable();
}
void draw() {
}
void markov()
{
countInComingSequence();
buildNewSequence();
}
void countInComingSequence()
{
//we need to know how many times each pattern appears so we can divide transitions by it later
//first clear out wordOccurenceSum
@taboularasa
taboularasa / ResizeArray.java
Created May 19, 2009 14:23
Reallocates an array with a new size, and copies the contents of the old array to the new array.
/**
* Reallocates an array with a new size, and copies the contents
* of the old array to the new array.
* @param oldArray the old array, to be reallocated.
* @param newSize the new array size.
* @return A new array with the same contents.
*/
private static Object resizeArray (Object oldArray, int newSize) {
int oldSize = java.lang.reflect.Array.getLength(oldArray);
Class elementType = oldArray.getClass().getComponentType();
@taboularasa
taboularasa / HttpRequest.java
Created May 19, 2009 14:24
Send HTTP request & fetching data using Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL my_url = new URL("http://www.viralpatel.net/blogs/");
BufferedReader br = new BufferedReader(new InputStreamReader(my_url.openStream()));
String strTemp = "";
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
@taboularasa
taboularasa / ArrayToMap.java
Created May 19, 2009 14:26
Convert Array to Map in Java
import java.util.Map;
import org.apache.commons.lang.ArrayUtils;
public class Main {
public static void main(String[] args) {
String[][] countries = { { "United States", "New York" }, { "United Kingdom", "London" },
{ "Netherland", "Amsterdam" }, { "Japan", "Tokyo" }, { "France", "Paris" } };
Map countryCapitals = ArrayUtils.toMap(countries);
@taboularasa
taboularasa / ParseXML.java
Created May 19, 2009 14:27
Parsing / Reading XML file in Java
package net.viralpatel.java.xmlparser;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@taboularasa
taboularasa / Zip.java
Created May 19, 2009 14:28
Creating ZIP and JAR Files in Java
import java.util.zip.*;
import java.io.*;
public class ZipIt {
public static void main(String args[]) throws IOException {
if (args.length < 2) {
System.err.println("usage: java ZipIt Zip.zip file1 file2 file3");
System.exit(-1);
}
File zipFile = new File(args[0]);