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 / docker-compose.yml
Last active April 27, 2023 21:18
my local development environment
version: '3.8'
services:
mongo:
image: mongo:5.0
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin123
ports:
@mucahitnezir
mucahitnezir / index.js
Created June 23, 2021 10:12
PageSpeed Insights API
const axios = require('axios');
const config = {
method: 'get',
url: 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed',
params: {
key: '<YOUR_GOOGLE_API_KEY>',
url: 'https://mucahitnezir.com',
locale: 'tr'
},
@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 = yourname@yoursite.com
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',