This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import io | |
from pathlib import Path | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
from PIL import ExifTags | |
import exiftool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function signature(e){switch(typeof e){case"string":return"s";case"number":return Number.isInteger(e)?"i":"f";case"undefined":return"u";default:return null===e?"n":e.constructor===Array?"a":`{${Object.keys(e).sort().map(r=>`${r}:${signature(e[r])}`).join(",")}}`}} | |
function deserilize(sign){return eval(`i='i';s='s';n='n';a='a';f='f';var o=${sign};o;`)} | |
function _diff([e,t]){return Object.keys(e).forEach(f=>{"object"==typeof e[f]&&"object"==typeof t[f]?([e[f],t[f]]=_diff([e[f],t[f]]),Object.keys(e[f]).length||Object.keys(t[f]).length||(delete e[f],delete t[f])):e[f]===t[f]&&(delete e[f],delete t[f])}),[e,t]} | |
function diff(f,i){return _diff([f,i].map(deserilize))} | |
// > use mydb | |
db.mycollection.mapReduce(function() { emit(signature(this), 1)}, function(k, vs) { return Array.sum(vs) }, { out: {replace: 'mycollection_', db: 'mydbschema'}, scope: { signature }) | |
// > use mydbschema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const java = require('java'); | |
const path = require('path'); | |
const JAVA_DIR = path.resolve(__dirname, '../libs/java/'); | |
java.options = [ '-Xms3072m' , '-Xmx3072m', '-Xmn1152m' ]; | |
java.asyncOptions = { | |
asyncSuffix: 'Async', | |
syncSuffix: '', // For readability, remove the convetional suffix of sync | |
// functions. | |
ifReadOnlySuffix: '_alt', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import importlib | |
import inspect | |
import sys | |
from copy import copy | |
from pathlib import Path | |
from types import ModuleType | |
import klepto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
import argparse | |
import json | |
import os | |
import shutil | |
from pathlib import Path | |
def convert(obj): | |
if type(obj) == list: | |
return [convert(item) for item in obj] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Node: # for the effectivity reason, do not inherit from ABCs | |
__slots__ = ('beg', 'end', 'link', 's', 'node') | |
def __init__(self, s): | |
self.s = s | |
self.beg = self.end = self.link = None | |
self.node = defaultdict(lambda: Node(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
The implementation of getting n largest elements in the array. | |
The algorithms follows the page: | |
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/ | |
''' | |
import operator | |
from math import inf | |
def nlargest_bubble(n, items): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstring> | |
#include <iostream> | |
#include <algorithm> | |
#include <utility> | |
using namespace std; | |
class MyString { | |
public: | |
MyString() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict, deque | |
def max_trinket(s, a): | |
''' | |
Attributes: | |
s: The maximum number of trinkets allowed of a single type | |
a: Array of the types of the trinkets | |
''' | |
if not s: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import itemgetter | |
def eat(stones): | |
max_e = {} | |
stones.sort(key=itemgetter(2), reverse=True) | |
def dp(time, i): | |
if i == len(stones): | |
return 0 | |
if (time, i) not in max_e: | |
max_e[(time, i)] = max( |