Skip to content

Instantly share code, notes, and snippets.

View Exlord's full-sized avatar

FarhadAdeli Exlord

View GitHub Profile
@Exlord
Exlord / MediStreamTech.js
Last active July 21, 2023 10:51
Tech to handle MediaStream playback in Videojs
import videojs from 'video.js';
const Html5 = videojs.getTech('Html5');
const supportsSrcObject = 'srcObject' in HTMLMediaElement.prototype;
export default class MediaStreamTech extends Html5 {
/**
* A getter/setter for the `Html5` Tech's source object.
* > Note: Please use {@link Html5#setSource}
*
@Exlord
Exlord / index.php
Last active April 16, 2018 07:43
Php IntlDateFormatter fa_IR bug test
function formatMyDate($locale, $pattern, $year, $month, $day) {
$timezone = new \DateTimeZone('Asia/Tehran');
$dateTime = new \DateTime('now', $timezone);
$dateTime->setDate($year, $month, $day);
$timeStamp = $dateTime->getTimestamp();
$dateFormatter = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
$timezone,
if(!Array.prototype.isArray){
Array.prototype.isArray = function (variable) {
return variable.constructor === Array;
}
}
function flatten(arr, result) {
result = result || [];
for (let i = 0, length = arr.length; i < length; i++) {
var value = arr[i];
/* EventManager, v1.0.1
*
* Copyright (c) 2009, Howard Rauscher
* Licensed under the MIT License
*/
(function() {
function EventManager() {
this._listeners = {};
@Exlord
Exlord / web-request.cs
Created June 25, 2015 04:31
C# WebClient or WebRequest retrives unreadable data where browser recives correct html
//if you are trying to read a webpage using webclient or webrequest and getting very diffrent data than the browser
//the chances are that the content is compressed
//but if you are reciving correct html but diffrent than the browser then you should set a correct UserAgent
System.Net.HttpWebRequest r = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://kat.cr/");
r.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
r.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)r.GetResponse();
System.IO.Stream respS = resp.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(respS, System.Text.Encoding.GetEncoding(1252));
@Exlord
Exlord / dynamic_stylesheet.js
Last active August 29, 2015 14:23
Dynamicly loading stylesheets with js and handling stylesheets onload event
//Its very tricky to load LINK tags dynamicly and listen to their onload event, i found lots of hacks and tricks.
//This is the best and cleanest option that i came up with
//Basicly you just load the link file with ajax and put it inside a STYLE tag.
//This is a pure JS solution, no jQuery
function createXMLHTTPObject() {
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
@Exlord
Exlord / delayed_link.js
Last active August 29, 2015 14:22
Delay in directive's link fn until a http request is over in Angular 1.3
@Exlord
Exlord / ViewContentLoaded.js
Last active August 29, 2015 14:22
Attach a global event handler for $ViewContentLoaded in Angular 1.3
(function (angular) {
var origMethod = angular.module;
angular.module = function (name, reqs, configFn) {
var module = origMethod(name, reqs, configFn);
module.run(function ($rootScope) {
$rootScope.$on('$viewContentLoaded', function () {
var appEl = angular.element(' [ng-view],ng-view,.ng-view', '[ng-app="' + name + '"]');
@Exlord
Exlord / RoutePrefix.js
Last active March 29, 2022 20:32
Add a global Prefix to all routes in Angular 1.3 router
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (needle) {
for (var i = 0; i < this.length; i++) {
if (this[i] === needle) {
return i;
}
}
return -1;
};
}
@Exlord
Exlord / BrowserProvider.js
Last active August 29, 2015 14:22
Fixing Duplicate $browser provider with multiple app bootstrap in Angular 1.3
var __browser = null;
(function (angular) {
var origMethod = angular.module;
angular.module = function (name, reqs, configFn) {
var module = origMethod(name, reqs, configFn);
///////////////////// override the browser service
module.config(['$provide', '$compileProvider', '$routeProvider', function ($provide, $compileProvider, $routeProvider) {