Skip to content

Instantly share code, notes, and snippets.

View niuk's full-sized avatar

Kangyuan Niu niuk

View GitHub Profile
@niuk
niuk / gist:1682411
Created January 26, 2012 11:48
What valgrind tells me.
==8944== Memcheck, a memory error detector
==8944== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==8944== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==8944== Command: ./Generator
==8944==
; ModuleID = 'myModule'
==8944== Invalid write of size 8
==8944== at 0xB3BB8C: ??? (in /home/karl/Haskell/Hammer/Generator)
==8944== Address 0x64ed560 is not stack'd, malloc'd or (recently) free'd
==8944==
@niuk
niuk / gist:1682404
Created January 26, 2012 11:46
This code will segfault.
{-# LANGUAGE
OverloadedStrings,
FlexibleInstances #-}
module Main where
import Prelude
import System.IO
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /home/test/.ssh/identity type -1
debug1: identity file /home/test/.ssh/id_rsa type 1
debug1: identity file /home/test/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
main : IO ()
open : IO Handle
write : Handle -> String -> IO ()
close : Handle -> IO ()
main = do
fd <- open "log.txt"
write fd "Hello World!"
close fd
@niuk
niuk / derp.cpp
Created July 20, 2011 20:02
Resource Handling, PART II
/* The Hammer code for read_buf_from_file would look like this: */
void *read_buf_from_file(char *path) {
int ret = -1;
void *buf = malloc(512) <-
lambda(buf) {
if (ret < 0) free(buf);
};
int fd = open(path, O_RDONLY) <-
lambda(fd) {
@niuk
niuk / herp.cpp
Created July 20, 2011 18:27
Resource Handling, PART I
/* Say you want to read some stuff into a buffer.
* To do so in C, a (very) naive programmer would write something like: */
void *read_buf_from_file(char *path) {
void *buf = malloc(512);
int fd = open(path, O_RDONLY);
read(fd, buf, 512);
return buf;
}
interface Eq require
{type T; eq}
interface Eq provide
type T : Type
eq : (T, T) -> Bool
module EqInt : Eq where
type T = Int
eq = builtIn_eqInt