Skip to content

Instantly share code, notes, and snippets.

View mohsin's full-sized avatar

Saifur Rahman Mohsin mohsin

View GitHub Profile
@mohsin
mohsin / default.htm
Last active August 30, 2020 14:43
Code to make Mohsin.Social plugin with OFFLINE.Mall plugin of OctoberCMS
// Add code on the Code section of the layout file.
function onInit() {
Event::listen('rainlab.user.login', function($user) {
// If the user doesn't have a Customer model it was created via the backend.
// Make sure to add the Customer model now
if ( ! $user->customer && ! $user->is_guest) {
$customer = new \OFFLINE\Mall\Models\Customer();
$customer->firstname = $user->name;
$customer->lastname = $user->surname;
$customer->user_id = $user->id;
@mohsin
mohsin / LocalValetDriver.php
Created August 25, 2020 07:06
Valet driver equivalent of the extensionless-php nginx directive
<?php
/**
* Valet Driver equivalent of http://www.tweaktalk.net/60/nginx-remove-php-file-extension-from-url
*/
class LocalValetDriver extends LaravelValetDriver
{
/**
* Ensure only files which have a .php file on disk get served by this driver.
*/
@mohsin
mohsin / index.js
Created August 2, 2020 16:27
EZTV filter down top shows by rating
// Visit https://eztv.io/showlist/rating/ and sort by rating. Then execute code to remove the ones which have votes lesser than N
// Here N is 100000
$('html body div#header_holder table.forum_header_border tbody tr td.forum_thread_post span').filter((id, node) => {
return parseInt(String(node.firstChild.nodeValue).replace(',','').replace(/\((\d+) votes\)/, '$1'), 10) < 100000;
}).each((id, node) => {
node.parentNode.parentNode.style.display = 'none';
});
@mohsin
mohsin / wix-lazy-image.js
Created June 12, 2020 19:00
Wix Lazy Image Loading Custom Element
// Add this script as Public/custom-elements/wix-lazy-image.js (yes, create a folder called custom-elements)
// In your Wix page, add the Custom Element, choose Corvid file and select the file which you saved in above step.
// Now set Tag Name as lazy-image and save. Now, press Set Attributes and add a field called src with the correct URL of image.
const addLazyScript = () => {
const script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.2/lazysizes.min.js';
script.async = true;
return script;
}
@mohsin
mohsin / waterfall.js
Created May 14, 2020 19:27
jQueryless Waterfall with custom Deferred
/* Usage
* waterfall(this, [Promise1, Promise2, ...])
* .fail(function(reason){
* console.log('failed')
* })
*/
export function waterfall(...params) {
var steps = [],
dfrd = new Deferred(),
@mohsin
mohsin / index.js
Created May 3, 2020 19:40
Code to calculate country-wise death percent for COVID-19 cases at https://www.worldometers.info/coronavirus/
// Run thro' browser JS console
$('#main_table_countries_today > tbody:nth-child(2) > tr').each(function(item) {
var total = parseInt($(this).children('td:nth-child(2)').text().replace(/,/g, ''), 10);
var active = parseInt($(this).children('td:nth-child(7)').text().replace(/,/g, ''), 10);
var deadCases = parseInt($(this).children('td:nth-child(4)').text().replace(/,/g, ''), 10);
var recOrDead = total - active;
$(this).append('<td>' + ((deadCases / recOrDead) * 100).toFixed(3) + '</td>');
});
@mohsin
mohsin / gist:6b68b2d826c2dac4e803aceee9bd44c7
Created November 1, 2019 13:06
PHP-CS Sublime Text 3 Configuration
// SublimeLinter Settings - User
// Make sure to drop phpcs.xml at HOME directory.
{
"linters": {
"phpcs": {
"args": "--standard='~/phpcs.xml'",
"styles": [
{
"icon": "circle"
}
@mohsin
mohsin / list.txt
Created September 3, 2019 08:23
List of git files in a new Android Studio generated project
new file: .gitignore
new file: app/.gitignore
new file: app/build.gradle
new file: app/proguard-rules.pro
new file: app/src/main/AndroidManifest.xml
new file: app/src/main/java/com/acme/MainActivity.kt
new file: app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file: app/src/main/res/drawable/ic_launcher_background.xml
new file: app/src/main/res/layout/activity_main.xml
new file: app/src/main/res/layout/content_main.xml
@mohsin
mohsin / mail-in-a-box.md
Created August 23, 2019 09:28
Installation Log Mail-In-A-Box on GCP instance

Setup DNS A record mail.mywebsite.com to external IP of instance

First let's install SSL certificates coz Mail-In-A-Box certificates are not linked to an email

sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx

If dkpg lock issue appears:

lsof /var/lib/dpkg/lock
ps cax | grep PID
@mohsin
mohsin / DropboxController.php
Created August 7, 2019 19:57
Laravel function to download files from Dropbox
public function download(Request $request, $clintId, $dtId, $inId)
{
$path = $request->input('dropbox_file_path');
$downloadFileName = basename($path);
$cheaders = [
'Authorization: Bearer ' . env('DROPBOX_BEARER_TOKEN'),
'Content-Type: text/plain',
'Dropbox-API-Arg: {"path":"$path"}'
];