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 / tax_name_parser.pl
Created November 25, 2016 20:23
Parser script about taxonomy id and name
my $filename = 'speclist.txt';
my $write_file = "parsed_taxonomy_id.txt";
open(IN, '<', $filename)
or die "Could not open file '$filename' $!";
open(my $out, ">", $write_file)
or die "Could not open file $write_file";
while(<IN>){
if ($_ =~ /(\d+)\:\sN=(.*)/){
print $out "$1|$2\n";
my ($type, $search_term) = @ARGV;
$file = 'parsed_tax_name.txt';
sub get_tax_id_or_name{
open(FILE, "<$file") or
die("Could not open log file. $!\n");
while(<FILE>) {
if ($type eq "-t" and $_ =~ /$search_term\|(.*)/){
return $1;
@mersanuzun
mersanuzun / CustomMatcher.scala
Created November 6, 2017 13:53
Custom matcher for Result object in scala
import org.scalatest.matchers.{MatchResult, Matcher}
import play.api.mvc.Result
trait CustomMatcher {
def beStatus(status: Int) = Matcher { obj: Result =>
MatchResult(
obj.header.status == status,
s"${obj.header.status} was not equal $status",
s"${obj.header.status} was equal $status",
)
@mersanuzun
mersanuzun / startup_script.sh
Created December 11, 2017 12:29
Create user and index in Mongodb
#!/bin/bash
# Set variables
USERNAME=$MONGODB_USERNAME
PASSWORD=$MONGODB_PASSWORD
DB_NAME=$MONGODB_DBNAME
# Create User
mongo $DB_NAME --eval "db.createUser({user: '$USERNAME',pwd: '$PASSWORD',roles: [{role: 'readWrite',db: '$DB_NAME'}]});"
@mersanuzun
mersanuzun / build.sbt
Last active December 22, 2017 08:32
Gatling custom simulation and data directory in sbt
// In build.sbt file
lazy val hub = (project in file("."))
.enablePlugins(GatlingPlugin)
.settings(inConfig(Gatling)(Defaults.testSettings): _*)
// for simulations
scalaSource in Gatling := baseDirectory.value / "test/gatling/"
// for data
resourceDirectory in Gatling := baseDirectory.value / "test/gatling/resources/data/"
@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) => {
@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 / 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 / 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])) {
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) => {