Skip to content

Instantly share code, notes, and snippets.

View lqt0223's full-sized avatar

lqt0223 lqt0223

  • Shanghai, China
View GitHub Profile
@lqt0223
lqt0223 / base64.c
Created January 25, 2018 06:05
22 Base64 Encoding
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define B64_UNIT_BYTE_SIZE 3
int b64_readbytes(char* src, int count) {
int result = 0;
for (int i = 0; i < count; i++, src++) {
result += *src;
@lqt0223
lqt0223 / tiny-compiler.js
Created January 22, 2018 03:37
21 tiny-compiler
// tiny-compiler
// a coding practice based on mgechev/tiny-compiler: https://github.com/mgechev/tiny-compiler/blob/master/tiny.js
// accepting expression like 'mul 2 3'(operator prefixed) and evaluate result
// (or transpile it into normal arithmetic expression (operator in the middle))
const OPERATIONS = ['add', 'sub', 'mul', 'div']
const OP_MAP = {
add: (a, b) => a + b,
sub: (a, b) => a - b,
@lqt0223
lqt0223 / main.c
Last active February 19, 2018 00:16
21 Using FFMpeg - bootstrap code for decoding
// a very simplified FFMPEG decoding bootstrap code (without any error handling...)
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
int main(int argc, const char *argv[])
{
// register formats
av_register_all();
@lqt0223
lqt0223 / xml_parse.js
Last active May 9, 2019 03:58
20 XML parser
// A coding exercise of implementing a XML parser
// Caution: this is not a full implementation. Some features(ex. self-closing tag) are not implemented.
// Further tests need to be done
function xml_parse(xml) {
var i = 0
var ch = xml[i]
var focusedNode
function next(c) {
if (c) {
@lqt0223
lqt0223 / json_stringifier.js
Last active December 27, 2017 12:39
19 JSON stringifier
function json_stringify(json, indent) {
var str = ''
var stack_dep = 0
function getSpaces(length) {
var spaces = new Array(length)
spaces.fill(' ')
return spaces.join('')
}
@lqt0223
lqt0223 / json_parser.js
Created December 27, 2017 09:55
18 JSON parser
// This is a coding exercise of implementing a parser. Some minor parsing capabilities are not implemented.
// The algorithm are mainly from Douglas Crockford's 'https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js'
function json_parse(str) {
var i = 0
var ch = str[i]
// core function that recursively called to move forward scanning pointers and accept tokens
function next(c) {
if (c) {
@lqt0223
lqt0223 / sequence.js
Last active April 13, 2018 08:31
17 Running asynchronous jobs in sequence (without paralleling) - A Promise based implementation
// Running asynchronous jobs in sequence (without paralleling)
// A Promise based implementation
// The 'sequence' function receive an array and an iteratee as parameters.
// The iteratee is a function that returns a promise.
// You should incapsulate your desired asynchronous job in this function.
// The array is the parameters for the iteratee function in order.
// The 'sequence' function returns a promise to make it thenable.
// The promise will resolve all results of asynchronous jobs in an array,
@lqt0223
lqt0223 / navigator.md
Last active November 28, 2017 02:54
vue navigator component with view stack, main-sub stage, transition and swipe back

实现一个页面缓存、左滑返回的navigator

前言

本文将介绍如何在不使用vue-router提供的router-view的情况下,实现一个渲染路由对应组件的navigator控件,并逐步增加主副舞台区分、页面缓存、页面切换动画、左滑返回支持等功能。

本组件的源码位于我的github: https://github.com/lqt0223/navigator-demo/blob/master/src/components/Navigator.vue

本组件的demo: https://navigator-demo.herokuapp.com/#/view1 (建议在移动设备上打开(在iOS设备上使用Safari等浏览器打开时可能遇到左滑返回冲突的问题),或使用chrome dev tool,在手机模式下打开以支持触摸事件)

@lqt0223
lqt0223 / a.md
Last active November 15, 2017 14:41
vue navigator demo

A navigator component written in Vue

  • Use it with vue-router...
  • When navigating, any new view is pushed into view stack.
  • You can specify 'main' routes, whose view will not be stacked.
  • Transition is not implemented. Please use transition hook methods.

Usage example:

<template>
@lqt0223
lqt0223 / event.js
Last active June 17, 2017 05:08
Event System
function EventEmitter () {
var eventStorage = {}
this.on = function(event, handler) {
if(!eventStorage[event]) eventStorage[event] = []
eventStorage[event].push(handler)
}
this.emit = function(event) {
var events = eventStorage[event]