Skip to content

Instantly share code, notes, and snippets.

View karellism's full-sized avatar
:electron:
Educating myself

Karel Vanhelden karellism

:electron:
Educating myself
  • Karellism
  • karelvanhelden@gmail.com
View GitHub Profile
@karellism
karellism / SimpleCMS.php
Created November 1, 2015 02:34
Code template for a simple CMS - php class
<?php
class simpleCMS {
var $host;
var $username;
var $password;
var $table;
public function display_public() {
@karellism
karellism / buildDB.php
Created November 1, 2015 02:37
Create a database for the simple CMS - php file
private function buildDB() {
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS testDB (
title VARCHAR(150),
bodytext TEXT,
created VARCHAR(100)
)
MySQL_QUERY;
return mysql_query($sql);
@karellism
karellism / connectDB.php
Created November 1, 2015 02:38
Connect to database for simple CMS - php file
public function connect() {
mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
return $this->buildDB();
}
@karellism
karellism / BuildForm.php
Created November 1, 2015 02:39
Build the Form for simple CMS - php file
public function display_admin() {
return <<<ADMIN_FORM
<form action="{$_SERVER['PHP_SELF']}" method="post">
<label for="title">Title:</label>
<input name="title" id="title" type="text" maxlength="150" />
<label for="bodytext">Body Text:</label>
<textarea name="bodytext" id="bodytext"></textarea>
<input type="submit" value="Create This Entry!" />
</form>
@karellism
karellism / writeToDB.php
Created November 1, 2015 02:40
Saving the data to the database for simple CMS - php file
public function write($p) {
if ( $p['title'] )
$title = mysql_real_escape_string($p['title']);
if ( $p['bodytext'])
$bodytext = mysql_real_escape_string($p['bodytext']);
if ( $title && $bodytext ) {
$created = time();
$sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')";
return mysql_query($sql);
} else {
@karellism
karellism / displayDataFromDB.php
Created November 1, 2015 02:42
Displaying the data from the simple CMS database - php file
public function display_public() {
$q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 3";
$r = mysql_query($q);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$title = stripslashes($a['title']);
$bodytext = stripslashes($a['bodytext']);
$entry_display .= <<<ENTRY_DISPLAY
@karellism
karellism / SimpleCMS.html
Created November 1, 2015 02:43
Plain html page for using Simple CMS class - html file
<!DOCTYPE html>
<html lang="en">
<head>
<title>SimpleCMS</title>
</head>
<body>
</body>
import java.io.*;
import java.util.Scanner;
public class MixedTypeInput {
public static void main(String[] args) {
double number;
Scanner in = new Scanner(System.in);
System.out.println("Enter your gross income: ");
@karellism
karellism / LocalHostName.java
Created December 30, 2015 01:27
LocalHostName.java
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostnameExample {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
} catch (UnknownHostException e) {
@karellism
karellism / codeforcestemplate.cpp
Last active February 15, 2019 08:12
CodeForces C++ Template
/*
* Karellism - Karel Vanhelden
* Problem ??
*/
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for(auto i=0; i<(n); i++)