sh19910711's blog

By sh19910711, 5 years ago, In English,

Greetings :-)

tl;dr

https://github.com/social-snippet/social-snippet

Application Demo


0. Introduction to the Social Snippet

I'm starting a new software project, "The Social Snippet Project", to manage the snippet libraries for the online judges (e.g. watashi's library, marioyc's library and etc...). As its name implies, it's made possible to share and retrieve your snippet libraries around the world through GitHub and other hosting services.

The social snippet project provides several things:

  1. Command-line interface to use and manage the snippet libraries and its dependencies
  2. Registry system to find the snippet libraries
  3. Editor plugins to use the snippets actually (e.g. Vim, Emacs and etc...)

The mission of the project is to create the snippet system which you can use on any programming languages, any editor softwares and any operating systems.


1. How It Works

Inserting Snippet

Let's assume that we are tackling some graph shortest path problems, and then we decide to solve the problems by using find_shortest() function from our graph library. Here is a pseudo C++ program code for that:

    // solution.cpp
    #include <iostream>
    using namespace std;

    // @snip <graph-lib:algorithm/find_shortest.cpp>

    void solve(Graph graph, Vertex start, Vertex goal) {
        cout << "The Answer = " << find_shortest(graph, start, goal) << endl;
    }

The @snip / @snippet annotation tags

The social snippet specifies the snippet code by putting annotation tags on the comment line.

// @snip <graph-lib:algorithm/find_shortest.cpp>

In order to insert a snippet, we can use a @snip annotation tag. After inserting a snippet, the tagged line will be replaced by a snippet code such as follow:

    // @snippet <graph-lib:algorithm/find_shortest.cpp>
    int find_shortest(Graph graph, Vertex start, Vertex goal) {
        ... some implementation ...
    }

The @snippet annotation tag shows that the snippet code is already inserted in the program code. Finally, the first program code will be translated as the follows:

    // solution.cpp
    #include <iostream>
    using namespace std;

    // @snippet <graph-lib:algorithm/find_shortest.cpp>
    int find_shortest(Graph graph, Vertex start, Vertex goal) {
        ... some implementation ...
    }

    void solve(Graph graph, Vertex start, Vertex goal) {
        cout << "Answer  is " << find_shortest(graph, start, goal) << endl;
    }

Dependency Management

One more thing, the social snippet can resolve the dependencies among the snippets. For example, not deeply thinking, if the previous snippet depends on the dijkstra's algorithm, then a replaced snippet code will be:

    // @snippet <graph-lib:algorithm/find-min/dijkstra.cpp>
    vector<int> find_min(Graph graph, Vertex start) {
        vector<int> min_dist;
        ... some implementation ...
        return min_dist;
    }

    // @snippet <graph-lib:algorithm/find_shortest.cpp>
    int find_shortest(Graph graph, Vertex start, Vertex goal) {
        vector<int> dist = find_min(graph, start);
        return dist[goal.id];
    }

like above. The depended snippets are also inserted into the program code automatically.

Usage Example

Here is my last submission for Codeforces Round #268. I was using the social-snippet as a template code manager.

http://codeforces.com/contest/501/submission/9413315


Installation Guide

Core utilities (including command-line interfaces) are available on RubyGems.org. First, you need to install Ruby, and then type:

    $ gem install social_snippet

And next, you need to install your editor's plugin for the social snippet. In the case of social_snippet.vim (Vim plugin), you should install plugins first as follow:

    git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim

And then, write the followings to your configuration file (~/.vimrc):

    set runtimepath+=~/.vim/bundle/neobundle.vim/
    call neobundle#begin(expand('~/.vim/bundle/'))
    NeoBundle "Shougo/neocomplete.vim"
    NeoBundle "social-snippet/vim-social-snippet"
    NeoBundleCheck
    call neobundle#end()
    let g:neocomplete#enable_at_startup = 1
    let g:social_snippet#complete#enable = 1


The Command-line Interface

The sspm command is to manage the snippet libraries. It has several sub-commands. If you are finding some libraries, then you should type the below command to search:

    $ sspm search <keyword>

And if you find the expected library, then you should type the below command to install:

    $ sspm install <name>

You can view the available sub-commands by typing:

    $ sspm

or

    $ sspm --help

You can also view the usage of the sub-command by typing:

    $ sspm {sub-command} --help

2. Publish Your Libraries on the Registry System

The social snippet reigistry system is currently supported only the libraries publishing on the GitHub. If you have a GitHub repository, you can publish it by putting snippet.json file into the repository. The snippet.json's format is as follow:

    {
        "name": "your-lib-name",
        "desc": "the description",
        "languages": ["C", "C++"],
        "license": "MIT",
        "main": "path/to/src"
    }

The repository will be registered to the registry system as the name written in the snippet.json. In order to publish the repository, you should type the below command:

    $ sspm publish {The URL of repository}

For example:

    $ sspm publish git://github.com/social-snippet/example-repo

Here are the examples, please check them out:


3. Welcome Patches

Why don't you contribute this project. The project is under the terms of MIT License, and the project is still in the development phase. So welcome patches and pull-requests (Now I'm writing the documents for the developers). Feel free to contribute to the project, it's fine if you do just the ones you understand. There is a heavy context switching in the development. My hope is to focus me to a single task as possible. Help me:


Thanks

 
 
 
 
  • Vote: I like it
  • +26
  • Vote: I do not like it