Skip to content

Instantly share code, notes, and snippets.

@tetsuok
tetsuok / duck.go
Created May 26, 2012 20:03
A sample of duck typing
// duck typing
package main
import "fmt"
// Virtual duck
type Duck interface {
Quack() string
}
@tetsuok
tetsuok / type_assertions.go
Created May 26, 2012 17:23
An example of type assertions for empty interface
// An example of type assertions for empty interface (i.e., interface{})
package main
import (
"container/list"
"fmt"
)
type Node struct {
@tetsuok
tetsuok / test_boost_unit_test.sh
Created May 10, 2012 07:18
Code to test boost test link error.
#!/bin/bash -x
cat << EOF > foo.cc
#define BOOST_TEST_MODULE foo
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(foo_test) {
int a = 0;
BOOST_CHECK_EQUAL(0, a);
}
@tetsuok
tetsuok / test_dark_bg.sh
Created May 8, 2012 23:00
Test dark slide background.
#!/bin/bash -x
filename=sinx
epsfile=${filename}.eps
tex_master=main.tex
tex_cmd=pdflatex
color=white # color which you want to change to.
gnuplot <<EOF
set terminal postscript eps enhanced color 30
@tetsuok
tetsuok / whitecolor.gp
Created May 8, 2012 22:26
Code to change colors of various components in Gnuplot
# Change colors of elements in Gnuplot
# change a color of border.
set border lw 3 lc rgb "white"
# change text colors of tics
set xtics textcolor rgb "white"
set ytics textcolor rgb "white"
# change text colors of labels
@tetsuok
tetsuok / default_template.cc
Created May 7, 2012 23:41
Code that clang does not allow
// Clang does not compile the code, but gcc does.
// See e.g.,
// http://www.mail-archive.com/[email protected]/msg08044.html
template <typename T>
class Foo {
public:
Foo() {}
~Foo() {}
void func(int a);
@tetsuok
tetsuok / stack.cc
Created May 5, 2012 14:13
C++ code that clang++ does not accept but g++ does
#include <cstdlib>
struct Entry {
unsigned char key;
std::size_t value;
};
template <typename EntryT>
class Klass {
public:
@tetsuok
tetsuok / gen_reduced_eps.sh
Created April 19, 2012 17:34
Generate reduced EPS files
#!/bin/bash
# A script to generate reduced EPS files.
# Taken from http://electron.mit.edu/~gsteele/pdf/
#
epsfile=$1
pngfile=${epsfile/eps/png}
jpgfile=${epsfile/eps/jpg}
new_epsfile=reduced_${epsfile}
echo $new_epsfile
@tetsuok
tetsuok / complex_cube_root.go
Created April 2, 2012 09:23
An answer of the advanced exercise: complex cube roots on a tour of Go
package main
import (
"fmt"
"math/cmplx"
)
// FIXME:
// Currently calculate only real part of the input
// complex number.
@tetsuok
tetsuok / fibonacci_closure.go
Created April 2, 2012 08:48
An answer of the exercise: Fibonacci closure on a tour of Go
package main
import "fmt"
// Very naive answer.
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
n := 0
a := 0