Skip to content

Instantly share code, notes, and snippets.

View timpulver's full-sized avatar

Tim Pulver timpulver

View GitHub Profile
@timpulver
timpulver / randomImage.php
Created March 19, 2012 19:16
Displays a random image
/*
Am Anfang müssen die Dateinamen im script gespeichert werden. Dazu nehme ich der Einfachheitshalber ein Array namens $bild. Die Funktion mt_rand() liefert eine Zufallszahl im Bereich unteres Array (also unterer Anzahl der eingetragenen Bilder). Mit der letzten Zeile wird der Wert aus dem Array $bild per PHP-Befehl "echo" in den HTML-Code geschrieben.
Um das Ganze nun nutzen zu können, musst du auf deinem Server diesen Quellcode in eine Datei mit der Endung .php speichern (sonst interpretiert der Server den Quelltext nicht als PHP). Wichtig dabei natürlich, dass dein Server überhaupt PHP installiert hat. Sollte aber mittlerweile überall Standard sein.
*/
<?PHP
// Hier kommen die dateinamen untereinander
$bild[] = "header1.jpg";
@timpulver
timpulver / stringToCharPtr.cpp
Created March 19, 2012 19:24
String in char* konvertieren (CPP)
// String definieren
string s1("Ein Text");
// Zeichen aus String in char-Feld umkopieren
char charArray[40];
// string.c_str() liefert char*
strcpy(charArray,s1.c_str());
@timpulver
timpulver / randomInt.cpp
Created March 19, 2012 19:26
Create a random number between grA and grB (CPP)
srand ( time(NULL) );
int grA, grB;
grA = 0; grB = i;
int a;
a = grA + (rand() % (grB - grA + 1));
@timpulver
timpulver / deleteFile.cpp
Created March 19, 2012 19:27
Delete a file (CPP)
#include <stdio.h>
int remove(const char *filename);
@timpulver
timpulver / directoryExists.cpp
Created March 19, 2012 19:28
Check if a directory exists (CPP)
bool DirectoryExists( const char* pzPath ){
DIR *pDir;
bool bExists = false;
pDir = opendir (pzPath);
if (pDir != NULL){
return true;
}
return false;
}
@timpulver
timpulver / stringCompare.cpp
Created March 19, 2012 19:31
Compare two Strings
// returns 0 if equal
stricmp(str1, str2);
@timpulver
timpulver / readFile.cpp
Created March 19, 2012 19:32
Read a textfile line after line
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
ifstream f; // Datei-Handle
string s;
f.open(argv[1], ios::in); // Öffne Datei aus Parameter
@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);
@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 / 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);
}