Skip to content

Instantly share code, notes, and snippets.

View Weighted Random
class Solution {
private int[][] ranges;
private int totalSum;
private Random random;
public Solution(int[] weights) {
ranges = new int[weights.length][2];
for (int i=0, current = 0; i < weights.length; i++) {
View lengthOfLongestSubstringKDistinct
public int lengthOfLongestSubstringKDistinct(String str, int k) {
int maxLength = 0;
int distinct = 0;
int[] charCounts = new int[256];
for (int left = 0, right = 0; right < str.length(); right++) {
char rightChar = str.charAt(right);
if (charCounts[rightChar] == 0) {
distinct++;
}
charCounts[rightChar]++;
View S3ObjectMerger
package s3;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.*;
import com.google.common.base.Stopwatch;
import org.slf4j.Logger;
@azimbabu
azimbabu / GcsStorageProvider.java
Last active Aug 18, 2017
GCS based Storage Provider for mime4j
View GcsStorageProvider.java
import com.google.appengine.tools.cloudstorage.GcsFileOptions;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsInputChannel;
import com.google.appengine.tools.cloudstorage.GcsOutputChannel;
import com.google.appengine.tools.cloudstorage.GcsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.james.mime4j.storage.AbstractStorageProvider;
import org.apache.james.mime4j.storage.Storage;
import org.apache.james.mime4j.storage.StorageOutputStream;
@azimbabu
azimbabu / ClassLoaderLeakExample.java
Created Mar 22, 2016 — forked from dpryden/ClassLoaderLeakExample.java
Example of a ClassLoader leak in Java
View ClassLoaderLeakExample.java
import java.io.IOException;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
/**
* Example demonstrating a ClassLoader leak.
*
* <p>To see it in action, copy this file to a temp directory somewhere,
You can’t perform that action at this time.