Skip to content

Instantly share code, notes, and snippets.

@daniellowtw
daniellowtw / go_Interface_embedding_test.go
Last active March 31, 2016 10:20
Experiments with interface embedding
package main
import "testing"
type A interface {
x(key interface{}) interface{}
}
type B struct {
A
@daniellowtw
daniellowtw / a.go
Created December 10, 2015 17:25
adding a method to another method
package main
type foo func(int, int)
func (f foo) bar(x int) {
f (x, x)
}
func main() {
add := func (x int, y int) {
@daniellowtw
daniellowtw / shortAssignment.go
Last active October 30, 2015 12:58
Golang good and bad parts
// Cannot use short assignments when dealing with structs
package main
type foo struct {
stuff int
}
func main() {
foo.stuff, a := 1,2
println(a)
@daniellowtw
daniellowtw / main.go
Created October 27, 2015 10:03
Mocking in Go
package main
import (
"golang.org/x/net/context"
"github.com/stretchr/testify/mock"
)
type Foo interface {
Bar (ctx context.Context) (string)
}
@daniellowtw
daniellowtw / memoize.js
Created October 25, 2015 00:32
Javascript memoize decorator functor
function memoize(fn) {
var invocationCache = {};
return function() {
var args = Array.prototype.slice.call(arguments);
var cachedValue = invocationCache[args];
if (cachedValue !== undefined) {
return cachedValue;
}
var result = fn.apply(null, arguments);
invocationCache[args] = result;
@daniellowtw
daniellowtw / MyCakePattern.scala
Created October 15, 2015 13:51
An exploration of the cake pattern for scala
import org.scalatest.mock.MockitoSugar
/**
* This explores self type and the cake pattern
*
* The recipe:
* 1) Create a trait component
* 2) Declare any dependent components using self-types
* 3) Create the trait
* 4) Create an abstract val that will be instantiated with an instance of the component
var gulp = require('gulp'),
connect = require('gulp-connect');
watch = require('gulp-watch');
gulp.task('watch', function() {
watch(['*.html','js/*.js']).pipe(connect.reload());
});
gulp.task('server', function(done) {
@daniellowtw
daniellowtw / Zim resize.ahk
Created May 25, 2015 11:31
Macro to resize images in zim wiki after pasting them
SetTitleMatchMode, 2
#IfWinActive Zim ahk_class gdkWindowToplevel
!1::
SendInput, {AppsKey}e{Tab}{Tab}{Tab}{Tab}100{Enter}{Enter}
return
!2::
SendInput, {AppsKey}e{Tab}{Tab}{Tab}{Tab}200{Enter}{Enter}
return
!3::
@daniellowtw
daniellowtw / Full screen latex image README.md
Last active August 29, 2015 14:21
Full screen latex image
  • Create a new directory.
  • Download script.sh.
  • Create a folder in that directory called images.
  • Dump all images (whatever includegraphics can accept) that you want to combine in there.
  • Run script
@daniellowtw
daniellowtw / Pycrypto AES
Created May 7, 2015 13:28
Using pycrypto AES
# Taken from http://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256/12525165#12525165
import base64
import hashlib
from Crypto import Random
from Crypto.Cipher import AES
class AESCipher(object):
def __init__(self, key):