Skip to content

Instantly share code, notes, and snippets.

@EvanHahn
EvanHahn / gist:2587465
Last active October 9, 2023 01:26
Caesar shift in JavaScript
/*
JavaScript Caesar shift
by Evan Hahn (evanhahn.com)
"Encrypt" like this:
caesarShift('Attack at dawn!', 12); // Returns "Mffmow mf pmiz!"
And "decrypt" like this:
@EvanHahn
EvanHahn / app.js
Last active September 29, 2023 14:14
Do you love anime?
// 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");
-- 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),
@EvanHahn
EvanHahn / gist:1135851
Created August 10, 2011 01:46
Tic Tac Toe in Lua. Free license.
--[[
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
@EvanHahn
EvanHahn / quicksort_nodupes.coffee
Created October 11, 2012 17:37
CoffeeScript quicksort with tests
# 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.
@EvanHahn
EvanHahn / mergesort.coffee
Created October 11, 2012 04:16
CoffeeScript merge sort with tests
# 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)
@EvanHahn
EvanHahn / euler_method_calculator.cpp
Created August 21, 2011 08:33
Euler Method calculator
/* ***************************
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/ */
@EvanHahn
EvanHahn / gist:38f08f40a23e0cb9f4b0
Created September 5, 2014 19:20
Disabling some headers set by Express's static middleware.
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() {
var connect = require('connect')
var csp = require('helmet-csp')
var app = connect()
app.use(csp({
directives: {
mediaSrc: ['media.example.com']
}
}))
@EvanHahn
EvanHahn / app.coffee
Created December 4, 2013 15:34
req.secure is undefined in Connect apps
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)