Skip to content

Instantly share code, notes, and snippets.

Avatar

Eran Kampf ekampf

View GitHub Profile
View GalaxyCount.md

Galaxies Count

Problem Description

Given a 2d grid of '1's (space clusters with stars) and '0's (dark space clusters without any stars), count the number of galaxies on the grid. An Galaxy is a group a space clusters containing stars, surrounded by dark clusters (no starts) and connected horizontally or vertically.

Examples:

View cache.py
// Implement a cache class that stores given item. The cache is limited to a given `size` and will discard the
// least recently used item if it needs the space.
//
// Clearly document design choices, algorithm and possible optimizations.
// While we require you to implement one memory allocation algorithm,
// also document future looking design considerations.
//
// Implementation Notes:
// * While the interface below is written in Python, feel free to implement the Cache in the language of your choosing.
// * Do not use standard library data structures - write your own. (like Python's `collections` module etc.)
@ekampf
ekampf / mem.c
Last active May 20, 2020
Eran's Interview Question
View mem.c
// Implement a virtual memory manager that takes a large contiguous block of memory and manages allocations
// and deallocations on it.
// The entire buffer needs to be available for allocation. You can use whatever extra memory you need to manage it.
// You do need to consider the case of fragmentation.
// (Example test case: initialize with a buffer of 5 charts, allocate 5 blocks of szie 1, free blocks 2 and 4, try allocate a block of size 2)
//
// Clearly document design choices, algorithm and possible optimizations.
// While we require you to implement one memory allocation algorithm,
// also document future looking design considerations.
// There are many ways to implement this memory manager. It is important for us to know why you implemented it the way you did,
@ekampf
ekampf / big_query_dsl.py
Last active Apr 28, 2017
Choosing an Analytics Schema Scales
View big_query_dsl.py
__author__ = 'ekampf'
class FieldTypes(object):
integer = 'INTEGER'
float = 'FLOAT'
string = 'STRING'
record = 'RECORD'
ts = 'TIMESTAMP'
class FieldMode(object):
View test
{
"streams": {
"nasa": {
"input-path": "/HBOHD_HD_TVE_15152_0_5472624192174078163/format-hls-track-muxed-bandwidth-3101600-repid-root_audio_video1.m3u8",
"servers": [
"http://odol-atsec-sfb-43.linear-tve-pil.top.comcast.net"
]
}
},
"actions": [
@ekampf
ekampf / normalize.py
Last active Nov 20, 2016
Normalize values by std deviation
View normalize.py
def zscore(numbers_list):
numbers = numpy.array(numbers_list)
return (numbers - numbers.mean()) / numbers.std()
@ekampf
ekampf / resource_route.py
Last active Dec 17, 2015
webapp2.py (Google AppEgnine) Resource Route to describe RESTful resources
View resource_route.py
from webapp2 import Route
from webapp2_extras.routes import MultiRoute
from inflection import singularize, pluralize
__author__ = 'ekampf'
# pylint:disable=C0326,R0902
class ResourceRoute(MultiRoute):
@ekampf
ekampf / gist:13916578123fedb60977
Last active Aug 29, 2015
Python NotificationsManager and observer
View gist:13916578123fedb60977
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class observes(object):
def __init__(self, name):
@ekampf
ekampf / pypossibly.py
Created Jun 11, 2014
Python option patrern (Maybe Monad)
View pypossibly.py
import logging
import sys
class Maybe(object):
pass
class Nothing(Maybe):
def is_some(self):
return False
@ekampf
ekampf / nested_dict.py
Last active Aug 29, 2015
Python Nested Dictionary
View nested_dict.py
class Nil(object):
def __getitem__(self, key):
return Nil()
def __nonzero__(self):
return False
class NestedDict(dict):
def __init__(self, *args, **kwargs):
self.update(*args, **kwargs)
You can’t perform that action at this time.