Skip to content

Instantly share code, notes, and snippets.

View mucahitnezir's full-sized avatar
🎯
Focusing

Mücahit Nezir mucahitnezir

🎯
Focusing
View GitHub Profile
@mucahitnezir
mucahitnezir / tc-kimlik.js
Last active February 14, 2023 07:16
Generate identity number for Republic of Turkey
const generateNumber = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const generateIdentityNumber = () => {
const identityNumber = [];
for (let index = 0; index < 9; index++) {
const minNumber = index === 0 ? 1 : 0;
identityNumber[index] = generateNumber(minNumber, 9);
@mucahitnezir
mucahitnezir / function.js
Created September 21, 2020 12:41
Lambda function for url rewriting: lambda@edge function
const appendToDirs = 'index.html';
const regexSuffixless = /\/[^/.]+$/; // e.g. "/some/page" but not "/", "/some/" or "/some.jpg"
const regexTrailingSlash = /.+\/$/; // e.g. "/some/" or "/some/page/" but not root "/"
exports.handler = (event, context, callback) => {
const { request } = event.Records[0].cf;
const { uri } = request;
// Append ".html" to origin request
if (uri.match(regexSuffixless)) {
@mucahitnezir
mucahitnezir / nginx.conf
Created September 21, 2020 12:31
Nginx site configuration for: SPA website and Node.js proxy pass
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html;
location /backend/ {
rewrite ^/backend/(.*) /$1 break;
@mucahitnezir
mucahitnezir / index.html
Created May 17, 2019 12:44
Api Gateway WebSocket Demo on Frontend
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebSocket Demo</title>
</head>
@mucahitnezir
mucahitnezir / style.css
Last active November 24, 2018 11:28
CSS class for one line text
.one-line-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
@mucahitnezir
mucahitnezir / .env
Last active July 11, 2018 08:24
Node.js mail sender helper file.
COMPANY_NAME = your-company-name
MAIL_SERVICE = mail-service-name
MAIL_ADDRESS = [email protected]
MAIL_PASSWORD = mail-password
@mucahitnezir
mucahitnezir / .htaccess
Created December 30, 2017 16:08
.htaccess file to block non allowed redirects.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} redirectedsiteaddress1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} redirectedsiteaddress2\.com [NC]
RewriteRule .* - [F]
</IfModule
@mucahitnezir
mucahitnezir / app.js
Last active January 13, 2018 21:38
My custom handlebars template engine configuration
const express = require("express")
, exphbs = require("express-handlebars");
/* Create express instance */
var app = express();
/* Configure hbs view engine */
var hbs = exphbs({
extname: 'hbs',
defaultLayout: 'mainLayout',
@mucahitnezir
mucahitnezir / .htaccess
Last active August 21, 2023 01:11
General .htaccess file for gzip/deflate compression and redirecting both of www and ssl(https). Needed modules in httpd.conf: deflate_module(modules/mod_deflate.so), (expires_module modules/mod_expires.so), (headers_module modules/mod_headers.so), (rewrite_module modules/mod_rewrite.so)
## KEEP-ALIVE ##
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
## KEEP-ALIVE ##
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
@mucahitnezir
mucahitnezir / functions.php
Last active July 18, 2019 12:58
Googe Tag Manager integration for wordpress websites. Replace your GTM code with YOUR-GTM-CODE in functions.php. Copy the contents of these files to active wordpress theme in your wordpress website.
<?php
/* Google Tag Manager Code For Head Tag */
add_action('wp_head', 'wp_head_tag_manager');
function wp_head_tag_manager()
{
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],