Skip to content

Instantly share code, notes, and snippets.

@Yengas
Yengas / homography-rotate.py
Created April 11, 2018 22:40
Multiplying two homography with opencv python. Combining two homography so the output will be rotated
# Rotates the given homography from the origin point
def getRotatedHomography(homography, size, angle):
width, height = size
rotation = cv2.getRotationMatrix2D((width / 2, height / 2), angle, 1)
rotationHomography = np.concatenate((rotation, np.array([[0, 0, 1]])))
return np.dot(rotationHomography, homography)
@Yengas
Yengas / promise.js
Last active May 19, 2018 18:56
A promise implementation without any spec compliance. Just for fun.
class MyPromise{
// create a new instance of a promise
// callback is a function that accepts resolve and reject functions as params
constructor(callback){
this.resolved = false;
this.reject = false;
this.value = null;
// to temporarily hold promises that got created while this promise was in pending state
this.waiting = [];
@Yengas
Yengas / Encrypt.ts
Created May 19, 2018 17:16
Cross platform (react native, web, node) aes/triple des encryption and decryption with crypto-js
import { AES, TripleDES, lib, mode, CipherOption, Cipher } from 'crypto-js';
import { BinaryFormatter, wordArrayToUint8Array } from './utils';
export enum EncryptionAlgorithm{
AES = 0,
TripleDES = 1,
}
//const options = { padding: pad.ZeroPadding, mode: mode.CBC };
const options = {
[EncryptionAlgorithm.TripleDES]: {
@Yengas
Yengas / async-await-with-generators.js
Last active June 17, 2018 13:32
Simple implementation of async/await workflow with generators and yield.
function doSomething(){
return Promise.resolve(73);
}
function timeout(ms){
return new Promise((resolve) => setTimeout(resolve, ms, ms));
}
function asyncFlow(generatorFunc){
const generator = generatorFunc();
@Yengas
Yengas / example.md
Last active October 6, 2018 14:27
A python script that compares two branches/commits to see which files where added/deleted/modified/renamed. And also prints out which line ranges where added/deleted.

Usage

# get the diff between current head and master
git-changed-files-and-lines.py master
# get the diff between master and dev
git-changed-files-and-lines.py master dev

Example Result

@Yengas
Yengas / schema-optimization-explain.scala
Created November 15, 2018 16:32
Spark at Getir - 01
// Previous approach to conversion
// definition
def rowToDocument(row: Row): BsonDocument
// usage
rowToDocument(row) // for each line
// The (micro) optimized approach
// definition
def rowToDocumentMapper(schema: StructType): (Row) => BsonDocument
// usage
@Yengas
Yengas / insert-example.scala
Last active November 16, 2018 10:13
Spark At Getir - 01
import org.apache.spark.sql.types._
import org.apache.spark.sql.functions._
case class Order(id: String, userName: String)
val orders = Seq(Order("5b85bda7685ca053517a948b", "Ahmet"), Order("5b85bda764d8194a675a546d", "Mehmet"), Order("5b85bda812c1e568bc6596dc", "Ahmet")).toDS()
orders
.groupBy("userName")
.agg(
first(struct($"id" as "oid")) as "firstOrder",
@Yengas
Yengas / docker-compose.yaml
Created April 21, 2019 08:33
Lobby Menu deployment
version: '3'
networks:
face-network: {}
volumes:
database-storage: {}
services:
database:
build: ./persistence/database
volumes:
- database-storage:/data/db
# git commit with branch helper
gam () {
MESSAGE="$1"
TASK_ID=$(git branch | grep \* | cut -d ' ' -f2 | perl -l -ne '/[a-z]+\/([A-Z]+\-[0-9]+)($|=)/ && print $1')
if [ -z "$TASK_ID" ]; then
echo "task id not be found. branch examples: feature/RECO-01, feature/RECO-01=long-description"
echo "falling back to normal commit"
git commit -am "$MESSAGE"
elif [ -z "$MESSAGE" ]; then

Clean Code

Introduction

  • Writing clean code is like riding a bike, you can study physics of it, but still fall down the first time you try to do it
  • Programming languages will be created with higher abstractions, and more specific languages related to domains we work will be created(a+), but that doesn’t mean programming will be a lost art. We can’t create machines that do what we want. We can only create machines that can do what we say.

Chapter 1: Clean Code

  • Leblanc’s law: later equals never