This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Bits ((.&.)) | |
import Test.QuickCheck (Property, (==>)) | |
prop_bits :: Int -> Property | |
prop_bits n = n > 0 ==> intToBool (n .&. (n - 1)) == not (isPowerOfTwo n) | |
intToBool 0 = False | |
intToBool _ = True | |
isPowerOfTwo :: Int -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap(object): | |
def __init__(self, size): | |
self.num = 0 | |
self.size = size | |
self.data = [None] * size | |
def __repr__(self): | |
return '<Thing: %s>' % (self.data,) | |
def insert(arr, x): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
{-# LANGUAGE TemplateHaskell #-} | |
import Test.QuickCheck ((==>), Property) | |
import Test.QuickCheck.All (quickCheckAll) | |
-- main = interact $ show . checkBalance | |
main = $quickCheckAll | |
checkBalance :: String -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SwapElts where | |
-- If you have to use this function, arrays may be a better choice. | |
swapElts i j ls = [get k x | (k, x) <- zip [0..length ls - 1] ls] | |
where get k x | k == i = ls !! j | |
| k == j = ls !! i | |
| otherwise = x | |
-- This is a nice example of how to efficiently generate test cases. | |
-- A naive approach would have been to take separate arguments for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/elazarl/goproxy" | |
"log" | |
"net/http" | |
"os" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://code.google.com/p/go/issues/detail?id=640 | |
package main | |
import "fmt" | |
func main() { | |
args := []int{1, 2, 3} | |
fmt.Println(sum(args...)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
s := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := %#v\n\tfmt.Printf(s, s)\n}\n" | |
fmt.Printf(s, s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
%% -*- mode: erlang -*- | |
%%! -smp enable -hidden | |
%% | |
%% A concurrent prime sieve, inspired by the Go prime sieve | |
%% with daisy-chained filter processes. | |
%% https://golang.org/doc/play/sieve.go | |
%% | |
%% Translated by Issac Trotts (2016) | |
%% with help from Amiramix on StackOverflow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; A concurrent prime sieve translated from | |
;; https://golang.org/doc/play/sieve.go | |
;; by Issac Trotts with help from Chris Murphy and glts on Stack Overflow. | |
(require '[clojure.core.async :as async :refer [<! >! <!! chan go]]) | |
(defn generate-naturals | |
"Sends the sequence 2, 3, 4, ... to channel 'ch'." | |
[ch] | |
(go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import re | |
import sys | |
parser = argparse.ArgumentParser(description= | |
'''Filter some text with a regex, allowing matches to span multiple lines. | |
This tool is based on some ideas from Rob Pike's Sam editor: |