This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Mappable { | |
def toMap() { | |
def map = [:] | |
def fields = this.metaClass.getProperties().findAll { it.name != "class" } | |
fields.each { | |
def field = this.metaClass.getProperty(this, it.name) | |
if(field instanceof Mappable) | |
map[(it.name)] = field.toMap() | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BB { | |
static short getU8(ByteBuffer buffer) { | |
(buffer.get() & 0xFF) | |
} | |
static int getU16(ByteBuffer buffer) { | |
(buffer.getShort() & 0xFFFF) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import datetime | |
objectid = int(sys.argv[1], 16) | |
fmt = "%Y-%m-%d %H:%M:%S" | |
counter = objectid & 0xFFFFFF | |
shift = 24 | |
process_id = (objectid >> shift) & 0xFFFF | |
shift += 16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip = "192.168.0.1" | |
// Encode | |
e = (ip.split(/\./) as List).withIndex().collect { v,i->Long.parseLong(v) << (24 - (8 * i))}.inject(0) {a,b -> a+b } | |
// Decode | |
d = (0..3).collect{ (e >> (24 - (it * 8))) & 0xFF }.join(".") | |
assert d == ip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_time(epoch_us, fmt="%Y-%m-%d %H:%M:%S.%f"): | |
dt = float(epoch_us / 1000000.0) | |
v = datetime.datetime.fromtimestamp(dt) | |
return v.strftime(fmt) | |
def get_micros_for_time(stime, fmt="%Y-%m-%d %H:%M:%S.%f"): | |
assert stime | |
tt = time.strptime(stime, fmt) | |
assert tt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes([ | |
@Grab(group = 'com.gmongo', module = 'gmongo', version = '1.5'), | |
@GrabExclude("org.codehaus.groovy:groovy-xml") | |
]) | |
import com.gmongo.GMongo | |
import com.mongodb.DBCollection | |
import com.mongodb.DBObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def version_major = 0 | |
def version_minor = 1 | |
def version_patch = 0 | |
def version_release = "BETA" | |
group 'org.company' | |
version "${version_major}.${version_minor}.${version_patch}.${version_release}" | |
task setVersion() { | |
def appProperties = new File("src/main/resources/application.properties") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.annotation.Value | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.context.annotation.PropertySource | |
@Configuration | |
@PropertySource('classpath:application.properties') | |
class AppConfig { | |
@Value('${app.version.major}') | |
def major |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For Panda Debugging | |
pd.set_option('display.float_format', lambda x: '%.0f' % x) | |
pd.set_option('display.max_rows', 500) | |
pd.set_option('display.max_columns', 500) | |
pd.set_option('display.width', 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@staticmethod | |
def decode_ip(raw): | |
ip = ["%d" % ((raw >> (24 - (i * 8))) & 0xFF) for i in range(0, 4)] | |
return '.'.join(ip) |
OlderNewer