Skip to content

Instantly share code, notes, and snippets.

View zzt93's full-sized avatar

Tony Zeng zzt93

View GitHub Profile
@zzt93
zzt93 / Java constant - final
Last active August 29, 2015 14:14
Java constant - final
Java constant - final
@zzt93
zzt93 / extern_const.cpp
Last active August 29, 2015 14:14
Extern const array
#include <iostream>
#include "extern_const.hpp"
const int n = 10;
//const int a[] = {1, 2}; // this is also ok
extern const int a[] = {1, 2};
int main(int argc, char *argv[])
{
increse();
package lambda;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
* Created by zzt on 5/25/15.
* <p>
* Description:
@zzt93
zzt93 / Iter.java
Created July 30, 2015 03:01
Getting Iterator first then modify container will invalidate the iterator and cause `java.util.ConcurrentModificationException` for `next()` and `remove()` but not `hasNext()`
package so_test;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Created by zzt on 7/30/15.
* <p>
* Description:
* Getting Iterator first then modify container will
#include <stdio.h>
#include "var.h"
void hello1(const char *s) {
printf("hello1 %s\n", s);
}
void hello2(const char *s, const char* s2) {
printf("hello2 %s and %s\n", s, s2);
}
#include "var.h"
#include <stdio.h>
#define hello1(s) hello2(s, "default string")
void hello2(const char *s, const char* s2) {
printf("hello2 %s and %s\n", s, s2);
}
#define hello(...) xglue(hello, PP_NARG(__VA_ARGS__))(__VA_ARGS__)
#include <stdio.h>
#include <stdarg.h>
void hello2(int p1, int p2)
{
printf("hello2 %d %d\n", p1, p2);
}
void hello3(int p1, int p2, int p3)
{
@zzt93
zzt93 / prime.c
Created June 4, 2016 08:03
Code sample to learn pthread and performance tuning
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "prime.h"
void prime(long long n) {
// too large n cause stack overflow
size_t mem = sizeof(int)*(n + 1);
@zzt93
zzt93 / LongestPalindromic.java
Created July 7, 2016 11:47
A solution for longest palindromic problem and used to learn profiling
package interview.leetcode;
import competition.utility.MyIn;
import java.util.ArrayList;
/**
* Created by zzt on 7/6/16.
* <p>
* <h3></h3>
vector<int> getNext(const string& s) {
vector<int> res(s.length());
res[0] = -1;
const char* start = s.c_str();
int j = -1;
for(int i = 0; i < s.length() - 1; ) {
if(j == -1) {
res[i + 1] = 0;
i++;
j = 0;