Skip to content

Instantly share code, notes, and snippets.

View echaozh's full-sized avatar

Zhang Yichao echaozh

View GitHub Profile
{-# LANGUAGE PackageImports, UnicodeSyntax #-}
import "mtl" Control.Monad.State
type Stack a b = State [a] b
push a Stack a ()
push a = modify (a:)
pop Stack a a
page1 :: Markup
page1 = html $ do
head $ do
title "Introduction page."
link ! rel "stylesheet" ! type_ "text/css" ! href "screen.css"
body $ do
div ! id "header" $ "Syntax"
p "This is an example of BlazeMarkup syntax."
ul $ mapM_ (li . toMarkup . show) [1, 2, 3]
html = Arbre::Context.new do
h2 "Why Arbre is awesome?"
ul do
li "The DOM is implemented in ruby"
li "You can create object oriented views"
li "Templates suck"
end
end
@echaozh
echaozh / page-data.js
Created October 10, 2013 11:48
js code to find page data for template in harp
var page = (function (cur) {
var data = public;
for (var i = 0; i < cur.path.length - 1; ++i) {
data = data[cur.path[i]];
}
data = data.data[cur.path[cur.path.length - 1]];
return data;
}) (current);
@echaozh
echaozh / tag-page.jade
Created October 10, 2013 11:47
jade template for tag page
- var tagsForPosts = function() {
- var data = public.posts.data;
- var tags = {};
- for (var name in data) {
- if (name[0] != '_') {
- var ts = data[name].tags;
- for (var i in ts) {
- tag = ts[i];
- tags[tag] = tags[tag] || []
- tags[tag].push (name);
@echaozh
echaozh / teaser.html
Created October 10, 2013 11:40
teaser extracted
<p>The <a href="https://github.com/echaozh/python-dbtxn">python-dbtxn</a> is a library I wrote to ease db accessing from Python programs. Directly calling Python DBI leaves a lot of boilerplate code all over the place, and boilerplate code is bad. I googled, and there are no dbtxn like libraries, so I wrote my own.</p>
@echaozh
echaozh / teaser-extraction.js
Last active December 25, 2015 04:28
teaser extraction js snippet
var teaserForPost = function(name) {
var full = partial ("posts/" + name);
return full.replace (/<!-- more -->(.|\n)*/, '', 'm');
}
@echaozh
echaozh / post-example
Last active December 25, 2015 04:19
post example for teaser making in harp
The [python-dbtxn](https://github.com/echaozh/python-dbtxn) is a library I wrote to ease db accessing from Python programs. Directly calling Python DBI leaves a lot of boilerplate code all over the place, and boilerplate code is bad. I googled, and there are no dbtxn like libraries, so I wrote my own.
<!-- more -->
There are 2 sources of boilerplate code:
...