Skip to content

Instantly share code, notes, and snippets.

View NasirNobin's full-sized avatar
🎯
Focusing

NasirNobin NasirNobin

🎯
Focusing
View GitHub Profile
@NasirNobin
NasirNobin / valet-automatic-php-version-swap-on-cli.zsh
Last active March 17, 2022 19:40
This script that will read .valetphprc from the project root and will switch to that PHP version automatically. Moved here: https://github.com/NasirNobin/zsh-valet
# homebrew-instant-php-version-swap.zsh
#
# @author: NasirNobin
# @url https://gist.github.com/NasirNobin/3e5992608df21389dded1ac1661e1c7c
# @url https://github.com/seanyeh/autosrc
VALETPHPRC=".valetphprc"
VALETPHPRC_IGNORE=0
valetphprc_find(){
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const url = new URL(request.url);
@NasirNobin
NasirNobin / firstInRandomOrder.php
Created June 11, 2021 10:26
Optimized way of getting (1) random item from Laravel model when it has large numbers of records
<?php
// default inRandomOrder()->first() takes a shit load of time, when we have large numbers of records in database;
// here's a hack to make it a bit faster
// it makes an additional `count()` query, be aware of that
// add this to `AppServiceProvider@boot`
Builder::macro("firstInRandomOrder", function () {
return $this->skip(rand(0, ($this->count() - 1)))->first();
# https://www.facebook.com/hasin/posts/10158405563459633
ffmpeg -i input.mp4 -c:v libx265 -x265-params crf=20 output.mp4
<?php
/**
* Auto post to facebook from wordpress/website
* Author -> Nasir Uddin Nobin
*/
function fb_update($ID, $post){
/**
* download facebook php sdk https://github.com/facebookarchive/facebook-php-sdk
* upload it to your directory and include it
* if you paste this code to plugin file use (plugin_dir_path(__FILE__)
fs = require('fs')
var option = process.argv[2];
fs.readdirSync('./').forEach(file => {
if (/^\..*/.test(file) && option != '-a') return;
console.log(file);
fs = require('fs')
const needToPrint = ['name','description','version'];
const needToCopy = needToPrint.concat('dependencies');
const newJson = {};
fs.readFile('package.json', 'utf8', (err,data) => {
if (err) {
return console.log(err);
@NasirNobin
NasirNobin / wpinstall.sh
Created October 9, 2017 10:37
Single Command WP Installation
if [ $2 ]; then
DB_NAME=$2
else
DB_NAME='default_db'
fi
NAME=$1
TITLE=$(echo $NAME | tr 'a-z' 'A-Z')
wp core download
@NasirNobin
NasirNobin / pipexbd_link_grabber.js
Created June 16, 2017 08:44
media.pipexbd.com download links grabber