Skip to content

Instantly share code, notes, and snippets.

View umermansoor's full-sized avatar
🏠
Working from home

Umer Mansoor umermansoor

🏠
Working from home
  • San Francisco
View GitHub Profile
@umermansoor
umermansoor / unlaunch.java
Created August 5, 2021 05:25
Unlaunch Java
// initialize the client
UnlaunchClient client = UnlaunchClient.create("your_sdk_key");
// get variation
String variation = client.getVariation("flag_key", "userID_123");
// take action based on the returned variation
if (variation.equals("on")) {
// show the feature
} else if (variation.equals("off")) {
class Task implements IdentifiableCallable<Boolean> {
private final int id; // Task Identifier
volatile boolean cancelled; // Cancellation flag
public Task(int id) {
this.id = id;
}
@Override
/* A Custom Wrapper around FutureTask for returning Task Id.
* @author umermansoor
*/
public abstract class FutureTaskWrapper<T> extends FutureTask<T> {
public FutureTaskWrapper(Callable<T> c) {
super(c);
}
abstract int getTaskId();
/**
* Custom Callable Interface with Id.
* @author umermansoor
*/
public interface IdentifiableCallable extends Callable {
int getId(); // For getting task Id
void cancelTask(); // Method for supporting non-standard cancellation
RunnableFuture newTask();
}
public class CustomFutureReturningExecutor extends ThreadPoolExecutor {
public CustomFutureReturningExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
@Override
protected RunnableFuture newTaskFor(Callable callable) {
if (callable instanceof IdentifiableCallable) {
return ((IdentifiableCallable) callable).newTask();
class CancelleableSocketThread extends Thread {
@Override
public void interrupt() {
try {
server.close();
} catch (IOException ignored) {
class CancelleableSocketThread extends Thread {
@Override public void interrupt() {
try {
server.close();
} catch (IOException ignored) { }
finally { super.interrupt(); }
@umermansoor
umermansoor / gist:4525814
Created January 13, 2013 19:36
a sample .bash_profile for Hadoop
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
export HADOOP_INSTALL=/Users/umermansoor/Documents/hadoop-1.1.1
export PATH=$PATH:$HADOOP_INSTALL/bin
<!-- exec plugin to run the python script which generates annotations -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>gen_ver_from_python</id>
<phase>generate-sources</phase>
<goals>
<!-- Need this to detect source files in target/generated-sources folder -->
<!-- If used with a parent POM, the build-helper plugin stays with the child POM -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>