Skip to content

Instantly share code, notes, and snippets.

View dreamersdw's full-sized avatar

dreamersdw dreamersdw

  • Kingsoft Cloud
  • China
View GitHub Profile
def permutations(seq):
if not seq:
yield []
else:
for i in xrange(len(seq)):
for p in permutations(seq[1:]):
yield p[0:i] + [seq[0]] + p[i:]
for p in permutations([1, 2, 3, 4]):
print p
@dreamersdw
dreamersdw / brainfuck.c
Created October 29, 2011 16:16
Brainfuck interpreter written in C
#include <stdio.h>
#define match(from, to, ptr, dir, level) \
while(*(dir ptr)) { \
if (*ptr == to && level == 0) break; \
if (*ptr == from) ++level; \
if (*ptr == to) --level; \
}
char code[32768] = {0};
@dreamersdw
dreamersdw / lookup.sh
Created October 29, 2011 16:05
Linux下的划词翻译脚本(带发音)
#!/bin/bash
while true
do
cur_word=$(xclip -o | awk '{print $1}' | grep '^[a-zA-Z]\+$')
if [[ $last_word == $cur_word || -z $cur_word ]]; then
sleep 1
continue
fi
word=$cur_word
result=$(parse.py $word)