Skip to content

Instantly share code, notes, and snippets.

@cceasy
cceasy / user-script.js
Last active November 7, 2023 01:05
tampermonkey js
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
function replaceSpanContentById(sid, txt) {
@cceasy
cceasy / TransferMain.java
Created June 13, 2023 05:24
Tmp Bank Transfer
import java.util.*;
public class TmpMain {
List<One2OneTransfer> makeTransfer(List<AccountBalance> accounts, int baseAmount) {
if (accounts == null || accounts.isEmpty()) {
return Collections.emptyList(); // TODO we treat this case as doing nothing
}
int sum = accounts.stream().mapToInt(a -> a.balance).sum(); // TODO we assume amount sum would not exceed MAX INT
if (sum / accounts.size() < baseAmount) {
return null; // null means unable to do such a transfer
@cceasy
cceasy / min_coin_cnt.py
Created August 31, 2020 08:10
buy_coke - min_coin_cnt
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
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
[9291,9293,9295]
# 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
#!/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
#!/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
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

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