Skip to content

Instantly share code, notes, and snippets.

View vedhavyas's full-sized avatar
🐧

Vedhavyas Singareddi vedhavyas

🐧
View GitHub Profile
@vedhavyas
vedhavyas / Attributes.java
Created November 28, 2014 08:44
Attribute combinations - A snippet to display the combinations of attributes
import java.util.Scanner;
public class Attributes{
public static void main(String [] args){
Scanner scanIN = new Scanner(System.in);
Scanner scanSTR = new Scanner(System.in);
String [] temp;
String str;
System.out.println("No. of attributes");
int numAtr = scanIN.nextInt();
@vedhavyas
vedhavyas / FetchUserPhoneNumber.java
Last active December 18, 2015 05:53
This code will fetch user phone number from contact card as well as accounts
private ArrayList<String> getOwnerPhone() {
ArrayList<String> numbers = new ArrayList<>();
getPhoneFromContacts(numbers);
getPhoneFromProfile(numbers);
return numbers;
}
private void getPhoneFromContacts(ArrayList<String> numbers) {
final AccountManager manager = AccountManager.get(this);
final Account[] accounts = manager.getAccountsByType("com.google");
@vedhavyas
vedhavyas / FloatingService.java
Created April 10, 2016 12:07
Android Floating label
package com.instamojo.mink.services;
import android.animation.ValueAnimator;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.IBinder;
import android.view.Gravity;
@vedhavyas
vedhavyas / PostExampleAndroid
Last active April 18, 2016 12:03
POST Request example in Android
//Add library by adding the following line in dependencies section in gradle file
compile 'com.squareup.okhttp3:okhttp:3.2.0'
//Making a Post request
OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder()
.add("name", "Name Here")
.add("email", "email here")
.add("purpose", "purpose here")

Keybase proof

I hereby claim:

  • I am vedhavyas on github.
  • I am vedhavyas (https://keybase.io/vedhavyas) on keybase.
  • I have a public key whose fingerprint is F41E CDD3 DC96 7F1A AF2D 0308 BF62 2A66 FD4B 3589

To claim this, I am signing this object:

@vedhavyas
vedhavyas / .profile
Created July 12, 2017 13:04 — forked from bmhatfield/.profile
Automatic Git commit signing with GPG on OSX
# In order for gpg to find gpg-agent, gpg-agent must be running, and there must be an env
# variable pointing GPG to the gpg-agent socket. This little script, which must be sourced
# in your shell's init script (ie, .bash_profile, .zshrc, whatever), will either start
# gpg-agent or set up the GPG_AGENT_INFO variable if it's already running.
# Add the following to your shell init to set up gpg-agent automatically for every shell
if [ -f ~/.gnupg/.gpg-agent-info ] && [ -n "$(pgrep gpg-agent)" ]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else
@vedhavyas
vedhavyas / golang_pipe_http_response.go
Created January 18, 2018 10:07 — forked from ifels/golang_pipe_http_response.go
golang pipe the http response
package main
import (
"io"
"net/http"
"os/exec"
)
var (
BUF_LEN = 1024
@vedhavyas
vedhavyas / pr.md
Created August 21, 2018 03:45 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@vedhavyas
vedhavyas / numbers.go
Created December 29, 2018 22:17
Encode and Decode integers into []byte(inspired from a blog i couldn't find)
package main
import "fmt"
func main() {
nums := []int{256, 2, 100, 122234456, 10024}
fmt.Println(nums)
buf := encodeNumbers(nums...)
fmt.Println(buf)
fmt.Println(decodeNumbers(buf))
@vedhavyas
vedhavyas / kadanes.go
Created February 1, 2019 12:22
Kadane's algorithm to find max subarray
package main
import "fmt"
func kadanes(d []int) int {
var lm, gm int
var init bool
for _, n := range d {
lm = max(n, n+lm)