Skip to content

Instantly share code, notes, and snippets.

View faridv's full-sized avatar
😐
‌Dealing with challenges like this -> :|

Farid Rn faridv

😐
‌Dealing with challenges like this -> :|
View GitHub Profile
@faridv
faridv / getmax.ts
Created January 27, 2020 16:40
To find the maximum y value of the objects in array:
// https://stackoverflow.com/a/4020842/893111
Math.max.apply(Math, array.map(o => o.y))
(function takeOverConsole() {
var console = window.console;
function intercept(method) {
var original = console[method];
console[method] = function () {
var message = Array.prototype.slice.apply(arguments).join(' ');
original.call(console, arguments);
var xhr = new XMLHttpRequest();
// xhr.open('get', '/log.php?error=' + message);
@faridv
faridv / ticker.plugin.js
Created November 11, 2018 15:21
Titles ticker plugin for jQuery
// Ticker Plugin
$.fn.fTicker = function (options) {
var $ticker = $(this);
var settings = $.extend({
// defaults.
timeout: 5000
}, options);
$.each($ticker, function () {
var $el = $(this).find("ul:first");
if ($el.find("li").length < 2)
@faridv
faridv / active-tab.js
Last active June 4, 2024 08:09
Event listener to check if window/tab is active or inactive
$(window).on("blur focus", function (e) {
var prevType = $(this).data("prevType");
if (prevType != e.type) { // reduce double fire issues
switch (e.type) {
case "blur":
// do work
console.log('blurred');
break;
case "focus":
// do work
@faridv
faridv / gist:c595a687eb8fa065885d1f05d621f434
Created June 17, 2018 07:48 — forked from psdtohtml5/gist:5908031
jQuery: Drag and scroll horizontal div
<script type="text/javascript">
$(document).ready(function() {
$('.dragger').mousedown(function (event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('scrollLeft', this.scrollLeft)
.addClass("dragging");
return false;
@faridv
faridv / StorageHelper.ts
Created December 16, 2017 13:20 — forked from Digiman/StorageHelper.ts
Simple helper module on TypeScript for using local storage (HTML5) in browser. Also have the class to store the list of emails that need to use for autocomplete in the some pages.
// module with classes and logic for working with local storage in browsers via JavaScript
// see also: http://professorweb.ru/my/html/html5/level5/5_1.php
module StorageHelper {
export interface IStorageItem {
key: string;
value: any;
}
export class StorageItem {
key: string;
@faridv
faridv / strip_tags.js
Created August 8, 2017 06:51
Removing unwanted html tags while keeping their contents -- similar to PHP's strip_tags()
// Grabbed from here: https://stackoverflow.com/a/5601929/893111
var whitelist = 'p, img, strong';
$("*").not(self.whitelist).each(function(){
var content = $(this).contents();
$(this).replaceWith(content);
});
@faridv
faridv / Convert Persian & English digits together
Created August 7, 2017 13:09 — forked from MeTe-30/Convert Persian & English digits together
Convert Persian & English digits together | Javascript
String.prototype.toPersianDigits = function () {
var id = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
return this.replace(/[0-9]/g, function (w) {
return id[+w];
});
};
String.prototype.toEnglishDigits = function () {
var id = { '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4', '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9' };
@faridv
faridv / persianToLatinDigits.js
Created July 27, 2017 08:42
Convert Persian digits to Latin digits
function persianToLatinDigits (s) {
var a = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"];
var p = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
for (var i = 0; i < 10; i++) {
s = s.replace(new RegExp(a[i], 'g'), i).replace(new RegExp(p[i], 'g'), i);
}
return s;
}
@faridv
faridv / $_get.js
Created July 27, 2017 08:39
Get URL query parameters and store the in a global object
window.$_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});