Skip to content

Instantly share code, notes, and snippets.

View harish81's full-sized avatar
🏠
Working from home

Harish Nandoliya harish81

🏠
Working from home
View GitHub Profile
@harish81
harish81 / mime_type.php
Created April 7, 2019 03:09
Get Mime-Type based on filename in php
/**
* @param $filename string filename
* @return string mime-type of file
*/
private function getMimeContentType($filename)
{
$ar = explode(".", $filename);
$ext = $ar[count($ar) - 1];
$mime_types = array(
'.3dm' => 'x-world/x-3dmf',
@harish81
harish81 / style.css
Created October 24, 2019 06:20
Mini Table CSS - Mini responsive table using only css
div.table-mini-container {
overflow: auto;
min-width: 100px;
}
table.table-mini {
width: 100%;
border-collapse: collapse;
font-size: 0.85rem;
}
@harish81
harish81 / alert.js
Created May 28, 2020 02:46
Promise Based Bootstrap Modal As Confirmation Box or Alert.
function bsPopup(title = 'Alert', msg = 'Are you sure?') {
return new Promise((resolve, reject) => {
const autoId = 'modal' + new Date().getTime();
const modal = `
<div class="modal fade" id="${autoId}" tabindex="-1">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-exclamation-triangle mr-1"></i> ${title}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
@harish81
harish81 / binding.js
Last active June 5, 2023 22:32
Simple Two-Way Data Binding Using Javascript Proxies.
function observe(selector,data,listener=null) {
let parent = document.querySelector(selector);
let allBind = parent.querySelectorAll('[data-bind]');
const get = (target, key, receiver)=>{
const result = Reflect.get(target, key, receiver);
return result;
}
const set = (target,key,value,receiver)=>{
Reflect.set(target, key, value, receiver);
updateBinding(key,value);
@harish81
harish81 / DatePickerEditText.java
Created June 10, 2020 09:47
DatePicker EditText in Android
import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.widget.DatePicker;
import androidx.appcompat.widget.AppCompatEditText;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@harish81
harish81 / ClickToSelectEditText.java
Created June 10, 2020 09:50
Click to select edittext, alternative to spinner
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatEditText;
import java.util.List;
@harish81
harish81 / RepeatTaskTimer.java
Created June 12, 2020 08:58
Easy Repeat Task Timer For Android With listener support.
import android.app.Activity;
import java.util.Timer;
import java.util.TimerTask;
public class RepeatTaskTimer extends TimerTask {
private long timeInMillis;
private long delay;
private long finishTime;
private Listener listener;
private Activity activity;
@harish81
harish81 / VolleyMultipartRequest.java
Last active June 13, 2020 07:42
Volley Multipart Request.
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@harish81
harish81 / AndroidManifest.xml
Created June 13, 2020 10:20
Image Picker With Cropping Support
//register below activity
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity android:name=".ImagePickerActivity"></activity>
@harish81
harish81 / rgbtohex.php
Last active June 2, 2021 03:42
PHP function to convert hex color to RGB with alpha support
/**
* Convert the hex color to rgba.
* @param $hex - #fa11cc
* @param mixed $alpha - from 0.0 to 1.0
* @return array rgba
*/
function hexToRgb($hex, $alpha = false)
{
$hex = str_replace('#', '', $hex);
$length = strlen($hex);