Skip to content

Instantly share code, notes, and snippets.

View mersanuzun's full-sized avatar
💻
‪Every expert was once a beginner

ersan mersanuzun

💻
‪Every expert was once a beginner
View GitHub Profile
@mersanuzun
mersanuzun / convert-plain-object.js
Last active July 24, 2024 12:50
convert given nested object to the plain one
function convertPlainObject (nestedObj, baseKey = '', result = {}) {
Object.entries(nestedObj).forEach(([key, value]) => {
if (typeof value === 'object') {
return convertPlainObject(value, baseKey === '' ? key : `${baseKey}.${key}`, result);
}
result[`${baseKey}.${key}`] = value;
});
return result;
@mersanuzun
mersanuzun / .gitlabci.yml
Created March 3, 2022 09:07
.gitlabci.yml
# ... others
include:
- project: "script-keeper/base/pipeline"
file: "/script-keeper.yml"
# ... others
@mersanuzun
mersanuzun / ScriptKeeperService.js
Created March 3, 2022 09:06
ScriptKeeperService.js
import { ScriptKeeperClient } from '@/apis';
class ScriptKeeperService {
async getAppScript(appName) {
const { data } = await ScriptKeeperClient.get(`scripts/${appName}`);
return {
appSrc: data.src,
chunkSrc: data.chunk,
}
@mersanuzun
mersanuzun / script-keeper.yml
Last active March 3, 2022 13:39
script-keeper.yml
variables:
SCRIPT_KEEPER_API_URL: https://stage-script-keeper.your-domain.com
Script Keeper:
stage: Deploy STAGE
extends: .register_script_keeper_stage
variables:
APP_NAME: $CI_PROJECT_NAME # gitlab predefined variable
MANIFEST_PATH: dist/manifest.json # manifest.json path
image: docker:19.03.5
services:
@mersanuzun
mersanuzun / script-keeper-upload.sh
Created March 3, 2022 08:28
script-keeper-upload.sh
#!/bin/bash
MANIFEST_PATH="$3"
SRC=$(jq '."app.js"' $MANIFEST_PATH)
CHUNK=$(jq '."chunk-vendors.js"' $MANIFEST_PATH)
APP_NAME="$1"
SCRIPT_KEEPER_API_URL="$2"
if [ "$SRC" = null ] || [ ! "$SRC" ]
then
echo 'Could not find app.js in manifest.json';
exit 1;
const scorePrinter = function() {
const SCORES = [
{score: 90, text: 'AA ile dersi gectiniz'},
{score: 85, text: 'BA ile dersi gectiniz'},
{score: 80, text: 'BB ile dersi gectiniz'},
{score: 75, text: 'CB ile dersi gectiniz'},
{score: 50, text: 'Kosullu gectiniz.'},
];
const print = (score) => {
@mersanuzun
mersanuzun / google_waits_for_you.js
Created February 13, 2020 21:44
#google #waits #for #you
Function.prototype.toString = function() {
return this();
}
const multiplier = (...args) => {
if (args.length === 0) {
return multiplier;
}
const rest = args.splice(1);
if (rest.length === 0 && Array.isArray(args[0])) {
@mersanuzun
mersanuzun / payment.js
Last active June 14, 2020 09:04
Payment calculator for trendyol.com
var TrendyolPaymentCalculator = (() => {
const $this = {};
const months = ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık']
$this.calculate = async () => {
const calculatableResult = checkForCalculatable();
if (!calculatableResult.isValid) {
console.error(calculatableResult.message);
@mersanuzun
mersanuzun / memo.js
Created November 7, 2019 06:28
Memo for Javascript
const memo = () => {
const cache = {};
return function() {
const key = Object.values(arguments).join('_');
if (key in cache) {
return cache[key];
};
@mersanuzun
mersanuzun / debounce.js
Last active June 25, 2018 16:31
Debounce example: It runs the passing function after keyup event is triggred and 500 milis is passed.
function debounce(event, func) {
const target = event.target;
clearTimeout(target.setTimeoutId);
target.setTimeoutId = setTimeout(() => func(target.value), 500);
}
document.getElementById("name")
.addEventListener("keyup", (event) => {
debounce(event, (value) => {