Skip to content

Instantly share code, notes, and snippets.

View orhanveli's full-sized avatar

orhan orhanveli

  • Finbyte GmbH
  • Turkiye
  • 19:19 (UTC +03:00)
View GitHub Profile
@orhanveli
orhanveli / interview-question.js
Created September 23, 2020 13:55
The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and still retain the recursive pattern?
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
// process the list item...
nextListItem();
}
};
@orhanveli
orhanveli / interview-question.js
Created September 23, 2020 13:52
Write a sum method which will work properly when invoked using either syntax below.
console.log(sum(2,3)); // Outputs 5
console.log(sum(2)(3)); // Outputs 5
@orhanveli
orhanveli / interview-question.js
Created September 23, 2020 13:50
What will the code below output? Explain your answer.
console.log(0.1 + 0.2);
console.log(0.1 + 0.2 == 0.3);
@orhanveli
orhanveli / interview-question.js
Created September 23, 2020 13:48
What will the code below output to the console and why?
(function(){
var a = b = 3;
})();
console.log("a defined? " + (typeof a !== 'undefined'));
console.log("b defined? " + (typeof b !== 'undefined'));
@orhanveli
orhanveli / email-verify.js
Last active March 4, 2020 13:39
email-verify with nodejs
const dns = require('dns');
const mailcheck = require('mailcheck');
const isDomainMXValid = (domain) => {
return new Promise((resolve, reject) => {
dns.resolveMx(domain, (err, mxs) => {
if (err) {
reject(err);
}
resolve(!!(mxs && mxs.length > 0 && mxs[0].exchange));
@orhanveli
orhanveli / makeReq.ts
Created November 26, 2019 17:16
make req with http module
export const makeReq = (url: string | undefined, data = '', headers: any = {}, timeout = 5000): Promise<string> => {
if (!url) {
throw 'url must be defined!';
}
const contentLength = Buffer.byteLength(data, 'utf-8');
headers['Content-Length'] = contentLength;
headers['Content-Type'] = 'text/xml; charset=utf-8';
headers['Connection'] = 'keep-alive';
@orhanveli
orhanveli / README.md
Last active September 27, 2019 10:04
react-native-webview auto height and link click handler via window.postMessage
@orhanveli
orhanveli / namesub.py
Last active October 13, 2018 06:27 — forked from jasalt/namesub.py
rename subtitle files to match video files in same folder
'''
Rename subtitle files in same folder to match the movie file
(for xbmc-share folder)
Jarkko Saltiola 2013
'''
import os
import re
video_types = ["mkv","avi"]
@orhanveli
orhanveli / wp.sh
Last active December 5, 2017 03:52 — forked from bgallagh3r/wp.sh
Wordpress: Bash Install Script -- Downloads latest WP version, updates wp-config with user supplied DB name, username and password, creates and CHMOD's uploads dir, copies all the files into the root dir you run the script from, then deletes itself!
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
echo "Database User: "
read -e dbuser
echo "Database Password: "
@orhanveli
orhanveli / wordpress-backup.sh
Created July 5, 2017 08:17
wordpress-backup.sh
#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H%M")
DB_USER="dbuser"
DB_PASS="dbpass"
DB_NAME="database_name"
DB_HOST="127.0.0.1"
TREE_FILE="$NOW.tar.gz"