Skip to content

Instantly share code, notes, and snippets.

View anuragkapur's full-sized avatar

Anurag Kapur anuragkapur

View GitHub Profile
public int maxScoreForString(String str) {
//Init frequency of chars
int frequencyOfChars[] = new int[26];
//Case insensitive logic
str = str.toLowerCase();
//Populate frequencyOfChars based on characters of input string
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
public boolean isBalancedMessage(String msg) {
boolean isBalanced = true;
int countSmileys = 0;
// cleanup message string
char[] characters = msg.toCharArray();
StringBuffer cleanedMessageBuffer = new StringBuffer();
for (int i = 0; i < characters.length; i++) {
if(characters[i] == '(') {
public boolean isBalancedMessage(String msg) {
boolean isBalanced = true;
int minOpen = 0, maxOpen = 0;
char[] msgChars = msg.toCharArray();
for (int i = 0; i < msgChars.length; i++) {
if(msgChars[i] == '(') {
maxOpen ++;
@anuragkapur
anuragkapur / log4j.properties
Last active August 29, 2015 13:57
Sample Log4j Config via a Properties file
# Root logger option
log4j.rootLogger=ERROR, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Override logging level of a specific package
log4j.category.com.beancrunch.mycustompackage=DEBUG, stdout
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>anurag-kapur</application>
<version>master</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
# In a standard setup a remote called "heroku" points to your app. Remove this and setup two new "remotes" called "staging" and # "production".
$ git remote rm heroku
# point the remote named "staging" to the "staging" version of your app
$ git remote add staging git@heroku.com:wistreesolutions-staging.git
# point the remote named "production" to the "live" version of your app
$ git remote add production git@heroku.com:wistreesolutions.git
@anuragkapur
anuragkapur / .profile
Last active August 29, 2015 14:03
~/.profile
# .profile for anuragkapur on ak-skynet
# Maven
M2_HOME=/Users/anuragkapur/tech-stuff/tools/apache-maven/apache-maven-3.3.1
M2=$M2_HOME/bin
export PATH=$M2:$PATH
export M2_HOME=$M2_HOME
# Java
jdk7u65=/Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home
public class MyService extends Service<MyServiceConfiguration> {
@Override
public void initialize(Bootstrap<MyServiceConfiguration> bootstrap) {
bootstrap.setName("my-service");
}
@Override
public void run(AccessDropServiceConfiguration configuration, Environment environment) throws Exception {
environment.addResource(new AccessResource());
public class PlaygroundHttpClient {
private static final String X_FORWARDED_FOR = "X-Forwarded-For";
private void executeHttpGetOnDropwizardPlaygroundGreeting(String xForwardedFor, String name, String userAgent) {
URI uri = null;
try {
uri = new URIBuilder()
@Path("{path:.*}")
public class AccessResource {
private final Logger log = LoggerFactory.getLogger(AccessResource.class);
@GET
public Response checkAccessGet(@Context HttpServletRequest request) throws IOException {
logRequestInfo(request);
return checkAccess(request);
}