Skip to content

Instantly share code, notes, and snippets.

View advancedxy's full-sized avatar
:octocat:

advancedxy

:octocat:
View GitHub Profile
@advancedxy
advancedxy / mongodb.conf
Created December 8, 2013 13:06
logrotate config file for mongodb
/path/to/configsvr/config.log{
weekly
rotate 9
compress
size 100M
sharedscripts
create
postrotate
/bin/kill -SIGUSR1 `cat /path/to/configsvr/mongd.lock 2> /dev/null` 2> /dev/null || true
/bin/find /path/to/configsvr/ -type f -size 0 -regextype sed -regex ".*\.log\.[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}" -delete 2> /dev/null
public class HeightedQuickUnionUF {
private int[] id; // id[i] = parent of i
private int[] height; // sz[i] = number of objects in subtree rooted at i
private int count; // number of components
// Create an empty union find data structure with N isolated sets.
public HeightedQuickUnionUF(int N) {
count = N;
id = new int[N];
height = new int[N];
@advancedxy
advancedxy / shua.js
Created May 5, 2014 02:29
喜刷刷
box = $("div.m-chatform .edit textarea")
btn = $("div.m-chatform .btn")
var txt = ''
lines = []
function init() {
var xhr = new XMLHttpRequest()
xhr.open("GET", "http://10.240.138.100/tmp/tang.txt", true)
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
2.0.0.0/7
4.0.0.0/6
8.0.0.0/7
11.0.0.0/8
12.0.0.0/7
15.0.0.0/8
16.0.0.0/5
24.0.0.0/7
26.0.0.0/8
28.0.0.0/6
@advancedxy
advancedxy / rack_info.py
Created July 9, 2014 05:41
hadoop rack awareness script
#!/usr/bin/env python
import sys
import socket
data = """
100.200.208.12-100.200.208.46 : /xxx/rack_1
"""
def ip_integer_from_string(s):
return reduce(lambda a,b: a<<8 | b, map(int, s.split(".")))
@advancedxy
advancedxy / downxml.py
Last active August 29, 2015 14:13
advancedxy.com's post related code
#!/usr/bin/python2
#coding=utf-8
import os
import urllib2
import zipfile
import zlib
from urlparse import urlparse
from time import strftime,localtime
def initsites(filename):
@advancedxy
advancedxy / convert_text_chunzhen_bin.py
Last active August 29, 2015 14:13
advancedxy.com's blog related code
#coding:utf-8
import sys,struct,socket,array,datetime
def ip2str(ip):
return str(ip>>24)+'.'+str((ip>>16)&0xffL)+'.' \
+str((ip>>8)&0xffL)+'.'+str(ip&0xffL)
def str2ip(s):
(ip,) = struct.unpack('!I',socket.inet_aton(s))
return ((ip>>24)&0xffL)|((ip&0xffL)<<24) \
public int whileLoop(int);
descriptor: (I)I
flags: ACC_PUBLIC
Code:
stack=2, locals=3, args_size=2
0: iconst_0
1: istore_2
2: iload_2
3: iload_1
4: if_icmpge 16
@advancedxy
advancedxy / ParallelCollectionRDD.sc
Created January 20, 2015 02:00
This gist reproduce a bug in IntelliJ IDEA Scala plugin's type system
import scala.collection.immutable.NumericRange
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag
private object ParallelCollectionRDD {
/**
* Slice a collection into numSlices sub-collections. One extra thing we do here is to treat Range
* collections specially, encoding the slices as other Ranges to minimize memory cost. This makes
* it efficient to run Spark over RDDs representing large sets of numbers. And if the collection
* is an inclusive Range, we use inclusive range for the last slice.
@advancedxy
advancedxy / BitMap.scala
Created January 29, 2015 07:45
simple BitMap impl.
case class BitMap(val n: Int) {
private val bytes = Array.fill(n / 8 + 1)(0.toByte)
def setBit(i: Int) {
bytes(i / 8) = (bytes(i / 8) | (1 << (i & 7))).toByte
}
def unSetBit(i: Int) {
bytes(i / 8) = (bytes(i / 8) & ~(1 << (i & 7))).toByte
}