Skip to content

Instantly share code, notes, and snippets.

View anova's full-sized avatar

Necat Bolpaça anova

View GitHub Profile
@anova
anova / phone_number_format.js
Last active June 14, 2024 07:54
Format phone number for Turkey (+90) and strip parantheses and spaces.
function () {
if (!document.querySelector('#telefon') || 0 === document.querySelector('#telefon').value.length) {
return null;
}
var phone = '+90' + document.querySelector('#telefon').value.replace(/[\(|\)|\s]/g,'');
//+905551234567 -> 13 karakter
if (13 < phone.length) {
return null;
}
return phone;
@anova
anova / init.lua
Last active February 23, 2024 07:43
My initial neovim plugins and theme
-- vim: set autoindent expandtab shiftwidth=2 tabstop=2:
-- :PlugInstall
-- vim-plug https://github.com/junegunn/vim-plug
local vim = vim
local Plug = vim.fn['plug#']
local PlugBegin = vim.fn['plug#begin']
local PlugEnd = vim.fn['plug#end']
vim.cmd [[language en]]
const { PurgeCSSPlugin } = require("purgecss-webpack-plugin");
const glob = require("glob-all");
// https://stackoverflow.com/a/77249323/181295
module.exports = {
plugins: [
new PurgeCSSPlugin({
defaultExtractor: (content) => {
const defaultSelectors = content.match(/[A-Za-z0-9_-]+/g) || [];
const extendedSelectors = content.match(/[^<>"=\s]+/g) || [];
@anova
anova / web.config
Created November 1, 2023 11:22
web.config www and ssl enforce
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to www" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
@anova
anova / FAQPage-structured-rich-results.html
Created August 25, 2023 12:27
Sample HTML Structure for FAQPage Google Rich Results. https://search.google.com/test/rich-results
<!doctype html>
<html lang="tr" itemscope itemtype="https://schema.org/FAQPage">
<body>
<div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
<h2 itemprop="name">Sample Question 1?</h2>
<div itemprop="acceptedAnswer" itemscope itemtype="https://schema.org/Answer">
<div itemprop="text">
<p>Answer example 1</p>
</div>
</div>
@anova
anova / custom-scrollbar.css
Created August 11, 2023 09:30
Custom scrollbar example
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-thumb {
background-color: black;
}
::-webkit-scrollbar-track {
box-shadow: inset 0 0 2px gray;
@anova
anova / .htaccess
Created August 9, 2023 13:23
Enforce SSL and www with one redirect. Change example.com with your domain.
# https://stackoverflow.com/a/36986520
RewriteEngine On
RewriteCond %{HTTP_HOST} example\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
@anova
anova / cjs - search_term (q).js
Created August 8, 2023 11:12
Custom JavaScript Variable for GTM search_term query string
// cjs variable name: cjs - search_term (q)
function() {
var params = new URLSearchParams(window.location.search);
return params.get('q');
}
@anova
anova / createObserver.js
Created November 16, 2022 12:09
creates an Intersection Observer.
/** @return IntersectionObserver */
function createObserver(p_threshold) {
return new IntersectionObserver(
(entries) => {
entries.forEach((/** @type IntersectionObserverEntry */ entry) => {
if (entry.isIntersecting) {
const eventIntersecting = new CustomEvent("intersecting");
entry.target.dispatchEvent(eventIntersecting);
return;
}
@anova
anova / intersection-observer.js
Last active October 7, 2022 11:36
Trigger something when marked element's half percent is visible in viewport.
// define the observer
const observer = new IntersectionObserver((entries) => {
entries.forEach((/** @type IntersectionObserverEntry */ entry) => {
if (entry.isIntersecting) {
const eventIntersecting = new CustomEvent("intersecting");
entry.target.dispatchEvent(eventIntersecting);
return;
}
const eventNotIntersecting = new CustomEvent("not-intersecting");
entry.target.dispatchEvent(eventNotIntersecting);