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 / basic.c
Last active February 15, 2019 08:14
Simple C code template
#include <stdio.h>
int main(void) {
printf("Hello");
return 0;
}
@karellism
karellism / Divisibility.java
Last active February 15, 2019 08:42
TRUE or FALSE is Divisible by 7?
/******************************************************************************
*
* Reads in two integer command-line arguments x and y and prints "true"
* if both are divisible by 7, and false otherwise.
*
* a % 7 is the remainder when you divide 7 into a. If the remainder
* is 0, then a is divisible by 7.
*
******************************************************************************/
@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) {
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 / NumericInput.java
Last active June 2, 2019 22:22
Reading numeric values
// Demonstrates reading numeric values.
// From http://www.cs.utexas.edu/users/ndale/Scanner.html
// Class NumericInput demonstrates reading numeric values.
import java.util.Scanner;
import java.io.*;
public class NumericInput {
public static void main(String[] args) {
// Declarations
@karellism
karellism / cloudSettings
Last active November 29, 2020 06:24
Insert between html body tags to display simpleCMS class - php file
{"lastUpload":"2020-11-29T06:23:58.885Z","extensionVersion":"v3.4.3"}
@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>
@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 / 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 / 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>