Skip to content

Instantly share code, notes, and snippets.

@daschl
daschl / gist:5748526
Last active December 18, 2015 07:39
// MAin Code
public static void main(final String[] args) throws Exception {
// Load Configuration
ApplicationContext context =
new AnnotationConfigApplicationContext(ApplicationConfig.class);
// Load Repository
BlogPostRepository repo = context.getBean("blogPostService", BlogPostService.class).repository;
// Store 2 Blog Posts
@daschl
daschl / gist:5795581
Last active December 18, 2015 14:09
use this to unpack msgpack in a couchbase map function
Or compressed:
var _bin2num={},_num2bin={},_num2b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),_buf=[],_idx=0,_error=0,_isArray=Array.isArray||function(f){return"[object Array]"===Object.prototype.toString.call(f)},_toString=String.fromCharCode,_MAX_DEPTH=512;function msgpackunpack(f){_buf="string"===typeof f?toByteArray(f):f;_idx=-1;return decode()}
function decode(){var f,c,e,a=0,d,g,b=_buf;c=b[++_idx];if(224<=c)return c-256;if(192>c){if(128>c)return c;144>c?(a=c-128,c=128):160>c?(a=c-144,c=144):(a=c-160,c=160)}switch(c){case 192:return null;case 194:return!1;case 195:return!0;case 202:return a=16777216*b[++_idx]+(b[++_idx]<<16)+(b[++_idx]<<8)+b[++_idx],d=a>>23&255,g=a&8388607,!a||2147483648===a?0:255===d?g?NaN:Infinity:(a&2147483648?-1:1)*(g|8388608)*Math.pow(2,d-127-23);case 203:a=16777216*b[++_idx]+(b[++_idx]<<16)+(b[++_idx]<<8)+b[++_idx];
c=a&2147483648;d=a>>20&2047;g=a&1048575;if(!a||2147483648===a)return _idx+=4,0;if(2047===d)return _idx+=4,g?NaN:Infinity;a=16777216*
@daschl
daschl / gist:5796263
Last active December 18, 2015 14:19
MessagePack Library, Modified for Couchbase View inclusion.
/*!{id:msgpack.js,ver:1.05,license:"MIT",author:"[email protected]"}*/
/* Modified by @daschl and @avsej to strip out whats not needed */
// === msgpack ===
// MessagePack -> http://msgpack.sourceforge.net/
var msgunpack = (function () {
var _bin2num = {}, // BinaryStringToNumber { "\00": 0, ... "\ff": 255 }
_num2bin = {}, // NumberToBinaryString { 0: "\00", ... 255: "\ff" }
_buf = [], // decode buffer
_idx = 0, // decode buffer[index]
_toString = String.fromCharCode; // CharCode/ByteArray to String
@daschl
daschl / gist:5796268
Created June 17, 2013 11:34
Whitespace removed MsgPack Couchbase View library.
/*!{id:msgpack.js,ver:1.05,license:"MIT",author:"[email protected]"}*/
/* Modified by @daschl and @avsej to strip out whats not needed */
var msgunpack=function(){function k(){var g,d,e,b=0,f,h,c=m;d=c[++a];if(224<=d)return d-256;if(192>d){if(128>d)return d;144>d?(b=d-128,d=128):160>d?(b=d-144,d=144):(b=d-160,d=160)}switch(d){case 192:return null;case 194:return!1;case 195:return!0;case 202:return b=16777216*c[++a]+(c[++a]<<16)+(c[++a]<<8)+c[++a],f=b>>23&255,h=b&8388607,!b||2147483648===b?0:255===f?h?NaN:Infinity:(b&2147483648?-1:1)*(h|8388608)*Math.pow(2,f-127-23);case 203:b=16777216*c[++a]+(c[++a]<<16)+(c[++a]<<8)+c[++a];d=b&2147483648;
f=b>>20&2047;h=b&1048575;if(!b||2147483648===b)return a+=4,0;if(2047===f)return a+=4,h?NaN:Infinity;b=16777216*c[++a]+(c[++a]<<16)+(c[++a]<<8)+c[++a];return(d?-1:1)*((h|1048576)*Math.pow(2,f-1023-20)+b*Math.pow(2,f-1023-52));case 207:return b=16777216*c[++a]+(c[++a]<<16)+(c[++a]<<8)+c[++a],4294967296*b+16777216*c[++a]+(c[++a]<<16)+(c[++a]<<8)+c[++a];case 206:b+=16777216*c[+
@daschl
daschl / gist:5848839
Created June 24, 2013 09:24
ASM output
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from hsdis-amd64.dylib
Decoding compiled method 0x0000000105146150:
Code:
[Disassembling for mach='i386(base-hsdis)']
[Entry Point]
[Constants]
# {method} 'hashCode' '()I' in 'java/lang/String'
# [sp+0x30] (sp of caller)
0x00000001051462a0: inc esp
@daschl
daschl / gist:6460684
Created September 6, 2013 07:35
encoding
@Override
protected void encodeHeader(ByteBuf buf, BinaryMemcacheRequestHeader header) {
buf.writeByte(header.getMagic());
buf.writeByte(header.getOpcode());
buf.writeShort(header.getKeyLength());
buf.writeByte(header.getExtrasLength());
buf.writeByte(header.getDataType());
buf.writeShort(header.getReserved());
buf.writeInt(header.getTotalBodyLength());
buf.writeInt(header.getOpaque());
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java -Didea.launcher.port=7536 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 12.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Li
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
/*
* Copyright 2013 The Netty Project
*
* The Netty Project 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
*
* Unless required by applicable law or agreed to in writing, software
@daschl
daschl / gist:6823538
Created October 4, 2013 09:46
connecting attempt. not only return it to the user, but also react on changes in an async manner.
/**
* Handle {@link ConnectRequest} messages.
*
* @param request the connect request message.
* @return a {@link ConnectResponse}.
*/
private Promise<ConnectResponse> handleConnect(ConnectRequest request) {
if (connected.get()) {
return Promises.success(ConnectResponse.alreadyConnected()).get();
} else {