Skip to content

Instantly share code, notes, and snippets.

server = ServerSocket new() : ServerSocket
---------------------------------------------------------------
ERROR No such function accept(Int, SockAddr*, UInt*)
conn := accept(descriptor, addr&, addrSize&)
^^^^^^
Nearest match is:
accept: func (s : Int, addr : SockAddr*, addrlen : UInt) -> Int
..but the type of this arg should be UInt (lang/types [23951, 23955]), not UInt* (lang/types [23951, 23955])
5 4 1 + = [ "5 = 5, YAY!" ] [ ":(" ] if
import Data.List
main = print $ length . filter (\x -> sum x `elem` a) . filter (\x -> length x > 1) $ subsequences a
where a = [3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99]
str = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesed
require "prime"
fib = Fiber.new do
x, y = 0, 1
loop do
Fiber.yield y
x,y = y, x+y
end
end
def uncipher(str)
1.upto(26) do |shift|
key = Hash[('a'..'z').zip((97..122).collect{ |i| if (i+shift > 122) then ((i + shift) % 122) + 96 else i+shift end })].merge({' '=>' '.ord,','=>','.ord,'.'=>'.'.ord,'?'=>'?'.ord,'!'=>'!'.ord})
freqs = Hash.new(0)
tmp = str.split('').collect { |letter| switched = (key[letter]).chr; freqs[switched] += 1; switched }
total = 0
freqs.each { |e| total += e[1] }
puts tmp.join if freqs['e']/total.to_f * 100 > 7 and freqs['t']/total.to_f * 100 > 5 # Might want to eventually make more accomodating
end
end
@pheuter
pheuter / remove_all_gems.sh
Created November 12, 2010 00:13
Concurrently uninstalls all ruby gems
gem list | ruby -e "while line = STDIN.gets do puts line[/([\w_-]+)/,1] end" | parallel gem uninstall
@pheuter
pheuter / peculiar.rb
Created November 29, 2010 20:56
Guess what happens...
def f(*x) {:f=>->(o){p o}}[:f][x*", "] end
f 'Hello', gets
@pheuter
pheuter / merge.js
Created November 30, 2010 18:12
Javascript implementation of merge assignment
// ~ 3 loc
var puts = require('sys').puts;
function merge (a1, a2) {
var merged = [];
while(a1 && a2 != '') merged.push(a1[0] <= a2[0] ? a1.shift() : a2.shift());
return merged.concat(a1 != '' ? a1 : a2);
}
@pheuter
pheuter / merge.m
Created November 30, 2010 18:13
Objective C implementation of merge assignment
// ~ 27 loc
#import <Foundation/Foundation.h>
@interface Main : NSObject
{
NSMutableArray *a1, *a2, *merged;
}
@property(nonatomic, assign) NSMutableArray *a1, *a2, *merged;