Skip to content

Instantly share code, notes, and snippets.

(if (>= emacs-major-version 24)
(electric-pair-mode t)
;; Setup the alternative manually.
(progn
;; ...
))
(require 'ruby-electric)
(add-hook 'ruby-mode-hook
'(lambda ()
@tetsuok
tetsuok / answer_exercise_gotour.go
Created April 2, 2012 01:58
An answer of the exercise: Loops and Functions on a tour of Go
package main
import (
"fmt"
"math"
)
const Delta = 0.0001
func isConverged(d float64) bool {
@tetsuok
tetsuok / answer_word_count.go
Created April 2, 2012 02:20
An answer of the exercise: Maps on a tour of Go
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
a := strings.Fields(s)
@tetsuok
tetsuok / answer_pic.go
Created April 2, 2012 02:40
An answer of the exercise: Slices on a tour of Go
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// Allocate two-dimensioanl array.
a := make([][]uint8, dy)
for i := 0; i < dy; i++ {
a[i] = make([]uint8, dx)
}
@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
@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 / 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 / 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 / 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 / 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