Skip to content

Instantly share code, notes, and snippets.

View xplorld's full-sized avatar

Ruiyang Wang xplorld

View GitHub Profile
@xplorld
xplorld / Predicates.swift
Created May 13, 2016 10:16
(Pesudo-)Natural Language Predicates.
extension LazySequenceType {
public func reduceWhile<T>(
initial: T,
@noescape combine: (T, Self.Generator.Element) -> T,
@noescape criteria: (T) -> Bool
)-> T {
var generator = self.generate()
var now = initial
@xplorld
xplorld / ThoughtsOnRESTAPI.swift
Last active August 30, 2016 08:44
Thoughts On how a good REST API library should look like
//ThoughtsOnRESTAPI.swift
//Thoughts On how a good REST API library should look like
/*
object mapping : entity <-> json
can do it by reflection?
hierarchical configuration:
- auth header (for all requests)
- require status code, method verb etc (one config for each request)
- parameter and payload
@xplorld
xplorld / MyArray.cpp
Created October 9, 2016 10:39
a C++ "enhanced" array from `T[]`
template <class T>
struct MyArray {
private:
T * arr;
size_t size;
public:
using type = T;
MyArray(size_t size) :
size(size),
@xplorld
xplorld / NativeJSON.swift
Last active February 18, 2017 15:02
a JSON parser in Swift without Cocoa or Regular Expressions.
//
// main.swift
// RYJSON
//
// Created by Xplorld on 2017/2/18.
// Copyright © 2017年 xplorld. All rights reserved.
//
import Foundation
//a JSON parser
@xplorld
xplorld / StackVM.cpp
Created February 27, 2017 04:52
a simple-to-stupid stack vm
#include <iostream>
#include <stack>
//a stupid stack machine
typedef enum : int {
ADD, //0
SUB,
MUL,
DIV,
@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 *);
@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 / 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 / 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 / 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]
"""