Skip to content

Instantly share code, notes, and snippets.

View lujjjh's full-sized avatar

Jiahao Lu lujjjh

  • Shanghai, China
  • 21:02 (UTC +08:00)
View GitHub Profile
@lujjjh
lujjjh / main.py
Created May 24, 2021 04:33
Binary search
#!/usr/bin/env python3
import string
import random
from hashlib import md5
import struct
import sys
from bisect import bisect_left
import time
@lujjjh
lujjjh / html.coffee
Last active April 8, 2021 08:31
An HTML DSL in CoffeeScript
scope = []
enter = ->
scope.push([])
scope[scope.length - 1]
leave = ->
scope.pop()
scope[scope.length - 1]
package main
import (
"fmt"
"github.com/sergi/go-diff/diffmatchpatch"
)
const (
src = "Hello world!"
@lujjjh
lujjjh / template.js
Last active January 16, 2017 13:52
Another template "engine" for JavaScript
function compile(template) {
function expandFilter(expr) { return expr.replace(/^(.+?)(?:|(\|[^()]+))?$/, function ($0, expr, filters) {
if (!filters) return expr;
filters = filters.split(/\s*\|\s*/g).reverse();
return filters.join('(') + '(' + expr + filters.map(function () { return ')'; }).join('');
}); }
return new Function(
'with(this){with(arguments[0]){var out="' +
template.replace(/\\([@{}\\])|\{\{\s*([^]+?)\s*\}\}|^\s*@\s*(.+)|([^])/gm,
function ($0, escaped, expr, stat, ch) {