Skip to content

Instantly share code, notes, and snippets.

View kavinyao's full-sized avatar

Kavin Yao kavinyao

View GitHub Profile
@kavinyao
kavinyao / bst.py
Created November 14, 2013 20:06
Rudimentary BST in Python.
class Node(object):
"""A node in BST."""
def __init__(self, value, left_node=None, right_node=None):
self.value = value
self.left_node = left_node
self.right_node = right_node
def set_left(self, left_node):
self.left_node = left_node
#include <stdio.h>
int overlap_count(const char *s1, const char *s2)
{
const char *s1_begin = s1;
const char *p1, *p2;
while(*s1_begin != '\0') {
p1 = s1_begin;
p2 = s2;
#include <iostream>
using namespace std;
void swap(int A[], int i, int j)
{
int temp = A[i];
A[i] = A[j];
A[j] = temp;
}
#include <iostream>
using namespace std;
class Solution {
public:
// complexity: O(log(A)+log(B)) time, O(1) space
// precondition: 0 <= A, B <= 100,000,000
int zip(int A, int B) {
if (A < 0 || A > 100000000) return -1;
@kavinyao
kavinyao / client.go
Created July 27, 2018 08:46
Go practice with JSON, TCP networking, file system, command-line flag parsing
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"net"
"os"
"strconv"
@kavinyao
kavinyao / gist:4014994
Created November 5, 2012 02:38 — forked from clippit/gist:4012541
strstr
#include <stdio.h>
const char* my_strstr(const char* haystack, const char* needle) {
if (!*needle)
return haystack;
const char* h = haystack;
const char* n = needle;
while (*h) {
const char* hp = h;
@kavinyao
kavinyao / readme.md
Created July 19, 2020 01:30
Enable Ligature in wsltty

Here we use wsltty as example. The same options can be applied to mintty too.

  1. Download wsltty
  2. Open properties of WSL Terminal shortcut, add -o LigaturesSupport=1 -o Ligatures=2 options. It should looks like below
C:\Users\<username>\AppData\Local\wsltty\bin\mintty.exe -o LigaturesSupport=1 -o Ligatures=2 --WSL= --configdir="C:\Users\<username>\AppData\Roaming\wsltty" -~  -
@kavinyao
kavinyao / ObserverExample.java
Created June 23, 2012 06:59
Observer Pattern Example
import java.util.*;
/*
* Example of Observer Pattern:
* Student is the model
* View1 and View2 display information of the student
* View3 changes information of the student
* Whenever the student is changed, the views displaying it should be updated
*/