Skip to content

Instantly share code, notes, and snippets.

View kghost's full-sized avatar
🎯
Focusing

Zang MingJie kghost

🎯
Focusing
View GitHub Profile
case class BinaryTree(left: BinaryTree, right: BinaryTree)
def isComplete(tree: BinaryTree): Boolean = {
val q = scala.collection.mutable.Queue(tree)
var expectNull = false
while(!q.isEmpty) {
val n = q.dequeue
if (n != null) {
if (expectNull) {
return false
@kghost
kghost / gist:5524026
Created May 6, 2013 08:39
nova console
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index c849460..891ffe1 100755
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -2261,10 +2261,6 @@ class LibvirtDriver(driver.ComputeDriver):
# client app is connected. Thus we can't get away
# with a single type=pty console. Instead we have
# to configure two separate consoles.
- consolelog = vconfig.LibvirtConfigGuestSerial()
- consolelog.type = "file"
@kghost
kghost / go.patch
Last active December 16, 2015 16:59
ws.go
diff -r d5666bad617d src/pkg/net/file.go
--- a/src/pkg/net/file.go Thu Sep 27 15:36:22 2012 -0700
+++ b/src/pkg/net/file.go Wed Apr 24 11:49:35 2013 -0400
@@ -7,10 +7,132 @@
package net
import (
+ "errors"
+ "io"
"os"
@kghost
kghost / rss.go
Last active December 16, 2015 16:59
rss.go
package main
import (
"database/sql"
"encoding/json"
"fmt"
"github.com/coopernurse/gorp"
"github.com/kghost/rss"
_ "github.com/mattn/go-sqlite3"
"io/ioutil"
@kghost
kghost / route.sh
Last active October 17, 2015 20:14
route.sh
#! /bin/sh
MAX=10000
case "$script_type" in
route-up)
op=add
;;
route-pre-down)
op=delete
#! /bin/bash
for i in {1..20}
do
for j in {1..20}
do
echo $((i+j)) $i $j
done
done | sort -n | while read sum i j
do
(let* ((yin
((lambda (cc) (write-char #\@ (current-output-port)) cc) (call-with-current-continuation (lambda (c) c))))
(yang
((lambda (cc) (write-char #\* (current-output-port)) cc) (call-with-current-continuation (lambda (c) c)))))
(yin yang))
@kghost
kghost / ttyresize.sh
Last active October 6, 2015 06:58
ttyresize.sh
#! /bin/bash
tty -s || exit 1
trap '' 1 2 3 18
stty -echo
echo 1b5b313874 | xxd -ps -r
read -d t c
stty echo
#include <string.h>
#include <stdio.h>
#include <queue>
#define LOWER 0
#define UPPER 10000
#define S_MID_TOP_TO_LEFT 0
#define S_MID_BOTTOM_TO_LEFT 1
#define S_LEFT_TOP_TO_MID 2
package test
object TileAndTrouble extends App {
//val row = List(8, 8, 20, 17, 25, 25, 11)
//val col = List(15, 13, 10, 21, 20, 18, 17)
val row = List(12, 17, 43, 44, 34, 42, 43, 21, 36, 29, 30, 26)
val col = List(30, 35, 45, 43, 41, 28, 25, 29, 25, 38, 18, 20)
val size = row.length
def seperate_inner(n: Int, c: Int, max: Int): Seq[Map[Int, Int]] = {