Skip to content

Instantly share code, notes, and snippets.

View devudit's full-sized avatar
🎓
Focusing

Udit Rawat devudit

🎓
Focusing
View GitHub Profile
@devudit
devudit / closest-lower-higher-number.php
Last active January 6, 2024 18:22
Get closest, lower and higher number as a associative array from a array
<?php
function closestLowerHigherNr($array, $nr) {
sort($array);
$re_arr = array('lower'=>min(current($array), $nr), 'higher'=>max(end($array), $nr), 'closest'=>$nr);
foreach($array AS $num){
if($nr > $num) $re_arr['lower'] = $num;
else if($nr <= $num){
$re_arr['higher'] = $num;
break;
}
@devudit
devudit / create-field.php
Last active May 6, 2016 10:38
Creating custom field to user profile
<?php
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
@devudit
devudit / CacheJsController.php
Last active May 6, 2016 10:37
Cache js files in laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class CacheJsController extends Controller
{
@devudit
devudit / Helper.php
Created May 6, 2016 10:35
Dynamic body classes in laravel
<?php
// Create A class Helper as app/Helper/Helper.php
use Illuminate\Support\Facades\Request;
Class Helper {
public static function getBodyClass() {
$body_classes = [ ];
$class = "";
@devudit
devudit / attachment.php
Last active April 2, 2017 09:36
Add custom field to attachments in wordpress
<?php
/**
*
* @wordpress-plugin
* Plugin Name: Attachment custom fields
* Plugin URI: http://uditrawat.com
* Description: Custom fields for Attachments
* Version: 10.3
* Author: Udit Rawat
* Author URI: http://uditrawat.com
@devudit
devudit / class-master-slider-override.php
Last active May 6, 2016 13:24
Add custom tag on post slider of Master Slider
<?php
/**
*
* @wordpress-plugin
* Plugin Name: Custom Tags For Master Slider
* Plugin URI: http://uditrawat.com
* Description: Custom Tags For Master Slider
* Version: 1.3
* Author: Udit Rawat
@devudit
devudit / change_sortorder.php
Created May 9, 2016 05:58
How to change sort order of post page navigation
<?php
// get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'your_custom_post_type',
'your_custom_taxonomy' => 'your_custom_taxonomy_term'
);
$postlist = get_posts( $postlist_args );
@devudit
devudit / center-bootstrap-modal-script.js
Last active May 2, 2018 10:23
Center bootstrap modal, Vertically and Horizontally
(function ($) {
"use strict";
function $fixBootstrapModalPosition() {
$(this).css('display', 'block');
var $dialog = $(this).find(".modal-dialog"),
offset = ($(window).height() - $dialog.height()) / 2,
bottomMargin = parseInt($dialog.css('marginBottom'), 10);
// Make sure you don't hide the top part of the modal w/ a negative margin if it's longer than the screen height, and keep the margin equal to the bottom margin of the modal
if(offset < bottomMargin) offset = bottomMargin;
@devudit
devudit / class-custom-post-filter.php
Created May 24, 2016 13:19
Custom Filter On Post Listing
<?php
/**
*
* @wordpress-plugin
* Plugin Name: Custom Post Filter
* Plugin URI: http://uditrawat.com
* Description: Custom Post Filter For Posts
* Version: 1.3
* Author: Udit Rawat
* Author URI: http://uditrawat.com
@devudit
devudit / responsive-table.html
Created May 27, 2016 06:57
Make html table responsive using css only
<html>
<head>
<style type="text/css">
body {
font-family: arial;
}
table {
border: 1px solid #ccc;