Skip to content

Instantly share code, notes, and snippets.

View FayazK's full-sized avatar
🎯
Focusing

Fayaz Khan FayazK

🎯
Focusing
View GitHub Profile
@FayazK
FayazK / NumberAlphaInput.jsx
Created March 7, 2023 04:49
React component that uses the Ant Design Input and only allows numbers, alphabets, and underscores
import React from "react";
import { Input } from "antd";
const NumberAlphaInput = (props) => {
const handleInputChange = (event) => {
const regex = /^[a-zA-Z0-9_]*$/;
if (event.target.value === "" || regex.test(event.target.value)) {
props.onChange(event.target.value);
}
};
jQuery.fn.isInViewport = function () {
let elementTop = jQuery(this).offset().top;
let elementBottom = elementTop + jQuery(this).outerHeight();
let viewportTop = jQuery(window).scrollTop();
let viewportBottom = viewportTop + jQuery(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
@FayazK
FayazK / Frameworks.md
Last active November 13, 2018 05:45
CSS Frameworks, Libraries etc
<?php
foreach(str_split(base64_decode('YOUR_ENCODED_PASS_HERE')) as $chr)
echo chr(((($chr = ord($chr)) << 1) & 0xFF) | ($chr >> (8 - 1)));
@FayazK
FayazK / export-html-table-with-formatting.js
Created July 24, 2017 15:24
Export HTML Table to Excel with Formatting
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,',
template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) {
return window.btoa(unescape(encodeURIComponent(s)))
}
, format = function (s, c) {
return s.replace(/{(\w+)}/g, function (m, p) {
return c[p];
})
@FayazK
FayazK / Reusable JavaScript Functions.markdown
Last active July 24, 2017 15:25
Reusable JavaScript Functions

Reusable JavaScript Functions

@FayazK
FayazK / find-replace-dom.js
Created February 20, 2017 17:37
FInd & Replace in DOM using JavaScript
function findAndReplace(searchText, replacement, searchNode) {
if (!searchText || typeof replacement === 'undefined') {
// Throw error here if you want...
return;
}
var regex = typeof searchText === 'string' ?
new RegExp(searchText, 'g') : searchText,
childNodes = (searchNode || document.body).childNodes,
cnLength = childNodes.length,
excludes = 'html,head,style,title,link,meta,script,object,iframe';
/**
* author Remy Sharp
* url http://remysharp.com/tag/marquee
*/
(function ($) {
$.fn.marquee = function (klass) {
var newMarquee = [],
last = this.length;