Skip to content

Instantly share code, notes, and snippets.

View yixizhang's full-sized avatar

Yixi Zhang yixizhang

  • bay area
View GitHub Profile
def comb(n, k):
if k == n:
return [[1 for _ in range(n)]]
if k > n:
return False
if k == 0:
return [[0 for _ in range(n)]]
if k == 1:
ret = []
for i in range(n):
@yixizhang
yixizhang / _readme.md
Created May 30, 2017 02:03 — forked from mislav/_readme.md
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

# show commits since master to HEAD
git log --oneline --decorate master~..HEAD
@yixizhang
yixizhang / f.sh
Created August 31, 2016 04:50
ts
mocha test/api/responses/notFound.test.js | ts '[%Y-%m-%d %H:%M:%.S]'
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited --filter status=created -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
docker volume ls -qf dangling=true | xargs -r docker volume rm
@yixizhang
yixizhang / test_ciphers.sh
Last active December 29, 2015 14:29
return a list of available ciphers for url
#!/usr/bin/env bash
# OpenSSL requires the port number.
SERVER=$1
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
echo Obtaining cipher list from $(openssl version).
for cipher in ${ciphers[@]}
@yixizhang
yixizhang / nock.coffee
Last active December 29, 2015 08:49
nock sample
nock = require 'nock'
quest = require 'quest'
# chaining
scope = nock('http://url.ly')
.filteringRequestBody (path) ->
if path == '*'
return '-'
else
@yixizhang
yixizhang / shortest_path.py
Last active December 26, 2015 07:19
Dijkstra algorithm
import sys
def shortest_path(g, start, end):
"""
Dijkstra's algorithm Python implementation.
Arguments:
graph: Dictionnary of dictionnary (keys are vertices).
start: Start vertex.
@yixizhang
yixizhang / inorderiterator.py
Created October 21, 2013 04:52
in order tree traversal iterator
class InOrderTree(Tree):
""" iterator for inorder traversal over a binary tree """
def __init__(self, root):
self.node = root
self.stack = []
def __iter__(self):
return self
def next(self):
@yixizhang
yixizhang / 8queens
Created August 8, 2013 06:05
3行Python搞定八皇后问题 @liancheng
from itertools import *
c = range(8)
[v for v in permutations(c) if 8==len({v[i]+i for i in c})==len({v[i]-i for i in c})]