Skip to content

Instantly share code, notes, and snippets.

@ijt
ijt / .bashrc_common
Created October 23, 2010 22:43
.bashrc_common, sourced from my .bashrc files
# Path
#
if echo $PATH | grep -v $HOME/bin > /dev/null; then
export PATH="$HOME/bin:$PATH"
fi
# Recursive search with ack
#
export ACK_ROOT=$HOME
@ijt
ijt / vimrc.vim
Created October 27, 2010 23:15
vimrc
syntax on
" Indentation
"
filetype indent on
function! Spaces()
set expandtab
set shiftwidth=4
set softtabstop=4 " Backspace deletes 4 spaces
set tabstop=4
@ijt
ijt / git-svn-diff
Created December 23, 2010 18:35
Shows differences between your local git-svn repo and the central svn repo
#!/usr/bin/python
# This file is originally from http://code.google.com/p/git-svn-utils/source/checkout. It
# contains some small changes by ijt to get it working on OS X.
import sys,re,os, subprocess
def get_output(cmd):
'''a little wrapper around subprocess.Popen'''
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p.wait()
@ijt
ijt / haskell_http.hs
Created April 29, 2011 21:33
Example of an HTTP request in Haskell
#!/usr/bin/env runhaskell
import GHC.IO.Handle
import Network
import Network.Socket
main = do
handle <- connectTo "hackage.haskell.org" (PortNumber 80)
hPutStr handle "GET /packages/hackage.html HTTP/1.1\n"
hPutStr handle "Host: hackage.haskell.org\n"
@ijt
ijt / freebase_example.hs
Created April 30, 2011 01:08
Example of making a Freebase query from Haskell
import Network.HTTP (simpleHTTP, getRequest, getResponseBody, urlEncode)
main = do
resultJson <- queryFreebase "{\"query\":[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]}"
putStrLn resultJson
-- Runs a query against Freebase and returns the result in JSON format.
queryFreebase :: String -> IO String
queryFreebase jsonQuery = do
let query = urlEncode $ jsonQuery
@ijt
ijt / http_get.go
Last active August 21, 2024 05:11
Example of using http.Get in go (golang)
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
@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 / 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 / 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 / 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