Skip to content

Instantly share code, notes, and snippets.

View farvisun's full-sized avatar
👀
watching

Mohammad Askari farvisun

👀
watching
View GitHub Profile
@farvisun
farvisun / node-express-cors-middleware.js
Created March 8, 2020 11:49 — forked from cuppster/node-express-cors-middleware.js
express.js middleware to support CORS pre-flight requests
app.use(express.methodOverride());
// ## CORS middleware
//
// see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
@farvisun
farvisun / compile.sh
Last active March 1, 2020 18:17
Compile nginx with brotli,Pagespeed and vts module
# Install dependencies
#
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
apt-get install build-essential \
zlib1g zlib1g-dbg zlib1g-dev \
libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev \
unzip uuid-dev checkinstall
@farvisun
farvisun / index.php
Created October 30, 2019 17:37
Download Instagram Stories without mark them as seen :)))
<?php
/**
you should this before run this code
composer require mgp25/instagram-php
*/
require_once __DIR__ . '/vendor/autoload.php';
@farvisun
farvisun / index.php
Created May 13, 2019 05:00
Tag regex with persian characters
<?php
$text = '#سلام_دنیا';
if(preg_match('/\#([א-תآ-یÀ-ÿ一-龥а-яا-یa-z0-9\-_]{1,50})/iu',$text)){
echo $text ." is tag\n";
}else{
echo $text ." is not tag\n";
}
@farvisun
farvisun / nginx.conf
Created March 21, 2019 14:44 — forked from jrom/nginx.conf
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
@farvisun
farvisun / API.md
Created February 5, 2019 07:01 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@farvisun
farvisun / jquery-scroll-bottom.js
Created January 17, 2019 19:38 — forked from toshimaru/jquery-scroll-bottom.js
Detect the scrolling to bottom of the page using jQuery.
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
@farvisun
farvisun / convertor.php
Created July 29, 2018 17:00
convert music video to mp3 inside directory with ffmpeg
<?php
$files = scandir(__DIR__);
foreach($files as $file){
$name = explode(".",$file);
unset($name[count($name)-1]);
$name = implode("-",$name);
$name = str_replace(" ","-",$name);
$name = strtolower($name);
$name = preg_replace("/[\-]{1,}/i","-",$name);
echo "Start Convert for " . $name . "\n";
@farvisun
farvisun / slugify.php
Created February 22, 2018 06:08
create slug from persion unicode characters
<?php
function slugify($str, $options = array()) {
// https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Utils/Slug.php
// Make sure string is in UTF-8 and strip invalid UTF-8 characters
$str = mb_convert_encoding((string)$str, 'UTF-8', mb_list_encodings());
$defaults = array(
'delimiter' => '-',
'limit' => null,
'lowercase' => true,
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://farvisun.ir/$1 [R,L]