Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Learning

Pranav Lathigara pranavlathigara

🤓
Learning
  • Rajkot
View GitHub Profile
@fuadarradhi
fuadarradhi / AesCipher.java
Created Jan 6, 2019 — forked from demisang/AesCipher.java
AES/CBC/PKCS5Padding encrypt/decrypt PHP and JAVA example classes
View AesCipher.java
import android.support.annotation.Nullable;
import android.util.Base64;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@mzgreen
mzgreen / SizeHelper.kt
Last active Feb 13, 2021
A ConstraintHelper implementation that has additional layout params: screenHeight_percent and screenWidth_percent which allow to make referenced views height and width to be equal to screenHeight(or screenWidth)*some_percent_value. Where some_percent_value is a value between 0.0 and 1.0.
View SizeHelper.kt
class SizeHelper @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintHelper(context, attrs, defStyleAttr) {
private val screenHeight: Int = resources.displayMetrics.heightPixels
private val screenWidth: Int = resources.displayMetrics.widthPixels
private var layoutConstraintScreenHeightPercent = UNSPECIFIED_CONSTRAINT_SCREEN_PERCENT
@sandeeptengale
sandeeptengale / BaseActivity.java
Last active Dec 17, 2020
Sample code to create BaseActivity for Android
View BaseActivity.java
package com.vtuforum.android.views
import android.app.ProgressDialog
import android.os.Bundle
import android.support.design.widget.CoordinatorLayout
import android.support.v7.app.AppCompatActivity
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.TextView
import com.vtuforum.vtustudies.R
@sjthn
sjthn / RecyclerViewAdapter.kt
Last active May 7, 2018
Kotlin template for RecyclerView Adapter in Android Studio
View RecyclerViewAdapter.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
#end
#parse("File Header.java")
class ${NAME}(private var items: MutableList<${ITEM_TYPE}>): RecyclerView.Adapter<${VIEWHOLDER}>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${VIEWHOLDER} {
@demisang
demisang / AesCipher.java
Last active Apr 6, 2021
AES/CBC/PKCS5Padding encrypt/decrypt PHP and JAVA example classes
View AesCipher.java
import android.support.annotation.Nullable;
import android.util.Base64;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@karthikeyan5
karthikeyan5 / GSTINValidator.java
Last active Jun 1, 2019
GSTIN Validator with checksum validation (Java,Python)
View GSTINValidator.java
// from http://developer.gstsystem.co.in/apiportal/howToStart/download
package org.gst.poc.util;
import java.util.Scanner;
public class GSTINValidator {
public static final String GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
public static final String GSTN_CODEPOINT_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static void main(String args[]) {
View BaseDao.kt
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Diederikjh
Diederikjh / Cryptography.java
Last active Mar 31, 2021
Single class that handles encryption and decryption with keys using the Android `Keystore` API. Mostly inspired by this [blog post](https://medium.com/@ericfu/securely-storing-secrets-in-an-android-application-501f030ae5a3). This was tested with API 18 and 25 level emulator (and a level 23 device).
View Cryptography.java
package com.example.yourapp;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.security.KeyPairGeneratorSpec;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.support.annotation.RequiresApi;
@krupalshah
krupalshah / PreferenceHelper.kt
Last active May 2, 2021
helper for shared prefs - kotlin version - Final implementation
View PreferenceHelper.kt
object PreferenceHelper {
fun defaultPrefs(context: Context): SharedPreferences
= PreferenceManager.getDefaultSharedPreferences(context)
fun customPrefs(context: Context, name: String): SharedPreferences
= context.getSharedPreferences(name, Context.MODE_PRIVATE)
inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) {
val editor = this.edit()
@Haehnchen
Haehnchen / decrypt.java
Created May 14, 2017
PHP encrypt and JAVA decrypt with openssl and AES-128-CBC
View decrypt.java
public static String decrypt(@NotNull String input, @NotNull String key){
byte[] bytes = Base64.decodeBase64(input);
if(bytes.length < 17) {
return null;
}
byte[] ivBytes = Arrays.copyOfRange(bytes, 0, 16);
byte[] contentBytes = Arrays.copyOfRange(bytes, 16, bytes.length);