Skip to content

Instantly share code, notes, and snippets.

View garenyondem's full-sized avatar
:shipit:

Garen Yöndem garenyondem

:shipit:
View GitHub Profile
@garenyondem
garenyondem / cmd.sh
Created October 8, 2016 12:38 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@garenyondem
garenyondem / platformHelper.js
Created August 23, 2017 16:42
Extract Platform From UserAgent
var constants = require('./constants');
function extractPlatformFromUserAgent(reqHeaders) {
if (!!reqHeaders['user-agent'].match(/iOS/) || !!reqHeaders['user-agent'].match(/iPhone/) || !!reqHeaders['user-agent'].match(/iPad/)) {
return constants.platform.ios;
} else if (!!reqHeaders['user-agent'].match(/Android/)) {
return constants.platform.android;
} else {
return null;
}
@garenyondem
garenyondem / server.js
Created September 22, 2017 15:25
Node.js Sample Server with Restify
/*
* Node.js Sample Server with Restify
* Copyright (C) 2014 - Thiago Uriel M. Garcia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
@garenyondem
garenyondem / data.json
Last active December 28, 2017 12:09
NodeJS Nedir?
{
"Author": "Garen",
"Message": "Hello World"
}
@garenyondem
garenyondem / getQueryParams.js
Last active December 28, 2017 12:09
NodeJS HTTP Server
const getQueryParams = function (req) {
let query = req.url.split('?');
let queryParams = {};
if (query.length >= 2) {
let params = query[1].split('&');
params.forEach((keyValuePair) => {
try {
let key = keyValuePair.split('=')[0];
let value = keyValuePair.split('=')[1];
queryParams[key] = value;
@garenyondem
garenyondem / invert-binary-tree.js
Created June 4, 2018 20:36 — forked from kidGodzilla/invert-binary-tree.js
Invert a Binary Tree in Javascript
// This problem was inspired by this original tweet by Max Howell:
// Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
// So, let's invert a binary tree in Javascript
// Original Tree
// 4
// / \
// 2 7
// / \ / \
const fs = require('fs').promises
(async () => {
try {
const data = JSON.parse(await fs.readFile('/path/to/file.json', 'utf8'))
} catch(err) {
console.error(err)
}
})()
:loop
start "My Great App Name" "C:\Users\Garen\Desktop\greatapp.exe" "param1"
timeout /t 600
goto loop
@garenyondem
garenyondem / encryptor.js
Last active October 23, 2018 20:08
Encrypt or decrypt strings in Node.js
const crypto = require('crypto');
module.exports = class Encryptor {
constructor(encryptionKey) {
this.ENCRYPTION_KEY = encryptionKey.toString(); // Must be 256 bits (32 characters)
this.IV_LENGTH = 16; // For AES, this is always 16
}
encrypt(text) {
let iv = crypto.randomBytes(this.IV_LENGTH);