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
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
@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 / config.json
Last active January 14, 2025 02:56
rss.go
{
"Server": "http://localhost:9091/transmission/rpc",
"BaseDir": "/home/kghost/rtorrent/download/",
"Database": "rss.db",
"SourceSets": [{
"Target": "hentai",
"Sources": [{
"Url": "https://sukebei.nyaa.si/?page=rss&u=hikiko123",
"Link": true
}]
#! /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
@kghost
kghost / echo server
Created November 2, 2010 06:04
echo server using scala continuation
package info.kghost.test
import java.net.InetSocketAddress
import java.nio.channels.SelectionKey
import java.nio.channels.Selector
import java.nio.channels.ServerSocketChannel
import java.nio.channels.SocketChannel
import java.nio.ByteBuffer
import scala.collection.JavaConversions.collectionAsScalaIterable