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 / 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 / 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
----------------------------------------------------------------------------------------
-- 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 / ranch_test.txt
Created September 23, 2016 08:19
ranch_test
➜ tmp git clone https://github.com/jekens/ranch_test.git
Cloning into 'ranch_test'...
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 21 (delta 2), reused 21 (delta 2), pack-reused 0
Unpacking objects: 100% (21/21), done.
Checking connectivity... done.
➜ tmp cd ranch_test
ubuntu:~/systemtap/systemtap-3.0/testsuite/systemtap.examples/network$ sudo stap -vv /home/ycc/systemtap/systemtap-3.0/testsuite/systemtap.examples/network/nettop.stp
Systemtap translator/driver (version 3.0/0.166, non-git sources)
Copyright (C) 2005-2015 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: NLS TR1_UNORDERED_MAP
Created temporary directory "/tmp/stapZuz725"
Session arch: x86_64 release: 4.2.0-36-generic
Kernel symbol table /lib/modules/4.2.0-36-generic/build/System.map unavailable, (No such file or directory)
Searched for library macro files: "/usr/local/share/systemtap/tapset/linux/*.stpm", found: 5, processed: 5
Searched for library macro files: "/usr/local/share/systemtap/tapset/*.stpm", found: 8, processed: 8
> build with kerl configurre option is:
> KERL_CONFIGURE_OPTIONS="--disable-native-libs --enable-vm-probes --with-dynamic-trace=systemtap --with-ssl=/usr/local --enable-hipe --enable-kernel-poll --without-odbc --enable-threads --enable-sctp --enable-smp-support --enable-sharez-zlib --enable-dynamic-ssl-lib"
> When i list the probes about erlang, the result is ok
```
ubuntu@ubuntu:~/systemtap$ stap -L 'process("/home/ubuntu/.kerl/builds/18.3_dtrace/release_18.3/erts-7.3/bin/beam.smp").mark("*")' |grep message
process("/home/ubuntu/.kerl/builds/18.3_dtrace/release_18.3/erts-7.3/bin/beam.smp").mark("message__queued") $arg1:long $arg2:long $arg3:long $arg4:long $arg5:long $arg6:long
process("/home/ubuntu/.kerl/builds/18.3_dtrace/release_18.3/erts-7.3/bin/beam.smp").mark("message__receive") $arg1:long $arg2:long $arg3:long $arg4:long $arg5:long $arg6:long
%% Author: Alex Radetsky <rad@pearlpbx.com>
%% Module: Simple SMPP Server on Erlang, gen_fsm, ranch, smpp34pdu.
%% It always authorize bind_transceiver and receives submit_sm
-module(smpp_protocol).
-behaviour(gen_fsm).
-behaviour(ranch_protocol).
-include_lib("smpp34pdu/include/smpp34pdu.hrl").
@developerworks
developerworks / migration.py
Created April 27, 2016 08:42 — forked from lucperkins/migration.py
Migrate SQL table to Riak
import psycopg2
from riak import RiakClient, RiakObject
from riak.datatypes import Set
import datetime
# Riak connection and set
client = RiakClient(pb_port=8087)
SETS_BUCKET = client.bucket_type('sets').bucket('key_sets')
# Get columns for table