Skip to content

Instantly share code, notes, and snippets.

View rezaiyan's full-sized avatar
👋

Ali Rezaiyan rezaiyan

👋
View GitHub Profile
@rezaiyan
rezaiyan / MockResponse.kt
Created October 21, 2022 07:05
Mock response
View MockResponse.kt
val client = OkHttpClient.Builder()
.addInterceptor(MockInterceptor())
.build()
//-------------------------
import okhttp3.Interceptor
import okhttp3.Protocol
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
View rmbuild.sh
#!/bin/bash
#hi
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for rootFolder in */ ; do
if [ -d $rootFolder"build" ]; then
echo "do you want to delete build folders of \"${rootFolder%?}\" project?"
read ans
if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
@rezaiyan
rezaiyan / build.gradle
Created May 6, 2021 19:16
Add your android library to the sonatype (maven central)
View build.gradle
Define these lines to the library gradle file:
project.group = "io.github.rezaiyan"
project.archivesBaseName = "LevelProgressBar"
project.version = "1.0.0"
apply from: '../publish.gradle'
@rezaiyan
rezaiyan / Activity.java
Created March 7, 2021 14:49
Transparent Activity
View Activity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
}
}
View MultipartHelper.java
public class MultipartHelper {
private final String fileDir;
private final String outputDir;
public MultipartHelper(String fileDir, String outputDir) {
this.fileDir = fileDir;
String baseDir = BaseApplication.getAppContext().getObbDir() + File.separator + "uploads";
this.outputDir = baseDir + File.separator;
File upload = new File(baseDir);
@rezaiyan
rezaiyan / StaggeredGridLayoutManager.java
Created September 29, 2020 09:24
To have a full width item in the StaggeredGridLayoutManager
View StaggeredGridLayoutManager.java
ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
if (getAdapterPosition() == 0) {
((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true);
} else {
((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(false);
}
}
@rezaiyan
rezaiyan / Degree.java
Created July 4, 2020 20:37
Array degree algo
View Degree.java
public static String codeHere(String inputData) {
// Use this function to write your solution;
String[] arrayInfo = inputData.split("\n");
int size = Integer.parseInt(arrayInfo[0]);
int[] lenghsArray = new int[size];
String[] stringArray = arrayInfo[1].split(" ");
List<Integer> subArray = new ArrayList<>();
@rezaiyan
rezaiyan / Projection.java
Last active April 19, 2020 04:53
EPSG 4326 , EPSG 3857 converter
View Projection.java
private static double EARTH_RADIUS = 6378137.0;
public static LatLng to4326(Wgs84 wgs84) {
double lat = Math.toDegrees(Math.atan(Math.exp(wgs84.getY() / EARTH_RADIUS)) * 2 - Math.PI/2);
double lng = Math.toDegrees(wgs84.getX() / EARTH_RADIUS);
return new LatLng(lat, lng);
}
public static Wgs84 toWgs84(LatLng latLng) {
double x = Math.toRadians(latLng.longitude) * EARTH_RADIUS;
@rezaiyan
rezaiyan / SharedViewModel.java
Last active November 11, 2019 08:01
This is a simple example of a shared viewmodel
View SharedViewModel.java
class SharedViewModel extends ViewModel {
public MutableLiveData<String> liveData = new MutableLiveData<>();
}
class parentFragment {
sharedVm = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);