Skip to content

Instantly share code, notes, and snippets.

@developerworks
developerworks / useWasm.js
Last active March 30, 2022 08:50
useWasm
// src/useWasm.js
export const useWasm = (fileName, imports) => {
const [state, setState] = useState(null);
useEffect(() => {
const fetchWasm = async () => {
const wasm = await fetch(fileName);
const instance = await AsBind.instantiate(wasm, imports);
setState(instance);
};
fetchWasm();
@developerworks
developerworks / basic.html
Created September 29, 2014 16:48
Strophe.js Client Code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Content-Language" content="zh-CN"/>
<title>Strophe.js Basic Example</title>
<script src='jquery.min.js'></script>
<script src='../strophe.js'></script>
<script src='basic.js'></script>
<script src="basic_lab.js"></script>
@developerworks
developerworks / mod_logxml.erl
Created October 15, 2014 08:55
Ejabberd module: log message,iq,presence stanza to a xml log file.
-module(mod_logxml).
-author('badlop@ono.com').
-behaviour(gen_mod).
-export([
start/2,
init/7,
stop/1,
send_packet/3,
receive_packet/4
]).

使用closure表在MySQL中管理分层关系

创建表

创建一个表示所有树节点的表.

CREATE TABLE `tree_node` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `data_body` text,

node_deleted datetime DEFAULT NULL,

var spell = {"a": "\u554a\u963f\u9515", "ai": "\u57c3\u6328\u54ce\u5509\u54c0\u7691\u764c\u853c\u77ee\u827e\u788d\u7231\u9698\u8bf6\u6371\u55f3\u55cc\u5ad2\u7477\u66a7\u7839\u953f\u972d", "an": "\u978d\u6c28\u5b89\u4ffa\u6309\u6697\u5cb8\u80fa\u6848\u8c19\u57ef\u63de\u72b4\u5eb5\u6849\u94f5\u9e4c\u9878\u9eef", "ang": "\u80ae\u6602\u76ce", "ao": "\u51f9\u6556\u71ac\u7ff1\u8884\u50b2\u5965\u61ca\u6fb3\u5773\u62d7\u55f7\u5662\u5c99\u5ed2\u9068\u5aaa\u9a9c\u8071\u87af\u93ca\u9ccc\u93d6", "ba": "\u82ad\u634c\u6252\u53ed\u5427\u7b06\u516b\u75a4\u5df4\u62d4\u8dcb\u9776\u628a\u8019\u575d\u9738\u7f62\u7238\u8307\u83dd\u8406\u636d\u5c9c\u705e\u6777\u94af\u7c91\u9c85\u9b43", "bai": "\u767d\u67cf\u767e\u6446\u4f70\u8d25\u62dc\u7a17\u859c\u63b0\u97b4", "ban": "\u6591\u73ed\u642c\u6273\u822c\u9881\u677f\u7248\u626e\u62cc\u4f34\u74e3\u534a\u529e\u7eca\u962a\u5742\u8c73\u94a3\u7622\u764d\u8228", "bang": "\u90a6\u5e2e\u6886\u699c\u8180\u7ed1\u68d2\u78c5\u868c\u9551\u508d\u8c24\u84a1\u8783", "bao": "\u82de\u80de\u5305\u8912\u9
@developerworks
developerworks / Writing Tools Writeup.markdown
Created March 12, 2018 16:26 — forked from mojavelinux/Writing Tools Writeup.markdown
How To Write A Technical Book (One Man's Modest Suggestions)
@developerworks
developerworks / index.html
Created November 7, 2017 18:10 — forked from martinsik/index.html
Simple WebSocket server based on libwebsockets. For full description read http://martinsikora.com/libwebsockets-simple-websocket-server
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
window.WebSocket = window.WebSocket || window.MozWebSocket;
var websocket = new WebSocket('ws://127.0.0.1:9000',
@developerworks
developerworks / register_jquery.min.js
Created October 3, 2014 12:42
Register user with strophe.js and strophe.register.js plugin.
/*
* jQuery 1.2.6 - New Wave Javascript
*
* Copyright (c) 2008 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008/05/26 $
* $Rev: 5685 $
*/
----------------------------------------------------------------------------------------
-- This function is used to update paths when inserted a new node
----------------------------------------------------------------------------------------
DROP FUNCTION IF EXISTS after_insert_node();
-- Step 1: Create a function used to update paths
CREATE OR REPLACE FUNCTION after_insert_node() RETURNS TRIGGER LANGUAGE PLPGSQL AS $$
BEGIN
@developerworks
developerworks / ecto_closure_table.ex
Created March 22, 2017 04:07 — forked from coryodaniel/ecto_closure_table.ex
Ecto closure table insert
defmodule CommentPath do
@moduledoc"""
Comment [closure table](http://www.slideshare.net/billkarwin/models-for-hierarchical-data).
"""
@primary_key false
schema "comment_paths" do
field :ancestor_id, Ecto.UUID
field :descendant_id, Ecto.UUID
field :depth, :integer