Skip to content

Instantly share code, notes, and snippets.

View frikishaan's full-sized avatar
💻
Coding...

Ishaan frikishaan

💻
Coding...
View GitHub Profile
@frikishaan
frikishaan / DateTimeWithTz.php
Last active May 10, 2024 11:28
Laravel Custom Cast to convert datetime fields to user's timezone
<?php
/*
* This custom cast will help convert a datetime field in database to local timezone of the user
* This also convert any input datetime string from user's timezone to the app's default timezone
*/
namespace App\Casts;
use Carbon\Carbon;
@frikishaan
frikishaan / animation.css
Last active January 31, 2024 06:07
CSS Text background animation
/*
* Create an element with class 'hero-text'
*
*/
.hero-text {
background: radial-gradient(circle, #0284c7, #ca8a04);
background-clip: text;
color: transparent;
background-size: 200% 200%;
@frikishaan
frikishaan / functions.php
Created October 11, 2023 12:00
Custom Date Format for meta value - Generate Press
<?php
add_filter( 'render_block', function( $block_content, $block ) {
$field_name = 'start_date'; // ACF field name
$postId = false;
$format = 'M j, Y g:i A'; // date format
$class = 'format-date'; // Additional CSS Class on block to find
$string = 'start_date'; // string of text to replace with date
$date = get_field( $field_name );
@frikishaan
frikishaan / functions.php
Created October 11, 2023 11:57
Filter posts by meta value - Generate Press
<?php
/*
* In this example, we are filtering the custom post type named 'Events'
*/
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
// apply filter if loop has class: upcoming-events-grid
if (! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'upcoming-events-grid' ) !== false) {
@frikishaan
frikishaan / functions.php
Created October 11, 2023 11:54
Sort Posts by meta value - Generate Press
<?php
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
// apply filter if loop has class: courses-grid
if (! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'courses-grid' ) !== false) {
$query_args = array_merge( $query_args, array(
'meta_key' => 'sort_order',
'orderby' => 'meta_value',
@frikishaan
frikishaan / web.php
Last active January 15, 2022 13:46
Force HTTPS in Laravel
<?php
...
/*
* Put this code in routes/web.php file
*/
use Illuminate\Support\Facades\URL;
if(env('APP_ENV') == "production"){
URL::forceScheme('https');
@frikishaan
frikishaan / GenerateHexColor.php
Created January 2, 2022 13:08
Generate random color hex code in PHP
<?php
function generateHexColor() : string
{
return substr(str_shuffle('ABCDEF0123456789'), 0, 6);
}
@frikishaan
frikishaan / web.php
Last active December 3, 2022 09:08
How to Generate Routes with Name and Route Prefix?
<?php
...
Route::prefix('/users')->middleware(['auth'])->name('users.')->group(function (){
Route::get('', function(){
return "Users";
})->name('index'); // Will generate Route ('/users') with name ('users.index')
Route::get('/edit', function(){
@frikishaan
frikishaan / .bashrc
Created September 13, 2020 07:51
Creating Aliases in Windows
# Create a .bashrc file in the directory "C:\Users\<User>
alias pa='php artisan'
alias nr='npm run'
alias ga='git add .'
alias p='python'
@frikishaan
frikishaan / truncateText.css
Created August 5, 2020 19:01
How to truncate multiple line of text?
.card-title{
-webkit-line-clamp: 2; // Max number of lines you want to show
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
}