Skip to content

Instantly share code, notes, and snippets.

View SylvanasSun's full-sized avatar

SylvanasSun SylvanasSun

  • Tianjin,China
View GitHub Profile
@SylvanasSun
SylvanasSun / 0_reuse_code.js
Created February 20, 2017 09:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@SylvanasSun
SylvanasSun / A.sorting_algorithm
Last active March 20, 2017 12:02
Some common sorting algorithm snippet.
Some common sorting algorithm snippet.
@SylvanasSun
SylvanasSun / MaxPriorityQueue.java
Created March 21, 2017 08:17
Using binary heap implements of the max priority queue.
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
* max heap priority queue
*
* @author SylvanasSun
*
@SylvanasSun
SylvanasSun / BinarySearchTree.java
Created March 26, 2017 12:13
Using binary search tree implements the symbol table.
package chapter3_searching.C3_2_BinarySearchTrees;
import edu.princeton.cs.algs4.Queue;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
* The {@code BinarySearchTree} class represents an ordered symbol table of generic
* key-value pairs.
@SylvanasSun
SylvanasSun / RedBlackBST.java
Created April 2, 2017 09:16
This implements uses a left-leaning red-black binary search tree. It requires that the key type implements Comparable interface and calls the compareTo() method to compare two key. It does not call either equals() or hashCode().
import edu.princeton.cs.algs4.Queue;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
* The {@code RedBlackBST} class represents an ordered symbol table of generic
* key-value pairs.
* This implements uses a left-leaning red-black Binary Search Tree.
* It requires that the key type implements the {@code Comparable} interface
@SylvanasSun
SylvanasSun / AvlTree.java
Created April 8, 2017 10:53
This implements uses a AVL balanced tree. Allow any node in the tree of the height of the two subtree biggest difference for one.
package chapter3_searching.C3_3_BalancedSearchTrees;
import edu.princeton.cs.algs4.Queue;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
* The {@code AvlTree} class represents an ordered symbol table of generic
* key-value pairs.
@SylvanasSun
SylvanasSun / ConcurrentStack.java
Last active May 29, 2017 10:29
This class represents a thread-safe stack and use CAS instruction to ensure thread safe.
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
/**
* This class represents a thread-safe stack and use CAS instruction to ensure thread safe.
*
* Created by SylvanasSun on 2017/5/29.
*
@SylvanasSun
SylvanasSun / log4j.xml
Created July 16, 2017 06:11
The log4j xml config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- 输出日志到控制台 ConsoleAppender -->
<appender name="console"
class="org.apache.log4j.ConsoleAppender">
<param name="encoding" value="UTF-8"/>
<layout class="org.apache.log4j.TTCCLayout">
<param name="ConversionPattern" value="TTCCLayout"/>
@SylvanasSun
SylvanasSun / girl_face_match.c
Created July 16, 2017 16:30
The algorithms from the movie <<The Social Network>>.
#include <stdio.h>
#include <math.h>
typedef struct {
const char *name;
int rank;
double expect_rate;
} girl;
const int K = 10;
@SylvanasSun
SylvanasSun / http_utils.py
Created February 6, 2018 09:48
Some utils in common use of python
import requests
import logging
METHOD_GET = 'GET'
METHOD_POST = 'POST'
RETURN_TEXT = 'TEXT'
RETURN_BINARY = 'BINARY'
RETURN_JSON = 'JSON'
RETURN_RAW = 'RAW'