Skip to content

Instantly share code, notes, and snippets.

View hengyunabc's full-sized avatar

hengyunabc hengyunabc

View GitHub Profile
@hengyunabc
hengyunabc / Test.java
Created August 22, 2017 06:10
java get fd count. openFileDescriptorCount / maxFileDescriptorCount
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import com.sun.management.UnixOperatingSystemMXBean;
public class Test {
public static void main(String[] args) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
if (operatingSystemMXBean instanceof UnixOperatingSystemMXBean) {
import java.security.SecureRandom;
public class PenneyGame {
static SecureRandom random = new SecureRandom();
public static void main(String[] args) {
int count = 100;
int winCount = 0;
for (int i = 0; i < 100; ++i) {
@hengyunabc
hengyunabc / gist:c906aa26c213cc74c5dc
Last active November 30, 2015 02:13
可以在匿名类里用{}来进行一些初始化工作,这样子可以避免要写一个构造函数。
scheduleJobManager.addScheduleJob(new ScheduleJobSupport(){
{
this.setInterval(intervalx);
}
@Override
public boolean permitAdd() {
return false;
}
});
@hengyunabc
hengyunabc / Test.java
Created August 1, 2012 07:59
Testcase for Kryo 2.18
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.FieldSerializer.Optional;
@hengyunabc
hengyunabc / proxy.py
Created June 21, 2012 18:07
对应goagent 186版的proxy.py文件
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Based on GAppProxy 2.0.0 by Du XiaoGang <dugang@188.com>
# Based on WallProxy 0.4.0 by hexieshe <www.ehust@gmail.com>
__version__ = '1.6.7'
__author__ = "{phus.lu,hewigovens}@gmail.com (Phus Lu and Hewig Xu)"
import sys, os, re, time, errno, binascii, zlib
import struct, random, hashlib
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.HashMap;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.FieldSerializerTest.Hello;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.MapSerializer;
package io.github.xdiamond.web.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@hengyunabc
hengyunabc / AlertService.js
Created June 1, 2015 03:00
angularjs AlertService.
'use strict';
angular.module('xdiamondApp')
.factory('AlertService', ['$timeout', '$rootScope', function ($timeout, $rootScope) {
var service = {};
var alerts = [];
//all template can use alerts like follow:
//<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="alert.close()">{{ alert.msg }}</alert>
@hengyunabc
hengyunabc / zkEnv.sh
Last active August 29, 2015 14:09
Set zookeeper output log to logs. 设置zookeeper输出日志到logs目录的配置
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@hengyunabc
hengyunabc / gist:d48fbebdb9bddcdf05e9
Last active August 29, 2015 14:03
std::notify_all_at_thread_exit, llvm libc++ implements.
template <class _Fp>
void*
__thread_proxy(void* __vp)
{
__thread_local_data().reset(new __thread_struct);
std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
(*__p)();
return nullptr;
}