Skip to content

Instantly share code, notes, and snippets.

@ijt
ijt / demux.hs
Created June 28, 2011 00:36
Haskell program to demux input
#!/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
@ijt
ijt / ijt_hoogle.vim
Created June 5, 2011 20:51
Hoogle plugin for Haskell in Vim
" $ 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>
@ijt
ijt / panic_example.go
Created May 24, 2011 07:02
Example of exception handling in Go
// Exception handling example, fleshed out from Rob Pike's post
// at http://goo.gl/ZiUra
package main
import "fmt"
func f(dopanic bool) {
defer func() {
if x := recover(); x != nil {
@ijt
ijt / applicative_quickcheck.hs
Created May 20, 2011 19:41
Example of checking a law for applicative functors using QuickCheck
#!/usr/bin/env runhaskell
import Control.Applicative
import Test.QuickCheck
newtype ZipList2 a = ZipList2 { getZipList :: [a] }
instance Applicative ZipList2 where
pure x = ZipList2 $ repeat x
(ZipList2 gs) <*> (ZipList2 xs) = ZipList2 (zipWith ($) gs xs)
@ijt
ijt / io_quickcheck_example.hs
Created May 11, 2011 22:12
Simple example of monadic IO with QuickCheck in Haskell
#!/usr/bin/env runhaskell
-- Synopsis:
-- $ cabal install QuickCheck
-- $ runhaskell io_quickcheck_example.hs
--
-- Author: Issac Trotts <issac.trotts@gmail.com>
import Directory
import System.Environment
@ijt
ijt / FfiExample.hs
Created May 11, 2011 07:19
Example of calling C from Haskell using the FFI
{-# LANGUAGE ForeignFunctionInterface #-}
-- Simple example of calling C from Haskell.
--
-- $ ghci
-- > :load FfiExample.hs
-- > c_sin pi
-- 1.2246467991473532e-16
--
-- $ ghc --make FfiExample.hs
@ijt
ijt / exec_run_example.go
Created May 4, 2011 00:01
How to make a system call in golang and check the return status
The new interface for system calls in Go is much better than it was. Check the examples here:
http://golang.org/pkg/os/exec/
@ijt
ijt / gorun.bash
Created May 3, 2011 08:18
Script to run golang files as scripts. Moved to http://github.com/ijt/goscript
This script has been moved to http://github.com/ijt/goscript and renamed to "goscript".
@ijt
ijt / goroutine_printf.go
Created May 1, 2011 20:37
How to call Printf in a goroutine without hanging
package main
import (
"fmt"
"os"
)
func PrintInts() {
for i := 0; ; i++ {
fmt.Printf("%d\r", i)
@ijt
ijt / http_get.go
Last active August 23, 2021 12:37
Example of using http.Get in go (golang)
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)