Skip to content

Instantly share code, notes, and snippets.

View aasokan's full-sized avatar

Archana Asokan aasokan

View GitHub Profile
@aasokan
aasokan / latency.txt
Created April 1, 2020 01:49 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@aasokan
aasokan / AnnotationSensitivePropertyNamingStrategy.java
Created October 22, 2015 00:19
Gists for JsonSnakeCase Annotation (From Dropwizard)
package com.yammer.dropwizard.json;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
/**
* A {@link PropertyNamingStrategy} implementation which, if the declaring class of a property is
@aasokan
aasokan / xargs_notes
Created June 4, 2015 21:51
Running commands on several remote hosts using ssh and xargs
Running commands on several remote hosts using ssh and xargs
There are a few different ways to run commands on groups or clusters of remote nodes, depending upon how complex the command.
Assuming your machines are named "node01" - "node22" :
# Run a command in parallel on all remote nodes
# results come back in random order as they are received.
pdsh -w "node[01-22]" df
@aasokan
aasokan / es_endpoints
Created April 9, 2015 18:21
All Elasticsearch endpoints
AliasesExist HEAD /_alias/{name}
AliasesExist HEAD /{index}/_alias/{name}
Analyze GET /_analyze
Analyze GET /{index}/_analyze
Analyze POST /_analyze
Analyze POST /{index}/_analyze
Bulk POST /_bulk
Bulk POST /{index}/_bulk
Bulk POST /{index}/{type}/_bulk
Bulk PUT /_bulk
@aasokan
aasokan / mvn_package_test
Created February 4, 2015 19:57
Maven skip compiling tests
// Skip compiling and running tests
mvn package -Dmaven.test.skip=true
// Skip running tests in the Jar but compile (and include) them in the jar
mvn package -DskipTests
//
mvn package
@aasokan
aasokan / assisted_inject
Created February 3, 2015 23:56
Guice Assisted Inject
AssistedInject allows you to dynamically configure Factory for class instead of coding it by yourself. This is often useful when you have an object that has a dependencies that should be injected and some parameters that must be specified during creation of object.
Example from docummentaiton is a RealPayment
public class RealPayment implements Payment {
@Inject
public RealPayment(
CreditService creditService,
AuthService authService,
@Assisted Date startDate,
@aasokan
aasokan / checked_provider_guice.java
Last active August 29, 2015 14:14
Checked Provider guice
// CheckedProvider is an interface, which is a part of extension guice-throwingproviders.
public interface CheckedProvider<T> {
T get() throws Exception;
}
// Injection
@Inject
private ExcelCheckedProvider<FlightSupplier> excelCheckedProvider;
// Binding
@aasokan
aasokan / constant_binding_guice
Created February 3, 2015 19:54
Binding Constants [Guice]
bindConstant().
annotatedWith(Names.named("maxResults")).
to(10);
@Inject
public void setMaxResults(@Named("maxResults")int maxResults) {
this.maxResults = maxResults;
}
@aasokan
aasokan / inject_builder
Created February 2, 2015 23:16
Builder Providers
public class DelivererBuilder {
private final MailServerFinder finder;
private Newsletter newsletter;
private String mailServerUrl;
private int port;
@Inject
public DelivererBuilder(MailServerFinder finder) {
this.finder = finder;
}
@aasokan
aasokan / reset_builder
Created February 2, 2015 23:14
Resetting Builders to avoid corruption
public Deliverer buildDeliverer() {
try {
return new Deliverer(letter, mailServerUrl, port);
} finally {
letter = null;
mailServerUrl = null;
port = -1;
}
}