Skip to content

Instantly share code, notes, and snippets.

@jcfrank
jcfrank / visitor.md
Last active August 29, 2015 14:03
Visitor pattern -- my understanding

Roles

  • Visitor interface

    Defines visit methods for all types that could be visited.

  • Visitor implementations

    Defines visit behavior for different types.

@jcfrank
jcfrank / decorator.md
Last active August 29, 2015 14:03
Python decorator pattern

Desc

Unlike java, python uses nested functions to implement decorators.

This could be tricky when we first try to understand.

A few features of python are applied:

  1. python functions are objects.
@jcfrank
jcfrank / hk2-sample.md
Last active August 29, 2015 14:13
HK2 is a dependency injection framework used in Jersey 2. This pice of code demonstrate how to add custom bindings.

HK2

Jersey 2 uses HK2 as dependency injection framework.
Although there are modules for integrating with Guice or Spring.
We can still just use HK2 to avoid using two frameworks for the same purposes.
Following snippets are two very basic sample for using HK2.

Sample

@jcfrank
jcfrank / angularjs-sample.md
Last active August 29, 2015 14:13
a basic angular rest client app.

Simple Angularjs app

This is a basic rest client app, very useful for creating demo page.

Backend

First, set up node.js as interface backend.
Dependencies:

  "dependencies": {
@jcfrank
jcfrank / emberjs-sample.md
Last active August 29, 2015 14:13
A basic ember rest client sample. Useful for demo page.

Simple Emberjs app

Backend

Dependencies:

  "dependencies": {
    "jade": "*",
    "coffee-script": "*",
@jcfrank
jcfrank / flask-sample.md
Last active August 29, 2015 14:13
A flask restful api server sample.

Simple Flask app

This snippet is from an API server of another open source project.
It was written to work with webpy, but I change it to use Flask.

requirements:

flask
flask-restful
@jcfrank
jcfrank / django-sample.md
Last active August 29, 2015 14:13
A django app sample. Only to remind myself how to set up django urls and views.

Simple Django app

New a root app

$ django-admin.py startproject mysite
$ cd mysite
$ python manage.py startapp myrestapp

mysite/settings.py

@jcfrank
jcfrank / emacs-cheatsheet.md
Last active March 18, 2018 15:17
Emacs cheat sheet.

Emacs 24.3 cheat sheet

Keys Desc
C-x C-c quit
M-x kill-emacs quit without saving
C-x s Save, Promt
C-x C-s Save
C-@ Mark mode
@jcfrank
jcfrank / erlang-websocket-sample.md
Last active November 3, 2022 07:15
A simple erlang cowboy websocket app

Simple Cowboy websocket app

Cowboy is such a simple web framework.
This is a sample websocket app.

new project

Use erlang.mk. Not that you have to, but it'd make things a bit easier.
First, create a folder for project, ex. myproject.
$ cd myproject/

@jcfrank
jcfrank / jersey2-mvc-sample.md
Last active February 26, 2021 13:14
A basic Jersey 2 mvc sample with Mustache.

Jersey 2 MVC

Jersey 2 also supports server-side template rendering.
This is a simple mustache sample.

Gradle

build.gradle
Add jerset mvc dependencies.