Skip to content

Instantly share code, notes, and snippets.

View mohitmamoria's full-sized avatar
🚀

Mohit Mamoria mohitmamoria

🚀
View GitHub Profile
@mohitmamoria
mohitmamoria / CreateNewBookModal.vue
Last active June 27, 2023 12:34
Vue3 Composable Overlays/Modals/Slide-overs
<script setup>
import Button from '@/Components/Button.vue';
import Card from '@/Components/Card.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import Modal from '@/Components/Modal.vue';
import TextInput from '@/Components/TextInput.vue';
import { useAPIForm } from '@/Composables/useAPIForm';
const form = useAPIForm({
@mohitmamoria
mohitmamoria / README.md
Last active November 3, 2024 12:50
Inertia.js Form Helper for Axios/API calls

Inertia.js ships with a fantastic form helper but it falls short when also using API/Axios calls in your project.

Here's a composable, built on top of the Inertia's form helper that hooks into it to replace the API calls with Axios.

To use, just replace useForm with useAPIForm.

const form = useAPIForm({
    title: '',
});
@mohitmamoria
mohitmamoria / app.js
Created January 25, 2023 15:54
Laravel + Vue
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
import { createApp, defineAsyncComponent } from "vue";
import "./bootstrap";
/**
@mohitmamoria
mohitmamoria / GoogleSignInActivity.java
Created May 19, 2016 07:45
The sample (read: crude) implementation of the New Google Sign In API
package com.horntell.pendulum;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.google.android.gms.auth.api.Auth;
@mohitmamoria
mohitmamoria / AuthServiceProvider.php
Last active August 29, 2015 14:02
Extending Auth in a Service Provider
<?php
// I am trying to extend Auth using a custom driver for MongoDB in the package's service provider's register method:
$this->app['auth']->extend('mongo', function($app)
{
return new Auth\MongoUserProvider($app['db']->connection('mongo'), $app['config']['auth.table']);
});
// But getting error that "Class auth does not exist in Container at line 485.". I tried doing this:
@mohitmamoria
mohitmamoria / filters.php
Created March 29, 2014 20:36
Laravel OPTIONS filter
App::before(function($request)
{
if($request->server('REQUEST_METHOD') == 'OPTIONS')
{
$response = Response::make(null, 200);
$response->headers->set('Access-Control-Allow-Origin', Config::get('app.url'));
$response->headers->set('Access-Control-Allow-Methods', 'PUT, POST, GET, PATCH, OPTIONS');
$response->headers->set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
return $response;
@mohitmamoria
mohitmamoria / human_filesize.php
Created March 28, 2014 20:30
Convert filesize from bytes to human readable format in PHP
/**
* Converts filesize from bytes to human readable format.
*
* @param number $bytes
* @param number $decimals
* @return string
*/
function human_filesize($bytes, $decimals = 2)
{
$size = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
@mohitmamoria
mohitmamoria / index.html
Created October 9, 2013 09:40
AngularJS Newline
<!-- use it like this. Please notice that nohtml filter was used before newlines. -->
<p ng-bind-html-unsafe="post.content | nohtml | newlines"></p>
@mohitmamoria
mohitmamoria / YouThereBro.js
Created October 7, 2013 05:15
You There, Bro?
// first, some awesomeness
Array.prototype.YouThereBro = [].indexOf
// now, some awesomeness++
var arr = [20, 8, 19, 93]
arr.YouThereBro(8) // you there bro?
// >> 1 (yep)
arr.YouThereBro(93) // you there bro?
@mohitmamoria
mohitmamoria / DatePicker.js
Created September 19, 2013 10:10
AngularJS directive for jQueryUI Datepicker
'use strict';
angular.module('myApp')
.directive('DatePicker', function () {
return {
restrict: 'C',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
element.datepicker({
dateFormat: 'yy-mm-dd',