Skip to content

Instantly share code, notes, and snippets.

#!/usr/local/bin/ruby
require 'socket'
class File
def self.binary?(name)
myStat = stat(name)
return false unless myStat.file?
open(name) { |file|
blk = file.read(myStat.blksize)
#include <iostream>
#include <vector>
#include <sstream>
#include <cctype>
using std::isalnum;
using std::isalpha;
using std::isdigit;
using std::isxdigit;
#define push(n) stack.push_back(n)
require 'rubygems'
require 'sinatra'
require 'gopherclient'
$types ={
"0"=>"TXT",
"1"=>"DIR",
"2"=>"CSO",
"3"=>"ERR",
"4"=>"HEX",
class GopherClient
def parseurl(url)
opts=url.sub('gopher://','').split('/') # split the url by slashes
host=opts.shift # the first element will be our host
type=opts.shift # type is second
if !@types.has_key?(type) then # check to see if a type was provided
opts.unshift(type) # if not, then its part of the path, put it back
puts "No type given, assuming 1" # tell them the error of their ways
type="1" # and assume its a directory
end
#!/usr/bin/perl
package GopherScript;
sub new
{
my $class = shift;
my $self = {
hostname => shift,
port => shift,
mode => "dir",
#!/usr/local/bin/ruby
require "open-uri"
id=ARGV[0]
if !id then
puts "No id given"
else
begin
puts open("http://gist.github.com/#{id}.txt").read
rescue
def fib(n)
if n == 0 || n == 1
n
else
fib(n - 1) + fib(n - 2)
end
end
if $0 == __FILE__
36.times do |i|
public class fib {
public static int fib(int n) {
if (n <= 1) {return n;}
return fib(n-1) + fib(n-2);
}
public static void main(String[] args) {
for (int i = 0; i < 36; i++)
System.out.println("n = " + i + " => " + fib(i));
(defun fib (n)
(if(or (= 0 n) (= 1 n)) n
(+ (fib (- n 1)) (fib (- n 2)))))
(defun start ()
(loop for x from 0 to 35 collect
(format t "n = ~d => ~d~%" x (fib x))))
(start)
(quit)
#! /usr/bin/mzscheme
#lang scheme
(define (fib n)
(if (or (= 0 n) (= 1 n)) n
(+ (fib (- n 1)) (fib (- n 2)))))
(let runfib ((i 0))
(unless (= i 36)
(display (string-append "n = " (number->string i) " => " (number->string (fib i)) "\n"))
(runfib (+ i 1))))