Skip to content

Instantly share code, notes, and snippets.

@skamille
skamille / reversint
Created May 17, 2014 00:13
how I would do this
List<String> list = Lists.newArrayList("sweet", "baby", "jesus");
List<String> reversed = Lists.newArrayList();
for(String item: list) {
String reversedString = new StringBuilder(item).reverse().toString();
reversed.add(reversedString);
}
@skamille
skamille / gist:2848015
Created June 1, 2012 01:51
Lists.transform
transform
public static <F,T> List<T> transform(List<F> fromList,
Function<? super F,? extends T> function)
Returns a list that applies function to each element of fromList. The returned list is a transformed view of fromList; changes to fromList will be reflected in the returned list and vice versa.
Since functions are not reversible, the transform is one-way and new items cannot be stored in the returned list. The add, addAll and set methods are unsupported in the returned list.
The function is applied lazily, invoked when needed. This is necessary for the returned list to be a view, but it means that the function will be applied many times for bulk operations like List.contains(java.lang.Object) and List.hashCode(). For this to perform well, function should be fast. To avoid lazy evaluation when the returned list doesn't need to be a view, copy the returned list into a new list of your choosing.
@skamille
skamille / gist:2847943
Created June 1, 2012 01:37
guava bug
List<Item> items = productCatalogClient.callEndpoint(getEndpoint(), map);
List<String> styleNames = Lists.transform(items, new Function<Item, String>() {
@Override
public String apply(Item item) {
return item.getStyleName();
}
});
// Save the styleNames in Cache
CacheUtil.getCache(FILTER_QUERY_CACHE_NAME).put(new Element(key, styleNames));
@skamille
skamille / log_snippet
Created May 3, 2012 17:21
ZK log snippet
2012-01-25 20:53:29,100 4079 [QuorumPeer[myid=119]/90.0.0.2:2888] DEBUG org.apache.zookeeper.server.quorum.CommitProcessor - Committing request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a
2012-01-25 20:53:29,100 4079 [CommitProcessor:119] DEBUG org.apache.zookeeper.server.FinalRequestProcessor - Processing request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a
2012-01-25 20:53:29,100 4079 [CommitProcessor:119] TRACE org.apache.zookeeper.server.FinalRequestProcessor - :Esessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a
2012-01-25 20:53:29,145 4124 [QuorumPeer[myid=119]/90.0.0.2:2888] DEBUG org.apache.zookeeper.server.quorum.CommitProcessor - Committing request:: sessionid:0x1e3516a4f8520001 type:setData cxid:0x4f206ccf zxid:0xf0000002e txntype:5 reqpath:n/a
2012-01-25 20:53:29,145 4124 [CommitProcessor:119] DEBUG org.apache.zookeeper.server.FinalRequestProce
2012-01-25 20:53:29,098 4077 [CommitProcessor:119] DEBUG Ignoring processTxn failure hdr: -1 : error: -110 org.apache.zookeeper.server.DataTree
2012-01-25 20:53:29,100 4079 [QuorumPeer[myid=119]/90.0.0.2:2888] DEBUG Committing CREATE request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a -org.apache.zookeeper.server.quorum.CommitProcessor
2012-01-25 20:53:29,100 4079 [CommitProcessor:119] DEBUG Processing CREATE request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a -org.apache.zookeeper.server.FinalRequestProcessor
2012-01-25 20:53:29,100 4079 [CommitProcessor:119] TRACE :Esessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a -org.apache.zookeeper.server.FinalRequestProcessor
2012-01-25 20:53:29,145 4124 [QuorumPeer[myid=119]/90.0.0.2:2888] DEBUG Committing SETDATA request:: sessionid:0x1e3516a4f8520001 type:setData cxid:0x4f206ccf zxid:0xf0000002e txntype:5 reqpa
@skamille
skamille / log_snippet
Created May 2, 2012 15:10
ZK log snippet
2012-01-25 20:53:29,098 4077 [CommitProcessor:119] DEBUG org.apache.zookeeper.server.FinalRequestProcessor - Processing request:: sessionid:0x1e3516a4f8520001 type:error cxid:0x4f206ca8 zxid:0xf0000002c txntype:-1 reqpath:n/a
2012-01-25 20:53:29,098 4077 [CommitProcessor:119] TRACE org.apache.zookeeper.server.FinalRequestProcessor - :Esessionid:0x1e3516a4f8520001 type:error cxid:0x4f206ca8 zxid:0xf0000002c txntype:-1 reqpath:n/a
2012-01-25 20:53:29,098 4077 [CommitProcessor:119] DEBUG org.apache.zookeeper.server.DataTree - Ignoring processTxn failure hdr: -1 : error: -110
2012-01-25 20:53:29,100 4079 [QuorumPeer[myid=119]/90.0.0.2:2888] DEBUG org.apache.zookeeper.server.quorum.CommitProcessor - Committing request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf0000002d txntype:1 reqpath:n/a
2012-01-25 20:53:29,100 4079 [CommitProcessor:119] DEBUG org.apache.zookeeper.server.FinalRequestProcessor - Processing request:: sessionid:0x1e3516a4f8520001 type:create cxid:0x4f206cac zxid:0xf000