Skip to content

Instantly share code, notes, and snippets.

View mdzzohrabi's full-sized avatar

Masoud Zohrabi mdzzohrabi

View GitHub Profile
@mdzzohrabi
mdzzohrabi / port-forward.js
Created January 17, 2023 13:00
Port Forwarding
// @ts-check
/**
* Forward local port to an external port through a local network proxy
*
* @author Masoud Zohrabi <mdzzohrabi@gmail.com>
*/
let net = require('net');
let invariant = (expr, error) => { if (!expr) throw Error(error); };
@mdzzohrabi
mdzzohrabi / generate-date-for-sql.js
Created December 31, 2022 12:00
Generate Jalali Dates for SQL
let startDate = new Date('2010-01-01');
let endDate = new Date('2060-12-29');
let date = new Date(startDate);
let result = '';
while (date < endDate) {
let monthName = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { month: 'long' }).format(date);
let month = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { month: 'numeric' }).format(date);
let weekDayName = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { weekday: 'long' }).format(date);
let weekDay = ['شنبه','یکشنبه','دوشنبه','سه‌شنبه','چهارشنبه','پنجشنبه','جمعه'].indexOf(weekDayName) + 1;
@mdzzohrabi
mdzzohrabi / port-forward.js
Created March 24, 2022 03:01
Forward local port to an external port through a local network proxy
/**
* Forward local port to an external port through a local network proxy
*
* @author Masoud Zohrabi <mdzzohrabi@gmail.com>
*/
let net = require('net');
let invariant = (expr, error) => { if (!expr) throw Error(error); };
let log = console.log.bind(console);
@mdzzohrabi
mdzzohrabi / src\policies\restrict-user.js
Last active March 5, 2022 13:33
Strapi Restrict User to Retrieve data only related to him (Strapi V4.0)
/**
* Strapi Restrict User to Retrieve data only related to him (Strapi V4.0)
*
* @author Masoud Zohrabi <mdzzohrabi@gmail.com>
*/
module.exports = (ctx, config, {strapi}) => {
// Assert user logged-in
if (!ctx.state.user) return false;
@mdzzohrabi
mdzzohrabi / EndlessAdapter.kt
Created September 28, 2017 09:40
Simple End-less RecyclerView Adapter (Kotlin)
package mdzzohrabi.adapter
import android.support.v7.widget.RecyclerView
import java.util.ArrayList
/**
* Endless Recycler view adapter
* @author Masoud Zohrabi <mdzzohrabi@gmail.com>
*/
abstract class EndlessAdapter<VH: RecyclerView.ViewHolder, T>: RecyclerView.Adapter<VH>() {
@mdzzohrabi
mdzzohrabi / open-port.js
Created October 26, 2016 00:38
Node.JS Simple Port Opening ( For NAT Testing )
const net = require( 'net' );
const process = require( 'process' );
const [ nodePath , scriptPath , port ] = process.argv;
if ( port === undefined ) {
console.error( 'Port not defined' );
return;
}
@mdzzohrabi
mdzzohrabi / EntityTreeType.php
Last active February 14, 2024 17:02
Symfony Entity Tree ( Hierarchy ) Form Type
<?php
/**
* (c) Masoud Zohrabi <mdzzohrabi@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mdzzohrabi\Form;
package com.example.android.basicnotifications;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
@mdzzohrabi
mdzzohrabi / PHP-Simple-MVC.php
Created December 11, 2015 13:39
PHP Simple MVC
<?php
/**
* Controller
*/
abstract class Controller {
/**
* Render view
* @param string $view View file
* @param array $params View parameters
* @return string Rendered view
@mdzzohrabi
mdzzohrabi / jQuery.Extend.coffee
Created August 22, 2015 13:56
jQuery additional features
# Orginal methods and variable
Base = {
jQuery:
append: jQuery.fn.append
val: jQuery.fn.val
remove: jQuery.fn.remove
}
window.Base = Base