Skip to content

Instantly share code, notes, and snippets.

:octocat:
coding

Selim Ozturk selimslab

:octocat:
coding
View GitHub Profile
View complex-vs-simple.md

When you first solve a problem, you come up with something very complex, and most people stop there. If you keep living with the problem you arrive at very elegant and simple solutions. - Steve Jobs

these 2 solutions for the same problem reminds me this quote

View nodeSummary.js
// net
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
var q = url.parse(req.url, true).query;
var txt = q.year + " " + q.month;
res.end(txt);
@selimslab
selimslab / LoginUtil.kt
Created May 31, 2020
native Android login, in Kotlin
View LoginUtil.kt
package com.example.ozturkse.awesomelogin
import android.content.Context
import android.support.v7.app.AppCompatActivity
class LoginUtil {
private val EMAIL = "email_shared_pref"
private val PASSWORD = "password_shared_pref"
@selimslab
selimslab / pas.py
Last active May 27, 2020
a simple interpreter in python
View pas.py
"""
Here be dragons
This is a basic interpreter
a computer program is just text. Compilers and interpreters translate this text for the machine
let's say our program is 2 * 7 + 3
1. First step is lexical analysis, a fancy term for tokenizing
View minWindow.py
def minWindow(self,s, t):
"""
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
Input: S = "ADOBECODEBANC", T = "ABC"
Output: "BANC"
1. Use two pointers: start and end to represent a window.
2. Move end to find a valid window.
3. When a valid window is found, move start to find a smaller window.
View map.js
function map(func, array) {
var result = [];
forEach(array, function (element) {
result.push(func(element));
});
return result;
}
show(map(Math.round, [0.01, 2, 9.89, Math.PI]));
View findUnsortedSubarray.js
const findUnsortedSubarray = nums =>
nums
.slice()
.sort((a, b) => a - b)
.reduce((acc, curr, idx) => acc + (curr === nums[idx] ? ' ' : 'x'), '')
.trim().length;
View codec.py
"""Design an algorithm to serialize and deserialize a binary tree. """
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Codec:
View trie.py
class Trie:
""" or prefix tree """
def __init__(self):
"""
a child of a Trie is a Trie
"""
self.trie = {}
def insert(self, word: str) -> None:
"""
View readme.md

You are a professional robber planning to rob houses along a street.

Each house has a certain amount of money stashed.

Meanwhile, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

q1: max robbery ?

q2: what if houses form a circle so the first and last are neighbors ?

You can’t perform that action at this time.