Skip to content

Instantly share code, notes, and snippets.

Zhang Yichao echaozh

View GitHub Profile
View stack-dsl.hs
{-# 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
View blaze-html.hs
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]
View ruby-html-dsl.rb
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 Oct 10, 2013
js code to find page data for template in harp
View page-data.js
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 Oct 10, 2013
jade template for tag page
View tag-page.jade
- 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 Oct 10, 2013
teaser extracted
View teaser.html
<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 Dec 25, 2015
teaser extraction js snippet
View teaser-extraction.js
var teaserForPost = function(name) {
var full = partial ("posts/" + name);
return full.replace (/<!-- more -->(.|\n)*/, '', 'm');
}
@echaozh
echaozh / post-example
Last active Dec 25, 2015
post example for teaser making in harp
View post-example
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:
...
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.