Skip to content

Instantly share code, notes, and snippets.

View benhoskings's full-sized avatar

Ben Hoskings benhoskings

View GitHub Profile
#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);
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(',')
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
/* GHC_PACKAGES base rts
*/
#include "Stg.h"
#include "HsBase.h"
EI_(base_GHCziShow_zdf17_closure);
EI_(base_GHCziShow_zdf13_closure);
static StgWord rtZ_srt[] = {
(W_)&base_GHCziShow_zdf17_closure, (W_)&base_GHCziShow_zdf13_closure
};
var handle_list_link = function() {
// Get the currently displayed element in the list, if there is one
var cur = $(this).parents('ul.list:first').children('li.cur');
var cur_clicked = $(this).is('.cur');
// If there is a current element, hide it
if (cur.length != 0) {
cur.removeClass('cur')
.children('a.cur').removeClass('cur')
.siblings('.data:visible').hide('drop', {direction: 'down'});
$(function() {
// Load JS-dependent CSS
$(document.createElement('link'))
.attr({type: 'text/css', href: '/stylesheets/js.css', rel: 'stylesheet', media: 'screen'})
.appendTo($('head'));
});