This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function truncate(string, words) { | |
var max_chars = 6 * parseInt(words); | |
var words_array = string.split(" "); | |
var index = parseInt(words) - 1; | |
var truncated = words_array.slice(0, index).join(" "); | |
if ( truncated.length > max_chars ) { | |
truncated = string.slice(0, max_chars) + "..."; | |
} else if ( truncated === string ) { | |
truncated = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Presence check | |
if ($firstname == '' || $lastname == '' || $street == '' || $suburb == '' || $postcode == '' || $email == '' || $status == '' || $dob == '') { | |
$error = 'Your field is empty'; | |
renderForm($firstname, $lastname, $street, $suburb, $postcode, $email, $status, $dob, $error); | |
// Validate Email | |
} elseif (ereg('\S+@\S+\.\S+', $email) == false) { | |
$error = 'Please enter a valid email address.'; | |
renderForm($firstname, $lastname, $street, $suburb, $postcode, $email, $status, $dob, $error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Validate using a custom URL (external server script) | |
function validates_instance_url( url, attr ) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if ( xhr.readyState === 4 ) { | |
if ( xhr.status !== 200 || xhr.responseText === "false" || xhr.responseText === "0" ) { | |
return false; | |
} else { | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ......................// | |
// Database configuration | |
// ......................// | |
// Establish connection to the MySQLite database file... | |
var db_connection = require("knex")({ | |
client: "sqlite3", | |
connection: { | |
filename: "../blog_database.db" // path to sqlite database we just created | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sqlite3 blog_database.db | |
sqlite3> CREATE TABLE Posts( | |
...> id INTEGER PRIMARY KEY AUTOINCREMENT, | |
...> title VARCHAR(255), | |
...> content TEXT, | |
...> created_at TEXT | |
...> ); | |
sqlite3> .quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Routes | |
var blogRoutes = require("./routes/blog.js"); | |
app.use("/", blogRoutes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require the express library | |
var express = require("express"); | |
var router = express.Router(); | |
router.get("/", function(request, response) { | |
response.render("index", { // "index" is the name of the view file to render (without extension) | |
title: "Welcome to my blog!" // Will be used for the HTML <title> | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require express to handle our http stuff later on. | |
var express = require("express"); | |
// Require EJS - our templating system for views. | |
var ejs = require("ejs"); | |
ejs.open = "<?"; | |
ejs.close = "?>"; // Use javascript in view files with <? ... ?> | |
// Express can be used under the `app` namespace. | |
var app = express(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container">The quick brown fox jumps over the lazy dog.</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def truncate(string, words) | |
# Define the maximum number of characters that can be used before | |
# standard truncation is applied (prevents long words from ruinning HTML). | |
max_chars = 6 * words | |
words_array = string.split(" ") # splits each word into an array ["like", "this"] | |
index = words - 1 # array indexes start at 0, so let's take one number off the words amount. | |
truncated = words_array[0..index].join(" ") | |
return truncated + "..." | |
end |