Skip to content

Instantly share code, notes, and snippets.

View Kurukshetran's full-sized avatar
🎯
Focusing

Kurukshetran Kurukshetran

🎯
Focusing
View GitHub Profile
@Kurukshetran
Kurukshetran / gist:83aa22b995e9e305b6fb226398cb3146
Created April 8, 2019 09:12 — forked from alder/gist:1420a45c19cb947e03ce
Manually read CSV data in JMeter witn BeanShell
import java.text.*;
import java.io.*;
import java.util.*;
String filename = "oprosnik_" + vars.get("fileNum") + ".csv";
ArrayList strList = new ArrayList();
try {
File file = new File(filename);
@Kurukshetran
Kurukshetran / CreditCardNumberGenerator.java
Created March 28, 2019 07:29 — forked from josefeg/CreditCardNumberGenerator.java
Credit card number generator in Java
import java.util.Random;
/**
* A credit card number generator.
*
* @author Josef Galea
*/
public class CreditCardNumberGenerator {
private Random random = new Random(System.currentTimeMillis());
@Kurukshetran
Kurukshetran / native-mem-tracking.md
Created March 12, 2019 07:35 — forked from prasanthj/native-mem-tracking.md
Native memory tracking in JVM

Enable native memory tracking in JVM by specifying the following flag

-XX:NativeMemoryTracking=detail

Know the <PID> of the java process

jps

To print ps based RSS

ps -p <PID> -o pcpu,rss,size,vsize

To print native memory tracking summary

I'm afraid the paths you are storing in MongoDB won't be very useful, since they are simply the default toString() representation of the referenced collection item. In order to use this path to access the property via java-object-diff, you'd need to be able to deserialize it to an actual instance of an object that has the same identity (equals == true) as the one you want to reference.

There are ways to do that, like writing a custom serializer for the PropertyPath to serialize a deserializable version of the reference item, but that leads to pretty verbose JSON and is rather fragile.

I personally don't recommend storing the diff in a database, but rather compare two document versions on demand. Depending on your scenario that may or may not cause performance issues. If it does, there are usually ways to cache the information you actually need, without storing the entire diff in the database.

I once had the same problem when I tried to generate a Github-like activity stream. I first approached it by stor

@Kurukshetran
Kurukshetran / MyComponent.java
Created March 7, 2019 13:34 — forked from milanboers/MyComponent.java
Enable/disable Spring component by property
@Component
@Conditional(MyComponent.EnabledCondition.class)
public class MyComponent {
protected static class EnabledCondition implements Condition {
private static final String ENABLED_PROPERTY = "mycomponent.enabled";
@Override
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
final Environment environment = context.getEnvironment();
return environment != null && Boolean.valueOf(environment.getProperty(ENABLED_PROPERTY));
}
@Kurukshetran
Kurukshetran / on-jsx.markdown
Created February 18, 2019 11:30 — forked from chantastic/on-jsx.markdown
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@Kurukshetran
Kurukshetran / gist:e690ce1fdec8618a17e41e47290cb396
Created February 18, 2019 07:03 — forked from kirkch/gist:3402882
Fast ways of writing to disk in Java
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
/**
* Compares the performance of streaming data to disk vs using memory mapped files.
*.
public class MappedIO {
private static int numOfInts = 4000000;
@Kurukshetran
Kurukshetran / README.md
Created February 13, 2019 15:03 — forked from jordansissel/README.md
logstash internal messaging and queues

Logstash internals (Queues and Threading)

The logstash agent is 3 parts: inputs -> filters -> outputs.

Each '->' is an internal messaging system. It is implemented with a 'SizedQueue' in Ruby. SizedQueue allows a bounded maximum of items in the queue such that any writes to the queue will block if the queue is full at maximum capacity.

Logstash sets the queue size to 20. This means only 20 events can be pending into the next phase - this helps reduce any data loss and in general avoids logstash trying to act as a data storage system. These internal queues are not for storing messages long-term.

In reverse, here's what happens with a queue fills.

@Kurukshetran
Kurukshetran / CustomResponseEntityExceptionHandler.java
Created January 4, 2019 06:36 — forked from matsev/CustomResponseEntityExceptionHandler.java
Generic response error handling using @ControllerAdvice
@ControllerAdvice
public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors();
List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size());
String error;
for (FieldError fieldError : fieldErrors) {
@Kurukshetran
Kurukshetran / DateTime
Created December 29, 2018 11:32 — forked from shady-robot/DateTime
A reference for datetime format
Mostly about the java.time package, about time and date format issue.
Nothing Special, just for reference.