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
/* | |
JavaScript Caesar shift | |
by Evan Hahn (evanhahn.com) | |
"Encrypt" like this: | |
caesarShift('Attack at dawn!', 12); // Returns "Mffmow mf pmiz!" | |
And "decrypt" like this: |
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
// Start Express | |
const express = require("express"); | |
const app = express(); | |
// Set the view directory to /views | |
app.set("views", __dirname + "/views"); | |
// Let's use the Pug templating language | |
app.set("view engine", "pug"); |
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
-- to start SQLite3 (worked on my Mac and on CAEN)... | |
-- sqlite3 sailors.db | |
-- to run this file in SQLite3... | |
-- .read this_filename.sql | |
drop table if exists Sailors; | |
create table Sailors ( | |
sid integer primary key, | |
name varchar(100), |
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
--[[ | |
TIC-TAC-TOE | |
by Evan Hahn (http://www.evanhahn.com/) | |
This is a program that allows you to play tic-tac-toe against the | |
computer. | |
You may change the configuration (below) to make the board more than 3x3, | |
or play with "white" and "black" instead of "x" and "o", and change how |
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
# Non-destructive quicksort. | |
# DOESN'T WORK WITH DUPLICATES. Too lazy. | |
# [1, 5, 8, 12].quickSort() | |
Array::quickSort = -> | |
# Is the array already sorted by nature of its length? | |
return this if @length <= 1 | |
# Pick a pivot as a random element. | |
# This is probably not the best pivot we could choose. |
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
# Non-destructive merge sort. | |
# [1, 8, 12, 5].mergeSort() | |
Array::mergeSort = -> | |
# If the array has one element, we're done. | |
return this if @length is 1 | |
# Split the array in half. | |
halfwayMark = Math.floor(@length / 2) | |
firstHalf = @slice(0, halfwayMark) |
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
/* *************************** | |
EULER METHOD CALCULATOR | |
by Evan Hahn (evanhahn.com) | |
*************************** | |
This will use the Euler method to estimate values of a differential | |
equation. | |
Code licensed under a CC-BY 3.0 license: | |
http://creativecommons.org/licenses/by/3.0/ */ |
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
var express = require("express"); | |
var onHeaders = require("on-headers"); | |
var path = require("path"); | |
var app = express(); | |
// ... | |
app.use(function(req, res, next) { | |
onHeaders(res, function() { |
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
var connect = require('connect') | |
var csp = require('helmet-csp') | |
var app = connect() | |
app.use(csp({ | |
directives: { | |
mediaSrc: ['media.example.com'] | |
} | |
})) |
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
connect = require 'connect' | |
app = connect() | |
# find-replace "connect" with "express" and req.secure will be a boolean rather than undefined. | |
app.use (req, res) -> | |
res.setHeader 'Content-Type', 'text/plain' | |
res.end "Secure: #{req.secure}" | |
app.listen(5000) |
NewerOlder