Skip to content

Instantly share code, notes, and snippets.

View maniksurtani's full-sized avatar

Manik Surtani maniksurtani

View GitHub Profile
@maniksurtani
maniksurtani / gist:f9cc0f3787bc2d55e953918317c1aa41
Created July 13, 2016 23:12
Square Inc. Individual Contributor License Agreement
An Individual Contributor License Agreement (an "Agreement") is required to establish and define the intellectual property license granted in connection with Contributions (defined below) from any person or entity to Square, Inc. (“Square”) for inclusion in any of the products owned or managed by Square (the “Work”). This Agreement is for your protection as well as Square’s. This Agreement does not alter your rights to use your own Contributions for other purposes. By executing this Agreement, you accept and agree to the following terms and conditions for any past, current, or future Contributions submitted to Square. Except for the license granted herein to Square and recipients of software distributed by Square, you reserve all right, title, and interest in and to the Contributions you create.
1. Definitions.
“Control:” shall mean (i) the power, direct or indirect, to cause the direction or management of an entity, whether by contract or otherwise; or (ii) ownership of fifty percent (50%) or more of the ou
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import static java.lang.System.currentTimeMillis;
public class HikariTest {
private static String db1 = "test1";
private static String db2 = "test2";
private static int RUNS = 5000;
@maniksurtani
maniksurtani / address.py
Created June 9, 2014 13:57
Address checker
import re
_POSTCODE_RE = re.compile('\s*[a-zA-Z]{1,2}[0-9][0-9a-zA-Z]?\s?[0-9][a-zA-Z]{2}\s*')
_SPLIT_POSTCODE_RE = re.compile('(.*)\s*([a-zA-Z]{1,2}[0-9][0-9a-zA-Z]?\s?[0-9][a-zA-Z]{2})\s*')
_COORDS_RE = re.compile("^([0-9.-]+),([0-9.-]+)$")
def is_coords(address):
return _COORDS_RE.match(address) != None
def is_postcode(address):
boolean debug = log.isDebugEnabled();
long start = debug ? System.nanoTime() : -1;
// do some work
if (debug)
log.debug("Duration(ms)..." + ((System.nanoTime() - start)/1000000000) + "\n"+ "\n");
@maniksurtani
maniksurtani / gist:5531469
Last active December 17, 2015 01:49
Bad code
Date timeStart1 = new Date();
// do some work
long timeDiff = Math.abs(new Date().getTime() - timeStart1.getTime());
log.debug("Duration(ms)..."+timeDiff+ "\n"+ "\n");
MapStressTest configuration: capacity 100000, test running time 60 seconds
Testing mixed read/write performance with capacity 100,000, keys 300,000, concurrency level 32, threads 12, read:write ratio 0:1
Container BCHM:LIRS Ops/s 3,031,391.87 Gets/s 0.00 Puts/s 3,031,391.87 HitRatio 77.07 Size 100,000 stdDev 54,867.90
Container BCHM:LRU Ops/s 2,637,209.78 Gets/s 0.00 Puts/s 2,637,209.78 HitRatio 72.66 Size 100,000 stdDev 54,903.04
Container CACHE:LIRS Ops/s 1,884,246.44 Gets/s 0.00 Puts/s 1,884,246.44 HitRatio 63.10 Size 100,000 stdDev 54,738.82
Container CACHE:LRU Ops/s 1,853,873.18 Gets/s 0.00 Puts/s 1,853,873.18 HitRatio 64.63 Size 100,000 stdDev 54,775.65
Container CACHE:NONE Ops/s 5,881,494.23 Gets/s 0.00 Puts/s 5,881,494.23 HitRatio 100.00 Size 262,682 stdDev 77,540.73
Container CHM Ops/s 21,165,771.67 Gets/s 0.00 Puts/s 21,165,771.67 HitRatio 100.00 Size 262,6
Multiverse:my_repo manik [t_tx_improvements]$ git graph
* 346d843 (HEAD, t_tx_improvements) reduced contention by avoiding an unnecessary CHM.putIfAbsent
* 6089b46 (upstream/master, origin/master, origin/HEAD, master) ISPN-1581 - Improve resiliency of retrying commits on state transfer
* 1b8cc1e ISPN-1662 - Transactions unblocked too early
* 21d233e ISPN-1658 - Can't cancel state transfer on the coordinator if a node left
* 764f2d7 L1OnRehashTest was waiting for the joiner to finish joining but not for all the other caches to finish invalidating keys before checking the ownership.
* 72a3b8b ISPN-1189, sanitise cache mode parsing
package org.infinispan.config;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory;
import org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore;
import org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.TestingUtil;
...
import org.infinispan.cdi.OverrideDefault;
import javax.annotation.Resource;
class Config {
@Resource(lookup="java:jboss/infinispan/my-container-name")
@OverrideDefault
@Produces
EmbeddedCacheManager defaultCacheManager;
}
...
import javax.cache.interceptor.CacheResult;
import javax.cache.interceptor.CachePut;
import javax.cache.interceptor.CacheValue;
import javax.cache.interceptor.CacheRemoveEntry;
import javax.cache.interceptor.CacheRemoveAll;
class MyDAO {
@CacheResult(cacheName="user-cache")
User getUser(long id){...};