Skip to content

Instantly share code, notes, and snippets.

@cceasy
cceasy / min_coin_cnt.py
Created August 31, 2020 08:10
buy_coke - min_coin_cnt
View min_coin_cnt.py
cache = dict()
def min_coin_cnt(i, j, k, n):
"""
assert i + j*5 + k * 10 >= n * 8
"""
if n == 0:
return 0
elif (i, j, k, n) in cache:
# print("HIT ", (i,j,k,n), '=', cache[(i,j,k,n)])
return cache[(i,j,k,n)]
@cceasy
cceasy / disjoint_set.py
Last active August 31, 2020 08:50
DisjointSet - union & find
View disjoint_set.py
class DisjointSet(object):
index = list()
depth = list()
def __init__(self, n):
self.index = list(range(n))
self.depth = [0] * n
def tree_num(self):
@cceasy
cceasy / vip_at_models.json
Last active September 16, 2019 07:00
used for spark sync pipeline
View vip_at_models.json
[9291,9293,9295]
View bit_array.py
# A bit array demo - written for Python 3.0
import array
def makeBitArray(bitSize, fill = 0):
intSize = bitSize >> 5 # number of 32 bit integers
if (bitSize & 31): # if bitSize != (32 * n) add
intSize += 1 # a record for stragglers
if fill == 1:
fill = 4294967295 # all bits set
else:
fill = 0 # all bits cleared
@cceasy
cceasy / server.py
Created June 25, 2019 02:42 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
View server.py
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
@cceasy
cceasy / resize_images.py
Created October 27, 2018 07:45
batch resize images
View resize_images.py
#!/usr/bin/env python
import os
from PIL import Image, ExifTags
from shutil import copyfile
orientation = 0x0112 # image exif info for Orientation 274
device = 0x010f # image exif info for Make 271
src_dir = 'todo'
@cceasy
cceasy / thrift.rb
Created October 25, 2018 07:16 — forked from chrislusf/thrift.rb
Install Thrift 0.9.3 with brew on macOS
View thrift.rb
class Thrift < Formula
desc "Framework for scalable cross-language services development"
homepage "https://thrift.apache.org/"
stable do
url "https://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.3/thrift-0.9.3.tar.gz"
sha256 "b0740a070ac09adde04d43e852ce4c320564a292f26521c46b78e0641564969e"
# Apply any necessary patches (none currently required)
[
@cceasy
cceasy / Flask on CF.md
Created August 23, 2017 04:39 — forked from ihuston/Flask on CF.md
Simple Flask application for Cloud Foundry
View Flask on CF.md

Simple Python Flask app on Cloud Foundry

This is a (very) simple Flask application that shows how the built-in Python buildpack detection on Cloud Foundry works.

To push to Cloud Foundry, log in and then use

$ cf push myapp-name

Python on Cloud Foundry