Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Having Fun

Aryan Dhankar GitEliteNovice

:octocat:
Having Fun
View GitHub Profile
@GitEliteNovice
GitEliteNovice / MyPool.java
Created Jan 14, 2018
Thread pool Singleton Class
View MyPool.java
package nation.know.aryan.com.poolofthreads.threadPoolClass;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
View MyRejectedExecutionHandler.java
package nation.know.aryan.com.poolofthreads.rejectedExecutionHandler;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Created by dell on 1/14/2018.
*/
View MyRunnable.java
package nation.know.aryan.com.poolofthreads.runnable;
import nation.know.aryan.com.poolofthreads.threadPoolClass.MyPool;
/**
* Created by user on 11/1/18.
*/
public class MyRunnable implements Runnable {
MyPool info;
View Knapsack Greedy Algorithm
Greedy Knapsack
{
for i=1 to n //step1
{
compute pi/wi; //step2
}
sort objects in non- increasing order p/w; //step3
for i=1 to n //step4
if(m>0 && wi<=m) //step5
View time_comlexity_fractional knapsack
Greedy Knapsack
{
for i=1 to n //step1
{
compute pi/wi; //step2
// form 1 to n we have compute above code ---- O(n) (tim taken , since it runs n times)
}
sort objects in non- increasing order p/w; //step3
@GitEliteNovice
GitEliteNovice / Webview.java
Last active Jul 9, 2020
Get Authentication code for LinkedN
View Webview.java
public class NewLinkedInIntegration extends Activity {
/*CONSTANT FOR THE AUTHORIZATION PROCESS*/
/****FILL THIS WITH YOUR INFORMATION*********/
//This is the public api key of our application
private static final String API_KEY = "your client id";
//This is the private api key of our application
private static final String SECRET_KEY = "your secret key";
View shouldOverrideUrlLoading.java
@Override
public boolean shouldOverrideUrlLoading(WebView view, String authorizationUrl) {
//This method will be called when the Auth proccess redirect to our RedirectUri.
//We will check the url looking for our RedirectUri.
if (authorizationUrl.startsWith(REDIRECT_URI)) {
Log.i("Authorize", "");
Uri uri = Uri.parse(authorizationUrl);
//We take from the url the authorizationToken and the state token. We have to check that the state token returned by the Service is the same we sent.
//If not, that means the request may be a result of CSRF and must be rejected.
String stateToken = uri.getQueryParameter(STATE_PARAM);
View getAccessTokenUrl_gist.java
private static String getAccessTokenUrl(String authorizationToken) {
return ACCESS_TOKEN_URL
+ QUESTION_MARK
+ GRANT_TYPE_PARAM + EQUALS + GRANT_TYPE
+ AMPERSAND
+ RESPONSE_TYPE_VALUE + EQUALS + authorizationToken
+ AMPERSAND
+ CLIENT_ID_PARAM + EQUALS + API_KEY
+ AMPERSAND
+ REDIRECT_URI_PARAM + EQUALS + REDIRECT_URI
View PostRequestAsyncTask.java
private class PostRequestAsyncTask extends AsyncTask<String, Void, Boolean> {
@Override
protected void onPreExecute() {
pd = ProgressDialog.show(NewLinkedInIntegration.this, "", "Loading", true);
}
@Override
protected Boolean doInBackground(String... urls) {
if (urls.length > 0) {
View getMemberInfo.java
public void sendGetRequest(String urlString, String accessToken) throws Exception {
URL url = new URL(urlString);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Bearer " + accessToken);
con.setRequestProperty("cache-control", "no-cache");
con.setRequestProperty("X-Restli-Protocol-Version", "2.0.0");
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
You can’t perform that action at this time.