Skip to content

Instantly share code, notes, and snippets.

@xlab
xlab / bytes_split.go
Last active April 4, 2022 17:21
Golang split byte slice in chunks sized by limit
func split(buf []byte, lim int) [][]byte {
var chunk []byte
chunks := make([][]byte, 0, len(buf)/lim+1)
for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
}
@kitak
kitak / konami_command.js
Last active August 29, 2015 14:02
コナミコマンドを実装した
var keyCodeCheck = (function () {
var konamiCommandKeyCodes = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var acceptIndex = 0;
var timerId = null;
var resetAcceptIndex = function () {
console.log('最初からやりなおしです');
acceptIndex = 0;
};