Skip to content

Instantly share code, notes, and snippets.

View airarm's full-sized avatar

Arman Hayrapetyan airarm

View GitHub Profile
@bridgetwes
bridgetwes / gist:b96b3135e750c586adf3e94ed9c0dcc9
Created December 27, 2023 21:21
Vanilla Javascript smooth scroll to element from URL hash - on load or from in page link
/*
*
* Smooth Scroll to Anchors
* */
const offsetTopScroll = 200;
//Smooth scroll on page load if anchor is in URL
if (window.location.hash) {
const hash = window.location.hash;
const target = document.getElementById(hash.replace('#', ''));
@TusharKanjariya
TusharKanjariya / custom-context-menu.js
Created May 8, 2023 11:06
The Essential Guide to Creating Custom Context Menus in JavaScript
var menu = document.querySelector(".context-menu");
var menuState = 0;
var contextMenuActive = "block";
// Method to turn on fullscreen of current window
function fullscreen() {
document.documentElement.requestFullscreen();
}
// Event Listener for window ContextMenu Event - When Right Click is clicked
@AM-77
AM-77 / copyToClipboard.js
Created May 27, 2020 14:15
Copy text to clipboard with vanilla JavaScript.
function copyToClipboard(textToCopy) {
const temp = document.createElement("input")
temp.type = "text"
temp.value = textToCopy
document.body.appendChild(temp)
temp.select()
document.execCommand("Copy")
document.body.removeChild(temp)
}
@lukewlms
lukewlms / ExpoLocaleNumbers.ts
Created June 21, 2019 18:54
Parsing and reading of localized numbers with Expo
import { locale } from "expo-localization";
const thousandsSeparator = (1000).toLocaleString(locale)[1] === "," ? "," : ".";
const decimalSeparator = thousandsSeparator === "." ? "," : ".";
export function parseLocaleNumber(stringNumber: string) {
return Number(
stringNumber
.replace(new RegExp(`\\${thousandsSeparator}`, "g"), "")
.replace(new RegExp(`\\${decimalSeparator}`), "."),
function interceptNetworkRequests(ee) {
const open = XMLHttpRequest.prototype.open;
const send = XMLHttpRequest.prototype.send;
const isRegularXHR = open.toString().indexOf('native code') !== -1;
// don't hijack if already hijacked - this will mess up with frameworks like Angular with zones
// we work if we load first there which we can.
if (isRegularXHR) {
@mujahidi
mujahidi / wp_user_query_pagination.php
Created May 29, 2018 12:49
Pagination with WP_User_Query object
<?php
// number of users we want to show per page
$number = 10;
// to pinpoint the current pagination number
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// count the number of users that should be passed over in the pages (offset) – this will take effect at the second page onwards.
$offset = ($paged - 1) * $number;
@vnsam
vnsam / gist:187be13c408b291f9b9c0a28c72fb7ff
Created October 10, 2017 13:21
Pro version key for Beyond Compare - v4.2.3.22587
This can be used in Mac by using following trick:
Open trial.key at path: /Applications/Beyond\ Compare.app/Contents/Resources/trial.key
Replace content of trial.key with:
--- BEGIN LICENSE KEY ---
H1bJTd2SauPv5Garuaq0Ig43uqq5NJOEw94wxdZTpU-pFB9GmyPk677gJ
vC1Ro6sbAvKR4pVwtxdCfuoZDb6hJ5bVQKqlfihJfSYZt-xVrVU27+0Ja
hFbqTmYskatMTgPyjvv99CF2Te8ec+Ys2SPxyZAF0YwOCNOWmsyqN5y9t
q2Kw2pjoiDs5gIH-uw5U49JzOB6otS7kThBJE-H9A76u4uUvR8DKb+VcB
rWu5qSJGEnbsXNfJdq5L2D8QgRdV-sXHp2A-7j1X2n4WIISvU1V9koIyS
@stewartknapman
stewartknapman / shopify-money.js
Created February 27, 2017 23:25
The Shopify.formatMoney method extracted from option_selection.js for stand-alone purposes.
var Shopify = Shopify || {};
// ---------------------------------------------------------------------------
// Money format handler
// ---------------------------------------------------------------------------
Shopify.money_format = "${{amount}}";
Shopify.formatMoney = function(cents, format) {
if (typeof cents == 'string') { cents = cents.replace('.',''); }
var value = '';
var placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
var formatString = (format || this.money_format);
@dnordby
dnordby / shopify-loadmore.md
Last active December 29, 2021 18:03
Shopify <li> loadmore (products)

Use Shopify pagination to trigger loadmore event

Markup

{% paginate collection.products by 16 %}
<div class="products__collection">
  <ul class="product collection__grid"">
    {% for product in collection.products %}
      {% assign prod_id = forloop.index | plus:paginate.current_offset %}
      {% include 'product-grid-item' with prod_id %}
@Rodrigo54
Rodrigo54 / php-html-css-js-minifier.php
Last active July 12, 2024 10:42 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
/**
* -----------------------------------------------------------------------------------------
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
* -----------------------------------------------------------------------------------------
*/
// HTML Minifier
function minify_html($input) {