Skip to content

Instantly share code, notes, and snippets.

:octocat:
coding

Selim Ozturk selimslab

:octocat:
coding
View GitHub Profile
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 Channels.go
Channels are a typed conduit through which you can send and receive values with the channel operator, <-.
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and
// assign value to v.
(The data flows in the direction of the arrow.)
Like maps and slices, channels must be created before use:
View csv.py
import csv
def read_csv(file_path):
with open(file_path, "r") as csvFile:
# or reader = csv.DictReader(csvFile)
reader = csv.reader(csvFile)
for row in reader:
yield row
@selimslab
selimslab / filters.py
Last active Jun 7, 2020
an API to explore mobile user events , built with Django REST, has filter, group, sort, and aggregate
View filters.py
from django_filters.rest_framework import FilterSet
from django_filters import DateFromToRangeFilter
from api.models import Record
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
class CustomFilter(FilterSet):
date = DateFromToRangeFilter()
View plusOne.go
func plusOne(digits []int) []int {
/*
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
View reverseBits.go
func reverseBits(num uint32) uint32 {
/*
Input: 00000010100101000001111010011100
Output: 00111001011110000010100101000000
*/
res := uint32(0)
power := uint32(31)
for num != 0 {
res += (num & 1) << power
num = num >> 1
View sortedArrayToBST.py
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
"""
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Example:
Given the sorted array: [-10,-3,0,5,9],
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 removeDuplicates1.py
def removeDuplicates(self, S: str) -> str:
"""
Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.
We repeatedly make duplicate removals on S until we no longer can.
Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.
Example 1:
View heap.py
class KthLargest:
"""
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Your KthLargest class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method KthLargest.add, return the element representing the kth largest element in the stream.
Example:
int k = 3;
int[] arr = [4,5,8,2];
You can’t perform that action at this time.