Skip to content

Instantly share code, notes, and snippets.

View sourovroy's full-sized avatar

Sourov Roy sourovroy

View GitHub Profile
@sourovroy
sourovroy / back-top-top.js
Last active March 29, 2018 05:41
Simple back to top
/* JavaScript */
jQuery(document).ready(function($){
// browser window scroll (in pixels) after which the "back to top" link is shown
var offset = 300,
//browser window scroll (in pixels) after which the "back to top" link opacity is reduced
offset_opacity = 1200,
//duration of the top scrolling animation (in ms)
scroll_top_duration = 700,
//grab the "back to top" link
$back_to_top = $('.cd-top');
@sourovroy
sourovroy / wp-admin-pagination.php
Last active September 26, 2017 13:32
Custom pagination for WordPress admin panel
<?php
function affilate_list_pagination($total_items, $total_pages, $current){
$output = '<span class="displaying-num">'.sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)).'</span>';
$removable_query_args = wp_removable_query_args();
$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
@sourovroy
sourovroy / setHTTPRequest.php
Last active November 5, 2017 18:33
This is a source file of a article about PHP cURL. http://sourov.im/send-http-request-using-php-curl/
<?php
/*
|---------------------------------------------------
| PHP class to send HTTP request in better way
|---------------------------------------------------
*/
if(!class_exists('setHTTPRequest')){
class setHTTPRequest
{
/**
@sourovroy
sourovroy / slug.php
Last active November 18, 2017 11:50
Generate a unique slug from post title
<?php
/**
* Create unique slug for post
*/
public static function generateSlug($title)
{
$slug = substr(str_slug($title), 0, 175); // Slug length will be 175 charecter
$latestSlug = static::whereRaw("slug = '$slug' or slug LIKE '$slug-%'")->value('slug');
if(!empty($latestSlug)){
@sourovroy
sourovroy / MediaController.php
Created November 20, 2017 12:43
Laravel upload file with unique file name
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class MediaController extends Controller
{
/**

Laravel install process in ubuntu

Copy Laravel Files

composer create-project --prefer-dist laravel/laravel blog

Folder Permision

@sourovroy
sourovroy / .bascrc.md
Last active February 23, 2024 08:08
Show git branch name in ubuntu terminal

Show git branch name in ubuntu terminal

Add these lines in your ~/.bashrc file

# Show git branch name
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
 git branch 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
@sourovroy
sourovroy / show-error.php
Last active January 24, 2018 10:00
Display PHP error. Enable debuging
<?php
// Show all php errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// END
@sourovroy
sourovroy / functions.php
Created February 14, 2018 07:02
WordPress allow any page to add extra url with it
<?php
/**
* Custom rewrite rule for career page
*/
add_action('init', function(){
add_rewrite_tag('%office_location%','([^&]+)');
add_rewrite_tag('%job_position%','([^&]+)');
});
@sourovroy
sourovroy / Dockerfile
Created June 27, 2019 11:11
Alpine Dockerfile for PHP, Node and Git
FROM alpine:3.10
# Install cURL, Zip, Vim
RUN apk update && apk add curl zip vim
# Install PHP
RUN apk add php7 php7-common php7-curl php7-json php7-zip php7-mbstring php7-openssl php7-phar php7-xml
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \