Skip to content

Instantly share code, notes, and snippets.

#redirect all traffic to https over ssl with Sinatra
configure :production do
# us a simple before filter to redirect all requests in production to https
# before do
# unless (@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme'])=='https'
# redirect "https://#{request.env['HTTP_HOST']}#{request.env["REQUEST_PATH"]}"
# end
# end
@justjkk
justjkk / knightstour.c
Created October 14, 2010 06:46
Backtracking solution to Knight's Tour problem
// Backtracking solution to Knight's Tour problem http://en.wikipedia.org/wiki/Knights_tour
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
// Constraint: MAXX should be greater than or equal to MAXY
#define MAXX 5
#define MAXY 5
typedef enum {FALSE, TRUE} bool;
int n = 0;
bool treaded_blocks[MAXX][MAXY];
@robertjwhitney
robertjwhitney / tower_of_hanoi.rb
Last active December 13, 2015 18:18
A lesson in recursion
# LETS GET READY TO RECURSE!!!!!!
#
# Tower of Hanoi
#
# You have 4 discs which vary in size from small to large
# There are 3 pegs, A, B, C, respectively
#
# The discs are all currently on peg A, with the largest disc on the bottom,
# and the smallest disc on the top.
#
@sanchojaf
sanchojaf / knights_tour.rb
Last active July 30, 2017 11:30
Knight’s Tour Problem [backtracking, ruby]
# A knight’s tour is a sequence of moves of a knight on a chessboard such that
# the knight visits every square only once. If the knight ends on a square that
# is one knight’s move from the beginning square (so that it could tour the board
# again immediately, following the same path), the tour is closed, otherwise it is open.
class KnightTour
def initialize(n)
@n = n
@path = 0
@board = Array.new(n) { Array.new(n, 0) }