Skip to content

Instantly share code, notes, and snippets.

View Chen-tao's full-sized avatar

Chen-tao Chen-tao

  • ByteDance
  • Beijing China
View GitHub Profile
/*
Copyright (c) 2016, Nitin Gode
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
@Chen-tao
Chen-tao / antixss.go
Created April 17, 2017 06:26
Auto XSS atack protector
package main
import (
"html/template"
"net/http"
)
//AntiXSS is main struct on auto AntiXss Handler
type AntiXSS struct {
http.Handler
@Chen-tao
Chen-tao / unzip-gbk.py
Created February 21, 2017 07:50
mac unzip chinese file name
#!/usr/bin/python
# -*- coding: utf-8 -*-
# unzip-gbk.py
import os
import sys
import zipfile
print "Processing File " + sys.argv[1]
/**
*
* @author tadchen
* @version 2017年2月9日
* @description TODO
*/
public class OctKanji {
public static void main(String[] args) throws Exception {
String str = URLEncoder.encode("大家好。", "UTF-8");
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
/**
* Definition for a binary tree node.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
//Java Solution 1 - Iterative
public ListNode reverseList(ListNode head) {
if(head==null||head.next==null)
return head;
ListNode p1 = head;
ListNode p2 = p1.next;
@Chen-tao
Chen-tao / Delete_Node_in_a_Linked_List.java
Created February 7, 2017 07:37
https://leetcode.com/problems/delete-node-in-a-linked-list/ Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
@Chen-tao
Chen-tao / LFU.java
Last active February 7, 2017 07:10
https://leetcode.com/problems/lfu-cache/ Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.
public class LFUCache {
Node head = null;
final int capacity;
Map<Integer, Integer> valueMap;
Map<Integer, Node> nodeMap;
public LFUCache (int capacity) {
this.capacity = capacity;
valueMap = new HashMap<>(this.capacity, 1f);