Skip to content

Instantly share code, notes, and snippets.

View timpulver's full-sized avatar

Tim Pulver timpulver

View GitHub Profile
@timpulver
timpulver / CallerWithParams.pde
Created September 24, 2012 16:41
[Processing] Reflection Test [Java, Reflection API]
import java.lang.reflect.*;
import java.io.File;
class CallerWithParams{
/**
@param o the object which contains the method to call,
when passing 'this' from within the processing main sketch,
all functions in your main sketch will be recognized
(setup(), draw(),..., custom methods)
@param m the name of the method to call without "()"
@timpulver
timpulver / transparentWindow.java
Last active October 11, 2015 00:48
[Processing 2.0] Create Transparent Window [Java, Frame]
/**
* Author: Tim Pulver
* Date: 2013
* Tested with Processing 2.0
* original code by jungalero (processing.org forum)
*/
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
@timpulver
timpulver / IpFromUrl.java
Created September 24, 2012 15:15
[Java] URL to IP address lookup [host, url, ip, server, convert, conversion]
import java.net.*;
import java.io.*;
public static class IpFromUrl {
// Returns the IP address of an URL
// i.e. http://www.facebook.com -> 123.456.789.10
public static String getIp( String hostname ) throws IOException {
try {
InetAddress ipaddress = InetAddress.getByName(hostname);
System.out.println("IP address: " + ipaddress.getHostAddress());
@timpulver
timpulver / p5_keystroke_simulator.java
Created September 24, 2012 13:05
[Processing] Simulates a key press
import java.awt.AWTException;
import java.awt.Robot;
KeystrokeSimulator keySim;
void setup(){
keySim = new KeystrokeSimulator();
}
void draw(){
@timpulver
timpulver / imgurImageUpload.java
Created August 20, 2012 17:49
Upload an image to image hoster Imgur (can be used for PGraphics, too)
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
@timpulver
timpulver / liveLineOutSignal.pde
Created July 12, 2012 18:06
[P5, Minim] Using live line out signal
/*
* make sure, you have activated stereomix as your recording device in your system settings!
*/
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioInput in;
SineWave sine;
@timpulver
timpulver / getDataDirectory.pde
Created July 12, 2012 16:56
[P5] How to get the DATA directory
//Sometimes we need the path to the Processing data directory.
// creates a virtual file within the data directory
File file = new File(dataPath("") + File.separator + "a_filename.txt");
//using dataPath("..."), the path can be altered, too (when using "", this is not the case).
@timpulver
timpulver / getDateAsInt
Created May 16, 2012 10:15
Returns the current date as Int in this form YYYYMMDD
/*
* Returns the current date as Int in this form YYYYMMDD
*/
int getCurDate(){
String month = String.valueOf(month());
if(month.length() == 1) month = "0" + month();
String day = String.valueOf(day());
if(day.length() == 1) day = "0" + day();
return Integer.parseInt(year() + "" + month + "" + day);
}
@timpulver
timpulver / RunExternalProgram.java
Created March 28, 2012 09:53
How to run an external program and get the return value
//Execute external program and get the return value
// Params have to be stored inside a string array
String[] params = {"cmd.exe", "/c", "dir"};
Process process = Runtime.getRuntime().exec(params);
// Don't forget to close all streams!
process.getErrorStream().close();
process.getInputStream().close();
process.getOutputStream().close();
@timpulver
timpulver / searchFile.cpp
Created March 19, 2012 19:36
Searches for a file (CPP, Win)
void CFile::search(fstream &FS) {
char savepath[MAX_PATH]; // zur Zwischenspeicherung des Pfades
int len;
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
strcpy(savepath, path); // Sicherung des Pfades
strcat(path, "\\*");
hFind = FindFirstFile(path, &FindFileData);