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
" $ cabal install hoogle | |
" | |
" Then put this file in ~/.vim/ftplugin/haskell/ijt_hoogle.vim | |
" | |
" Put your cursor over a function name and press \h to find out | |
" its signature and where it is defined. | |
" | |
command! Hoogle :exec("!hoogle '" . expand("<cWORD>") . "'") | |
map \h :Hoogle<CR> |
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 | |
import System.Environment | |
import System.Exit | |
import System.IO | |
usage = "usage: cat somefile | demux outfile1 outfile2 ..." | |
help = "This program alternates sending its input to outfile1 and outfile2." | |
main = do |
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 | |
-- Example of tailing a file, using two communicating Haskell threads. It's not | |
-- really necessary to do this concurrently, but the approach here generalizes | |
-- nicely if we want to filter or transform the output. | |
import Control.Concurrent | |
import Control.Monad | |
import System.Environment | |
import System.Exit |
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 ( | |
"reflect" | |
"sort" | |
"testing" | |
"testing/quick" | |
) | |
type IntSlice []int |
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 | |
import Data.List (sort, (\\)) | |
import Test.QuickCheck (Property, (==>)) | |
main = interact (showLn . median . map read . lines) | |
showLn :: Show a => a -> String | |
showLn x = show x ++ "\n" |
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
#!/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
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) | |
} |