Skip to content

Instantly share code, notes, and snippets.

View msoedov's full-sized avatar
:shipit:
Working from home

Alexander Myasoedov msoedov

:shipit:
Working from home
View GitHub Profile
import random
import itertools
COMPUTE_UNITS_PER_CYCLE = 24
CYCLES = 1000
task_weights = [0.1, 1, 6]
task_prob = [1, .4, .1]
"""
Given two 1d vectors, implement an iterator to return their elements alternately.
For example, given two 1d vectors:
v1 = [1, 2]
v2 = [3, 4, 5, 6]
By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1, 3, 2, 4, 5, 6].
Follow up: What if you are given k 1d vectors? How well can your code be extended to such cases?
package main
import (
"fmt"
"math"
"sync"
"time"
log "github.com/Sirupsen/logrus"
)
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. go vet (http://golang.org/cmd/vet)
# 3. gosimple (https://github.com/dominikh/go-simple)
# 4. unconvert (https://github.com/mdempsky/unconvert)
# 5. ineffassign (https://github.com/gordonklaus/ineffassign)
# 6. race detector (http://blog.golang.org/race-detector)
# 7. test coverage (http://blog.golang.org/cover)
from collections import deque
class RingBuff:
"""
# Spec for buffer
>>> buffer = RingBuff(5)
>>> buffer.write([1, 2, 3])
3
>>> buffer.write([4, 5, 6])
def wrapper3():
v = dict(counter=0)
def incr():
v['counter'] += 1
return v['counter']
return incr
fn = wrapper3()
from collections import defaultdict
# Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
# Only one letter can be changed at a time
# Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
# For example,
# Given:
# beginWord = "hit"
@msoedov
msoedov / topological_sort.py
Created March 19, 2018 20:11
sort_direct_acyclic_graph
import collections
def topological_sort(edge_list):
graph = collections.defaultdict(set)
for node, child in edge_list:
graph[node].add(child)
nodes = set(graph)
visited = set()
ordered = set()

Keybase proof

I hereby claim:

  • I am msoedov on github.
  • I am alex_mia (https://keybase.io/alex_mia) on keybase.
  • I have a public key ASBIHSvBS6d7MlO8ktNp2RK1id-Sp11usZ69em2lIB08sQo

To claim this, I am signing this object:

dockerfile = """
FROM python:{py_version}
MAINTAINER {maintainer}
WORKDIR /app
RUN pip install {requirements}
ENV PY_LIB "{app_content | encode_base64}"
RUN python -c "import os,base64;b=os.getenv('PY_LIB');b=base64.b64decode(b);print(b.decode('utf-8'))" | tee app.py
CMD python app.py
"""