Skip to content

Instantly share code, notes, and snippets.

View durgaswaroop's full-sized avatar
💭
Having Fun

Swaroop durgaswaroop

💭
Having Fun
View GitHub Profile
@durgaswaroop
durgaswaroop / Kmeans Readme.md
Created June 4, 2016 13:26 — forked from umbertogriffo/Kmeans Readme.md
Step by step Code Tutorial on implementing a basic k-means in Spark in order to cluster a geo-located devices

DATASET

* Download dataset at:
* https://drive.google.com/folderview?id=0B8DR8_DnlFdQM0diSnZJNnZTYlE&usp=sharing

CODE

@durgaswaroop
durgaswaroop / git_reference.md
Last active February 1, 2018 09:53
Useful Git Reference

Interactive Rebase

git rebase -i HEAD~3 // To pick three commits including HEAD. So, you get HEAD, HEAD^, HEAD^^

squash a commit ig you want to combine two commits as a single one.

Revert a file/folder to a commit

git checkout <commit_hash> -- <file/folder name>

Diff current version of file/folder with the version on another commit

@durgaswaroop
durgaswaroop / countdown.java
Last active December 28, 2016 19:25
Serial Countdown timers in Android
private class MyTimer extends CountDownTimer {
public MyTimer(final long millisInFuture, final long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(final long milliSecondsStillLeftToFinish) {
long seconds = milliSecondsStillLeftToFinish / 1000;
long mins = seconds / 60;
@durgaswaroop
durgaswaroop / Debugging.md
Last active January 2, 2017 15:30
Intellij Debugging

From the stack overflow question here, If we have a code like this,

public class testprog {
    static void f (int x) {
        System.out.println ("num is " + (x+0)); // <- step into
    }

    static void g (int x) {
-&gt; f(x); // &lt;----------------------------------- current location
@durgaswaroop
durgaswaroop / Android_Errors.md
Last active January 3, 2017 13:38
Android Studio Error fixes

Execution failed for task ':app:clean'. Unable to delete file: ...\app\build\intermediates\exploded.....jars\classes.jar

For this File > Invalidate Cache & Restart

@durgaswaroop
durgaswaroop / exponents.py
Created September 1, 2017 21:06
Python code to solve x**x**x = 10
# Written to calculate value of x such that x**x**x = 10
# Corresponding Quora answer: https://www.quora.com/If-x-x-x-10-what-is-x/answer/DurgaSwaroop-Perla
factor = 100000000
def direction(a, b):
if abs(a - b) < (a / factor):
return 0
elif a - b < 0:
return -1
@durgaswaroop
durgaswaroop / JavaOptionalsReference.md
Last active October 5, 2023 12:00
Java Optional usage and Best practices
  • Optional.empty() - An empty optional
  • Optional.of(t) - returns a present Optional containing t. (t must be non-null)
  • Optional.ofNullable(t) - returns an Optional with t that can be null

Rules

  1. Never return null from a method that's supposed to return an optional. It defeats the purpose of Optional
  2. Never do opt.get() unless you can prove that the optional is present.
  3. Prefer alternatives to using opt.isPresent() followed by opt.get()
  4. It's generally a bad idea to create an Optional for the sole purpose of chaining methods from it to get a value.
  5. If an Optional chain is nested or has an intermediate result of Optional<Optional>, it is probably too complex.
@durgaswaroop
durgaswaroop / webscraping with python | introduction.py
Created December 19, 2017 19:19
Webscraping with python | Introduction
from bs4 import BeautifulSoup as bs
import urllib.request as ureq
# Website url
freblogg_url = 'http://freblogg.com'
# Fetch the website
website = ureq.urlopen(freblogg_url).read()
# Parse the html of the site with soup
@durgaswaroop
durgaswaroop / REST-API-with-Spark-Microframework.java
Last active December 24, 2017 17:15
Creating RESTful API's with Spark microframework using Java
import spark.Request;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletException;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
@durgaswaroop
durgaswaroop / tweet-with-tweepy.py
Created December 24, 2017 22:21
Tweet with python using tweepy
import tweepy
import os
# Read all the auth keys from environment variables
consumer_key = os.environ["t_consumer_key"]
consumer_secret = os.environ["t_consumer_secret"]
access_token = os.environ["t_access_token"]
access_token_secret = os.environ["t_access_token_secret"]
# Using the keys, setup the authorization