Skip to content

Instantly share code, notes, and snippets.

View yeukhon's full-sized avatar

Yeuk Hon Wong yeukhon

  • TikTok USDS / ByteDance
  • New York, NY
  • 04:09 (UTC -04:00)
View GitHub Profile
FROM ubuntu:12.04.5
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y openssh-server git curl python-dev libpq-dev wget
RUN wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' >> /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get install -y postgresql-9.3
@yeukhon
yeukhon / BUILD.md
Last active August 29, 2015 14:06
Components selection for building a video editing and encoding workstation for my dad
@yeukhon
yeukhon / VAGRANT-COURSE.md
Last active March 19, 2022 15:44
Vagrant crash course
class Minheap(object):
def __init__(self, array):
self._array = [None] + array
self.build_heap()
def parent_of(self, i):
return i//2
def children_of(self, i):
return 2*i, (2*i)+1
def build_heap(self):
for i in xrange(len(self._array)//2, -1, -1):
@yeukhon
yeukhon / qselect.py
Last active August 29, 2015 14:06
Quickselect. Find the i-th order statistics in Python using Quicksort's randomized selection. This is a solution for https://www.hackerrank.com/challenges/find-median Note it is probably a better idea to pass the indices around instead of slicing (quicksort is an in-place sorting algorithm). But for simplicity, let's just use slice (which create…
import random
def q_select(numbers, ith):
if len(numbers) < 2:
return numbers[0]
# Chooses a pivot uniformly from random
p_index = random.randint(0, len(numbers)-1)
pivot = numbers[p_index]
# Before the partition, swap the pivot with the last element
numbers[p_index], numbers[-1] = (
import pqdict
def dijkstra(graph, source, target=None):
"""
Computes the shortests paths from a source vertex to every other vertex in
a graph
"""
# The entire main loop is O( (m+n) log n ), where n is the number of
# vertices and m is the number of edges. If the graph is connected
@yeukhon
yeukhon / list_alloc.py
Last active August 29, 2015 14:06
list extend vs nested loop
"""
>>> a = [[1,2], [3,3], [4]]
>>> o = []
>>> for x in a:
... o.extend(x)
...
>>> o
[1, 2, 3, 3, 4]
@yeukhon
yeukhon / README.md
Created September 4, 2014 21:48
How do you know where to "wrap" or "break" Python statement or expression into multiple lines?
stuff = set([ '%s.%s' % (prefix, type) for type in types(suffix) if prefix in get_types(given_type) ])
# how do I know where I can split this onto multiple lines?

and my answer is at the expression.

>>> [x
... for
import re
text1 = "alphanumeric@example.org"
text2 = "alphanumeric@long.subdomain.more.subdomain.domain.org"
r1 = re.compile(r'[a-zA-Z0-9]+@[a-zA-Z]+\.[a-zA-Z]+(\.[a-zA-Z]+)*')
print(r1.match(text1).group())
print(r1.match(text2).group())
print("part 2 - compare with and without (?:")
// api.js
var Job = function(settings, jq) {
var createJob = function(args) {
return $.ajax({
url: "https://yeukhon.me/api/job",
type: "POST",
crossDomain: true,
data: {
job_name: args.job_name,