Skip to content

Instantly share code, notes, and snippets.

View xplorld's full-sized avatar

Ruiyang Wang xplorld

View GitHub Profile
@xplorld
xplorld / leetcode 套路.md
Last active September 25, 2022 03:38
leetcode 套路

array -> contiguous subarray with max(f(arr))

套路 - 2 max

从左往右扫,维护 2 个 max,

  • 一个是 max(sub(arr[0:n]))
  • 一个是 max(sub(arr[0:n], including arr[n]))
for n in arr:

In dream about a nice language

We live in a world where computations are pervasive but still we don't have a "nice-enough" language for programmers to work, and every existing languages have certain drawbacks. This sketch aims to think of a hypothetical language that is nice-enough.

Why can't we have a nice language?

  • Lagacy (C++ headers, Python2 encodings, Bash ugliness)
  • Evolution of PL theory (generics, lifetime, ...), idk too much
  • Industry Experience (Inheritance considered evil, implicit type conversion (to some extent),...)
  • Learning curve (I don't like to use this term, but...)
@xplorld
xplorld / trie.py
Last active August 28, 2019 03:03
leetcode-safe trie
import collections
class Trie:
def __init__(self):
self.children = collections.defaultdict(Trie)
self.is_leaf = False
def add(self, string):
if string == '':
self.is_leaf = True
else:
@xplorld
xplorld / sorts.py
Last active December 17, 2018 23:30
One-line sort algorithms. Haskellized python code.
'''
Haskellized python code
License: WTFPL
'''
qsort1 = (lambda arr:arr if (len(arr)<2) else qsort1(filter(lambda x:x <= arr[0],arr[1:])) + [arr[0]] + qsort1(filter(lambda x:x > arr[0],arr[1:])))
qsort2 = (lambda arr:arr if (len(arr)<2) else qsort2([x for x in arr[1:] if x <= arr[0]]) + [arr[0]] + qsort2([x for x in arr[1:] if x > arr[0]]))
bsort = (lambda arr:arr if (len(arr)<2) else (lambda mid:bsort(filter(lambda x:x <= mid,arr))+bsort(filter(lambda x:x > mid,arr)))((max(arr)+min(arr))/2))
merge = lambda a,a1,a2: a+a2 if not a1 else a+a1 if not a2 else merge(a+[a1[0]],a1[1:],a2) if a1[0] < a2[0] else merge(a+[a2[0]],a1,a2[1:])
msort = lambda a:a if (len(a)<2) else merge([],msort(a[:len(a)/2]),msort(a[len(a)/2:]))
@xplorld
xplorld / Jason.json
Created November 5, 2018 03:24
调查员 #1. 胡立强 (Jason)
[{"character_name":"胡立强 (Jason)","player":"王瑞扬","occupation":"Trader","sex":"男","age":"28","birthplace":"河南安阳","residence":"旧金山","str":"60","dex":"70","pow":"70","con":"45","app":"60","edu":"80","siz":"65","int":"66","luck":"35","hp":"11","armor":"","san":"70","san_start":"70","mp":"","psychology":"10","credit_rating":"50","persuade":"10","fast_talk":"5","intimidate":"75","charm":"15","navigate":"10","survival_name":"生存(10%)","survival01":"10","jump":"80","climb":"50","swim":"20","drive_auto":"20","drive_other01_name":"駕駛(1%)","drive_other01":"1","ride":"5","stealth":"20","track":"10","disguise":"5","locksmith":"1","sleight_of_hand":"10","language_own":"","language_other_name":"語言(1%) ","language_other01":"1","accounting":"75","law":"5","occult":"5","history":"5","natural_world":"10","anthropology":"1","archaeology":"1","compute_use":"50","acting":"5","mech_repair":"10","elec_repair":"10","op_hv_machine":"1","spot_hidden":"25","listen":"20","library_use":"50","appraise":"70","cthulhu_mythos":"0","first_aid":"
@xplorld
xplorld / py
Created June 8, 2018 03:36
658. Find K Closest Elements
import bisect
class Solution:
def findClosestElements(self, arr, k, x):
"""
:type arr: List[int]
:type k: int
:type x: int
:rtype: List[int]
"""
@xplorld
xplorld / HallOfShame.md
Created March 19, 2018 19:16
Hall of SHAME

Making up language B by concentration of strings in language A should be put on the Hall of SHAME

  • concentrating SQL queries in Any lanugage
  • concentrating HTML in JavaScript
  • concentrating JavaScript in HTML
  • concentrating JavaScript in Backend languages
@xplorld
xplorld / PL_checklist.md
Created February 12, 2018 19:49
A checklist before you want to invent a new programming language

This work is copied from http://colinm.org/language_checklist.html. Thanks to Colin McMillen, Jason Reed, and Elly Jones for this amazing work!

Programming Language Checklist by Colin McMillen, Jason Reed, and Elly Jones.

You appear to be advocating a new: [ ] functional [ ] imperative [ ] object-oriented [ ] procedural [ ] stack-based [ ] "multi-paradigm" [ ] lazy [ ] eager [ ] statically-typed [ ] dynamically-typed [ ] pure [ ] impure [ ] non-hygienic [ ] visual [ ] beginner-friendly [ ] non-programmer-friendly [ ] completely incomprehensible

@xplorld
xplorld / neteasemusic_comment.py
Created June 5, 2016 10:44
Get comments on netease music songs.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# forked from http://playbear.github.io/2015/09/30/net-music-comment/
import requests
import json
import os
import base64
from Crypto.Cipher import AES
@xplorld
xplorld / virtualTable.c
Created June 1, 2017 12:10
a simple virtual-table implemented polymorphism simulation in C
#include <stdio.h>
#include <stdlib.h>
struct Base;
struct Derived;
int f_Base(struct Base * b);
int f_Derived(struct Derived* d);
typedef struct {
int (*f)(struct Base *);