Skip to content

Instantly share code, notes, and snippets.

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

Dhruva dhruva81

🏠
Working from home
View GitHub Profile
@dhruva81
dhruva81 / Insert a New Row at Top or Bottom of Tables in MS Word using VBA
Last active February 4, 2019 03:47
Insert a New Row at Top/Bottom of Tables in MS Word using VBA
Sub insertTopRow()
Dim theTable As Table
Dim theNewRow As Row
Dim i As Integer
For i = 1 to ActiveDocument.Tables.Count
Set theTable = ActiveDocument.Tables(i)
Set theNewRow = theTable.Rows.Add(theTable.Rows.First)
'Other row formatting
Next i
@dhruva81
dhruva81 / ShareX code to upload cropped images on server
Last active February 4, 2019 03:46
ShareX code to upload cropped images on server
<?php
$secret_key = "9ge9ag99135213tgedavxgfedsaxeg"; //Set this as your secret key, to prevent others uploading to your server.
$sharexdir = "yoyo/"; //This is your file dir, also the link..
$domain_url = 'http://website.com/';
$lengthofstring = 5; //Length of the file name
function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'));
By default, Excel provides the Conditional Formatting feature for us to complete this problem, please do as follows:
1. Select the data range that you want to highlight every nth row.
2. Click Home > Conditional Formatting > New Rule, see screenshot:
3. In the New Formatting Rule dialog box, click Use a formula to determine which cells to format option from the Select a Rule Type: list box, and then type this formula =MOD(ROW(),8)=0 into the Format value where this formula is true text box,
Tips: with above formula, you can highlight every fourth row in the range, you can change the number 4 to 3, 5, 6…for your need.
4. After entering the formula, then please click Format button to go to the Format Cells dialog, choose one color you like under the Fill tab.
If you want to highlight every nth column, please apply this formula: =MOD(COLUMN(), n)=0.
If you want to highlight every nth row, please apply this formula: =MOD(ROW(), n)=0.
@dhruva81
dhruva81 / blog.md
Created December 22, 2020 16:44 — forked from alesf/blog.md
Laravel - Eloquent: Cascading delete, forceDelete and restore

If you want to delete a model with related models you can use Laravel model events. There is also a special case if your models cascade.

Lets say you have Folder and File Eloquent models that are related and use SoftDeletes trait and when you delete a folder you also want to delete files in folder and all subfolders with files.

In the boot method or Folder model you catch delete and restore events (actually deleting and restoring events that trigger before restoring or deleting happens). You can delete/restore all files in folder you're deleting/restoring with $folder->files()->delete(); and $folder->files()->withTrashed()->restore();.

Folders on the other hand cascade (folder in a folder in a folder) and because events do not trigger if you don't pull the models (->get() method), the model events won't trigger for subfolders. That's why you need to pull the folders and iterate trough them (->each() method) and delete/restore them.

You could use database CASCADE feature but that does

@dhruva81
dhruva81 / image-src-regexpr.php
Created December 26, 2020 08:51 — forked from vyspiansky/image-src-regexpr.php
PHP: get image src attribute (regular expression)
<?php
// Source: http://goo.gl/qyLFbg
$html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />';
preg_match( '@src="([^"]+)"@' , $html, $match );
$src = array_pop($match);
// will return /images/image.jpg
@dhruva81
dhruva81 / instructions.md
Created February 17, 2021 11:41 — forked from ju5t/instructions.md
Livewire enabled TinyMCE blade component

Instructions

This is a very basic TinyMCE component. It uses 'entangle'. This allows you to link a Livewire and Alpine property to eachother. If one value changes, the other does too.

Installation

Add tinymce.blade.php to views/components/input. This can be another component folder too if you prefer, but keep in mind that you should also

var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@dhruva81
dhruva81 / BaseLayout.tsx
Created October 3, 2023 19:20 — forked from mxmtsk/BaseLayout.tsx
React implementation of Vue3 Adapater for https://github.com/lepikhinb/momentum-modal
/**
* Unfortunately I didn't find a way to add it directly to createInertiaApp so
* currently I'm placing it in my BaseLayout which is called on any route anyway
*/
import React from 'react';
import { ModalProvider } from '../components/momentum-modal/ModalContext';
const BaseLayout: React.FC = ({ children }) => {
/* Wrap your children with the provider */
return <ModalProvider resolve={(name) => import(`../pages/${name}`)}>{children}</ModalProvider>;
"use client";
import {
Dialog,
DialogContent,
DialogTitle,
DialogTrigger
} from "@/components/ui/dialog";
import { cn } from "@/lib/utils";
import { Expand, Loader2, RotateCcw, Trash2, UploadCloud } from "lucide-react";
@dhruva81
dhruva81 / CopyToClipboardAction.php
Created November 13, 2023 18:31 — forked from Z3d0X/CopyToClipboardAction.php
Filament CopyToClipboardAction
<?php
namespace App\Filament\Pages\Actions;
use Closure;
use Filament\Pages\Actions\Action as BaseAction;
use Illuminate\Support\HtmlString;
class CopyToClipboardAction extends BaseAction
{