[ create a new paste ] login | about

jleedev

Name:
Email:
Site/Blog:
Location:
Default language: Haskell
Favorite languages: Haskell,Python,Scheme
About: I <3 codepad

Saved pastes by jleedev:

Haskell, pasted on Feb 10:
1
2
3
4
import List(genericReplicate)
fibs=1:1:zipWith(+)fibs(tail fibs)
ggg=map(`genericReplicate`'g')fibs
main=mapM_ putStrLn ggg
view (4 lines, 22 lines of output)
Ruby, pasted on Jan 5:
1
2
3
4
5
class Spam
  def self.[] x
    puts "Spam.[] #{x}"
  end
end
...
view (12 lines, 2 lines of output)
Ruby, pasted on Sep 27:
1
2
3
4
5
def method_missing *args
  puts args.join ' '
  yield if block_given?
  args
end
...
view (12 lines, 12 lines of output)
Scheme, pasted on Sep 16:
1
2
3
4
5
(define-syntax 
  (syntax-rules ()
    (( a b) (λ a b))))
(print ((
                                       
...
view (7 lines, 1 line of output)
Haskell, pasted on Oct 20:
1
2
3
import List
r=genericReplicate
main=mapM print$do a<-[1..];b<-[1..a];[r a 'f'++r b 'u']
view (3 lines, 652 lines of output)
Python, pasted on Oct 20:
1
2
3
u = ''.join(map(unichr, [1505, 1500, 1511, 1493, 1501]))
s = u.encode('utf-8')
print s.decode('cp1255', 'replace').encode('utf-8')
view (3 lines, 1 line of output)
Haskell, pasted on Oct 19:
1
2
3
4
5
qux=map('q':)ux
u:ux=iterate('u':)"x"
vars="foo":"bar":"baz":qux
p(v:ars)=putStrLn v>>p ars
main=p vars
view (5 lines, 234 lines of output)
C++, pasted on Oct 11:
1
2
3
4
5
#include <cstdio>

void foo(unsigned short x)
{
 puts("x is a unsigned short");
...
view (18 lines, 2 lines of output)
Python, pasted on Jul 21:
1
2
3
4
5
import pickle

__name__ = 't'

class Spam(object):
...
view (10 lines, 34 lines of output)
Ruby, pasted on Jul 19:
1
2
3
4
5
require 'digest/sha1'
sha1 = ['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'].pack 'H*'
contents = "100644 a.txt\0#{sha1}100644 b.txt\0#{sha1}"
data = "tree #{contents.length}\0#{contents}"
p Digest::SHA1.hexdigest(data)
view (5 lines, 1 line of output)
Ruby, pasted on Jul 15:
1
2
3
4
5
[:zero?, :one?, :two?, :three?, :four?, :five?].each_with_index do |x,i|
  Integer.send(:define_method, x) { self == i }
end

p 0.zero?
...
view (7 lines, 3 lines of output)
Python, pasted on Jul 1:
1
2
3
4
5
from collections import defaultdict


def T():
    return defaultdict(lambda:T())
...
view (28 lines, 1 line of output)
Python, pasted on Jun 20:
1
2
3
4
5
# You can use the yield statement to create a generator...

def iter_function():
    yield 'hello'
    yield 'world'
...
view (40 lines, 7 lines of output)
Python, pasted on Jun 20:
1
2
3
4
5
def f():
    print "lol"
    yield "nope"

f()
view (5 lines)
Python, pasted on Apr 29:
1
2
3
4
5
def binomial(n):
    result = 1
    yield result
    for i in xrange(1,n+1):
        result *= (n-i+1)
...
view (8 lines, 201 lines of output)
Ruby, pasted on Apr 26:
1
2
3
4
5
p = method   :p
p             p
3.times      &p
0.upto 2,    &p
(0..2).each  &p
...
view (6 lines, 13 lines of output)
Haskell, pasted on Mar 14:
1
2
3
4
5
import Char (intToDigit)
import Numeric (showIntAtBase)
import Data.Word

cletus :: Word8 -> Word8
...
view (16 lines, 32 lines of output)
Haskell, pasted on Mar 5:
1
2
3
4
5
import List
import Control.Monad
import Control.Arrow
collatz 1 = Nothing
collatz n = Just . join (,) $ if even n
...
view (8 lines, 2306 lines of output)
Python, pasted on Feb 21:
1
2
3
4
5
class Spam(object):
    def __call__(self): pass
s = Spam()

print callable(s)
...
view (10 lines, 3 lines of output)
Haskell, pasted on Jan 12:
1
2
3
4
5
data N = Z | S N deriving (Ord,Eq,Show)
instance Num N where
        x + Z = x
        x + (S y) = S (x + y)
        fromInteger 0 = Z
...
view (9 lines, 1 line of output)
Ruby, pasted on Jan 7:
1
2
3
4
puts VERSION

class Spam
end
...
view (16 lines, 3 lines of output)
Ruby, pasted on Jan 7:
1
2
3
4
puts VERSION

class QuitRequested < Exception
end
...
view (22 lines, 2 lines of output)
C++, pasted on Dec 10:
1
2
3
4
5
#include <stdlib.h>
#include <assert.h>

class Image {
	const int width, height;
...
view (100 lines)
Plain Text, pasted on Nov 23:
1
2
3
4
5
&v      <
 >:1-:1`|
   >   *v
   |`0:\<
   $
...
view (7 lines)
Haskell, pasted on Nov 20:
1
2
3
4
5
-- I <3 Cale
import Ratio (numerator,denominator)
import List (sort)
posRationals = 1 : (posRationals >>= \x -> [1+x, 1/(1+x)]) :: [Rational]
pyth r = (x,y,z) where m = numerator r; n = denominator r; [x,y,z] = sort [2*m*n, m^2 - n^2, m^2 + n^2]
...
view (7 lines, 2425 lines of output)
Plain Text, pasted on Nov 13:
1
2
3
4
5
try
	tell application "Finder" to set pwd to quoted form of POSIX path of (target of front Finder window as alias)
	tell application "System Events" to set terminalOn to (exists process "Terminal")
	tell application "Terminal"
		if terminalOn then
...
view (15 lines)
Python, pasted on Nov 11:
1
2
3
4
5
from BeautifulSoup import BeautifulSoup
from urllib import urlopen
import sys,re

url = 'http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?servicetag=%s'
...
view (19 lines)
Haskell, pasted on Oct 17:
1
2
3
4
import qualified Data.Map as M
import IO
import List
import Random
...
view (34 lines, 1 line of output)
Python, pasted on Jul 24:
1
2
3
4
5
#!/usr/bin/python

import random
import re
import shutil
...
view (210 lines, 1 comment)
Ruby, pasted on Jul 4:
1
2
3
4
5
#!/usr/bin/env ruby

Dir["*.jpg"].each do |file|
  mm,dd,yy,h,m = [0,3,6,9,11].map { |start| file[start,2] }
  stamp = "20%s-%s-%s %s:%s" % [yy,mm,dd,h,m]
...
view (8 lines)
C++, pasted on Apr 16:
1
2
3
4
5
#include <iostream>
#include <csignal>
#include <cstdlib>
#include <unistd.h>
#include <exception>
...
view (39 lines, 1 line of output)
Ruby, pasted on Apr 16:
1
2
3
4
5
module Enumerable
  def mymap &b
    results = []
    each {|x| results << b[x] }
    results
...
view (9 lines, 1 line of output)
Haskell, pasted on Apr 6:
1
2
import Control.Monad
main = mapM_ print fibs where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
view (2 lines, 594 lines of output)
Haskell, pasted on Feb 13:
1
2
3
4
{-# LANGUAGE EmptyDataDecls #-}

data Z
data S a
...
view (23 lines, 1 line of output)
C, pasted on Feb 3:
1
2
3
4
5
#include <stdio.h>

const unsigned seed = 0x0C;
const unsigned mask = 0x11; 
const unsigned bits = 5;
...
view (21 lines, 1 line of output)
Haskell, pasted on Jan 13:
1
2
3
4
5
class Monoid m where
    mzero :: m
    madd :: m -> m -> m

reduce :: (Monoid m) => [m] -> m
...
view (15 lines, 1 line of output)
Ruby, pasted on Jan 12:
1
2
3
4
5
$sqrt5 = Math.sqrt(5)
$phi = (1+$sqrt5)/2
def fib n
  (($phi**n - (1-$phi)**n) / $sqrt5).to_i
end
...
view (6 lines, 10 lines of output)
Ruby, pasted on Jan 10:
1
2
3
4
5
require 'socket'

sock = TCPSocket::new("localhost", 9000)
loop do
  select([sock,STDIN],nil,nil)[0].each do |x|
...
view (13 lines)
Ruby, pasted on Jan 8:
1
2
3
puts (" "..":").to_a.join + (":".."~").to_a.join
puts ("A".."M").to_a.join + ("M".."Z").to_a.join
puts ("9"..";").to_a.join
view (3 lines, 3 lines of output)
Plain Text, pasted on Jan 7:
1
2
3
4
5
import java.awt.*;
import java.awt.geom.*;

public class ZoomRect {
	/** The size of the physical drawing area.
...
view (62 lines)
Ruby, pasted on Jan 3:
1
2
3
4
5
module Enumerable
  def product
    catch :zero do
      self.inject 1 do |n,i|
        throw :zero,0 if i==0
...
view (12 lines, 1 line of output)
Haskell, pasted on Dec 1:
1
2
import Control.Monad
main = (mapM_ putStrLn . replicateM 4) "01"
view (2 lines, 16 lines of output)
Python, pasted on Nov 18:
1
2
3
4
def take(n, it):
	r = iter(it)
	for i in xrange(n):
		yield r.next()
...
view (13 lines, 10 lines of output)
Haskell, pasted on Nov 3:
1
2
3
4
5
import Ratio

order = 13

newtype F = F Integer deriving (Eq)
...
view (35 lines, 1 line of output)
Haskell, pasted on Sep 2:
1
2
3
4
graycode 1 = [[0],[1]]
graycode (n+1) = map (0:) gn ++ map (1:) (reverse gn) where gn = graycode n

main = mapM_ print (graycode 4)
view (4 lines, 16 lines of output)
Python, pasted on Aug 7:
1
2
3
4
5
import sys

def thue(n):
	t = 0
	while n:
...
view (12 lines, 128 lines of output)
Python, pasted on Aug 7:
1
2
3
4
5
import sys

def thue(n):
	t = 0
	while n:
...
view (12 lines, 1 line of output)
C++, pasted on Jul 30:
1
2
3
4
5
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <utility>
...
view (38 lines, 3 lines of output)
Haskell, pasted on Jul 10:
1
2
3
4
5
import Control.Parallel

-- http://sequence.complete.org/hwn/20080709
forkbomb :: Integer -> ()
forkbomb n = forkbomb (2*n) `par` forkbomb (2*n+1)
...
view (8 lines, 3 lines of output)
C++, pasted on May 2:
1
2
3
4
5
#include <iostream>
#include <sstream>
#include <boost/static_assert.hpp>

#define ASSERT BOOST_STATIC_ASSERT
...
view (48 lines)
Plain Text, pasted on Apr 3:
1
2
3
4
5
mandel()
Prgm
Local x,y,z,c,m
For y,0,76
 For x,0,168
...
view (20 lines)