Skip to content

Instantly share code, notes, and snippets.

View huzaifaarain's full-sized avatar
🌎
[email protected]://~ workspace

Muhammad Huzaifa huzaifaarain

🌎
[email protected]://~ workspace
View GitHub Profile
@huzaifaarain
huzaifaarain / Readme.md
Last active January 8, 2021 06:26
Delete orphaned, unused files from git

A simple way to detect unused files in a project using git

After finding that we had a few images checked into our project’s repository but that were not referenced in the project, I wanted to write a script to quickly see if there were any other unused assets.

This was a one-off script, so it probably won’t suit everyone’s needs, but here’s how we approached the problem:

First, we needed to get a list of the files that git was tracking in our image directory. While you could use ls for that, I wanted to be sure that we weren’t going to list any files that git was ignoring, so we started with git ls-files, whose output will look something like this if called as git ls-files ./img:

img/foo.png img/bar.png

@huzaifaarain
huzaifaarain / fork-example.php
Created April 21, 2021 21:03 — forked from nicksantamaria/fork-example.php
Example: Parallel processing in PHP using pcntl_fork()
<?php
/**
* @file
* Basic demonstration of how to do parallel threads in PHP.
*/
// This array of "tasks" could be anything. For demonstration purposes
// these are just strings, but they could be a callback, class or
// include file (hell, even code-as-a-string to pass to eval()).
@huzaifaarain
huzaifaarain / Chapter7_CommandLineOperations.md
Last active April 26, 2021 21:34
Introduced commands in Linux Foundation LFS101x Course

Chapter 7: Command Line Operations

Viewing Files

cat Used for viewing files that are not very long; it does not provide any scroll-back.

tac Used to look at a file backwards, starting with the last line.

less Used to view larger files because it is a paging program. It pauses at each screen full of text, provides scroll-back capabilities, and lets you search and navigate within the file. Note: Use / to search for a pattern in the forward direction and ? for a pattern in the backward direction. An older program named more is still used, but has fewer capabilities: "less is more".

@huzaifaarain
huzaifaarain / query.sql
Created May 10, 2021 20:40
Update WP Links In Database After Migration
SET @oldUrl = "Existing URL" COLLATE utf8mb4_unicode_520_ci;
SET @newUrl = "New URL" COLLATE utf8mb4_unicode_520_ci;
UPDATE wp_options SET option_value = replace(option_value, @oldUrl, @newUrl) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldUrl, @newUrl);
UPDATE wp_postmeta SET meta_value = replace(meta_value,@oldUrl, @newUrl);
UPDATE wp_usermeta SET meta_value = replace(meta_value, @oldUrl, @newUrl);
@huzaifaarain
huzaifaarain / 2019-https-localhost.md
Created May 12, 2021 19:26 — forked from cecilemuller/2019-https-localhost.md
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@huzaifaarain
huzaifaarain / .htaccess
Created May 19, 2021 11:16
Remove public from URL Laravel 7.x including sub directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
@huzaifaarain
huzaifaarain / Readme.md
Created June 22, 2021 19:24
Laravel Directory Permission

Webserver as owner (the way most people do it, and the Laravel doc's way):

assuming www-data (it could be something else) is your webserver user.

sudo chown -R www-data:www-data /path/to/your/laravel/root/directory

if you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:

@huzaifaarain
huzaifaarain / Response.php
Created November 30, 2021 08:28 — forked from jeffochoa/Response.php
Laravel HTTP status code
<?php
// This can be found in the Symfony\Component\HttpFoundation\Response class
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;