Skip to content

Instantly share code, notes, and snippets.

View fnk0's full-sized avatar

Marcus Gabilheri fnk0

  • Snap
  • Los Angeles, CA
View GitHub Profile
public interface GithubAuth {
@POST("/authorizations")
UserToken getUserToken(
@Body LoginRequest body
);
}
@fnk0
fnk0 / JSonToCSV
Last active August 29, 2015 14:16
Simple function to convert a JSON to a csv object and download the file
var JSONToCSVConvertor = function (JSONData, ReportTitle, ShowLabel) {
//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var date = new Date();
var CSV = '';
//Set Report title in first row or line
CSV += 'MyTitle ' + date + '\r\n';
//This condition will generate the Label/Header
@fnk0
fnk0 / DetailActivity.java
Last active August 29, 2015 14:17
Inflating view
View v = LayoutInflater.from(activityContext).inflate(R.layout.fragment_share, null);
v.setLayoutParams(new RelativeLayout.LayoutParams(2048, 1536));
LinearLayout shareLayout = (LinearLayout) v.findViewById(R.id.share_layout);
shareLayout.setLayoutParams(new LinearLayout.LayoutParams(2048, 1536));
Bitmap b = PictureUtils.loadBitmapFromView(shareLayout);
PictureUtils.saveBitmap(b, false);
@fnk0
fnk0 / BaseActivity.java
Created March 16, 2015 15:22
GoogleFitClient
public void startFitnessClient() {
mGoogleFitClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
if (hasWearDevice) mGoogleFitClient.connect();
}
@fnk0
fnk0 / Collatz.java
Last active October 11, 2015 21:23
CodeU Session 1 Problems
public class Collatz {
//Consider a sequence of positive integers starting with x.If x is
// even,the next integer in the sequence is x/2.If x is odd, the
// next integer in the sequence is 3 * x + 1. The sequence stops when it
// reaches1.
//
// For example, if x is 7, the sequence is
//
// 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
//
@fnk0
fnk0 / Collatz.java
Last active October 11, 2015 21:23
Session 1 - Solutions
/**
* Created by <a href="mailto:marcusandreog@gmail.com">Marcus Gabilheri</a>
*
* @author Marcus Gabilheri
* @version 1.0
* @since 3/16/15
*/
public class Collatz {
// Consider a sequence of positive integers starting with x.If x is
// even,the next integer in the sequence is x/2.If x is odd, the
@fnk0
fnk0 / VideoDownloader.java
Last active March 13, 2024 08:48
Example of how to download a video using Okhttp and show a progress bar to the user
class VideoDownloader extends AsyncTask<Void, Long, Boolean> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(Void... params) {
@fnk0
fnk0 / BinaryTreeNode.java
Last active October 11, 2015 21:22
Collatz Graph: Code U session2
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Created by marcus on 4/12/15.
*/
public class BinaryTreeNode {
@fnk0
fnk0 / CollatzGraph.java
Last active October 11, 2015 21:21
Session 3 of the CodeU exercises
import com.google.gson.Gson;
import com.oracle.javafx.jmx.json.JSONWriter;
import jdk.nashorn.api.scripting.JSObject;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class CollatzGraph {
@fnk0
fnk0 / MathUtils.java
Created May 4, 2015 23:54
Simple methots to calculate the Min or Max of a list of integers. The same logic can be applied for floats, double, longs, etc..
/**
* Calculates the max of several integers at once.
*
* @param values
* 2 or more integers to which the maximum should be calculated
* @return The maximum value in the list
*/
public static int max(@NonNull int... values) {
if (values.length < 2) {
throw new RuntimeException("At least 2 integers are needed in order to calculate the maximum value.");