Skip to content

Instantly share code, notes, and snippets.

View benhoskings's full-sized avatar

Ben Hoskings benhoskings

View GitHub Profile
class Object
def metaclass
class << self; self; end
end
end
module CannedScopes
def self.included base
base.send :extend, ClassMethods
end
<VirtualHost *:80>
ServerName mohole.net
ServerAlias www.mohole.net
DocumentRoot /home/mohole/current/public
<Directory "/home/mohole/current/public/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
rightTriangles = [ (a,b,c) | c <- [1..500], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2]
main = print rightTriangles
puts (1..500).inject([]) {|acc,a|
(1..a).inject(acc) {|acc,b|
(1..b).inject(acc) {|acc,c|
acc << [a, b, c] if (a**2) == (b**2) + (c**2)
acc
}
}
}.map {|triangle| triangle.inspect }.join(',')
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool rightTriangle(int a, int b, int c) {
return a*a == b*b + c*c;
}
void printTriangle(int a, int b, int c, bool printed) {
printf("%s[(%i),(%i),(%i)]", (printed ? "," : ""), a, b, c);
module Enumerable
def sift! &block
ret, keep = partition {|i|
yield i
}
self.replace keep
ret
end
end
#!/bin/bash
iptables="iptables"
# network settings
iface_main="eth0"
iface_vhosts="eth0:0"
ip_main=`ifconfig $iface_main | grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
ip_vhosts=`ifconfig $iface_vhosts | grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
require 'rubygems'
require 'hpricot'
class Requester
def initialize
`touch cookies`
login
end
def login
class Integer
def to_ord
self.to_s + ((10...20) === self ? 'th' : %w{th st nd rd th th th th th th}[int % 10])
end
end
rightTriangles :: [(Int, Int, Int)]
rightTriangles = [ (a,b,c) | c <- [1..100], b <- [1..c], a <- [1..b], a*a + b*b == c*c]
main = print rightTriangles