Skip to content

Instantly share code, notes, and snippets.

View mayuroks's full-sized avatar

Mayur Rokade mayuroks

View GitHub Profile
package com.example.sigsegvapp
/*
* Notes:
*
* OpWeight function to get weight of an op
* Max function to return highest of two ops
*
* Evaluate entire string for all operators
* Save highest and leftmost operator
@mayuroks
mayuroks / YouTubeHelper.java
Last active October 11, 2018 19:55 — forked from jvanderwee/YouTubeHelper.java
Extract video id from YouTube url in java
import com.google.inject.Singleton;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Singleton
public class YouTubeHelper {
final String youTubeUrlRegEx = "^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))/";
final String[] videoIdRegex = { "\\?vi?=([^&]*)","watch\\?.*v=([^&]*)", "(?:embed|vi?)/([^/?]*)", "^([A-Za-z0-9\\_-]*)"};
open class Animal { // Parent class
var name: String? = null // Nullable variable
var legs: Int = 0 // Non-nullable variable
lateinit var map: HashMap<Integer, String> // Variable inited later in the code
constructor(legs: Int) {
this.legs = legs
}
constructor(legs: Int, name: String) {
@mayuroks
mayuroks / vairables.kt
Created August 23, 2018 15:46
Kotlin variables
// Use var to declare a variable, whose value can be changed later
var b: String = "Wow"
// val in Kotlin is same as final in Java
val a: Int = 0
// To initialize a variable as null
var c: String? = null
// Initialize a variable later in the code using lateInit
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvStatus"
public class MainActivity extends AppCompatActivity {
private ApiService apiService = HttpClient.getApiService();
private TextView tvStatus, tvInfo;
private Button btnHttpRequest, btnReset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class SchedulerProvider {
// UI thread
public static Scheduler ui() {
return AndroidSchedulers.mainThread();
}
// IO thread
public static Scheduler io() {
return Schedulers.io();
public class HttpClient {
private static final String API_BASE_URL = "https://jsonplaceholder.typicode.com/";
private static Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
private static ApiService apiService = retrofit.create(ApiService.class);
public interface ApiService {
@GET("/todos/1")
Flowable<Todo> getFirstTodo();
}
public class Todo {
String userId;
int id;
String title;
boolean completed;
public String getFormattedInfo() {
StringBuilder builder = new StringBuilder();
builder.append("Title: " + title + "\n\n");