This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Hackity hack hack. | |
Don't judge me for this. | |
Clearly, this is for testing purposes only. | |
./gcc test.c -o test -lusb-1.0 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates the Directory Tree | |
* | |
* @class MODx.tree.Directory | |
* @extends MODx.tree.Tree | |
* @param {Object} config An object of options. | |
* @xtype modx-tree-directory | |
*/ | |
MODx.tree.Directory = function (config) { | |
config = config || {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ws = new WebSocketServer(); | |
$ws->bind("0.0.0.0", "8080"); | |
$ws->onopen = function($client) { | |
echo "New connection: " . $client->sockfd . "\n"; | |
}; | |
$ws->onclose = function($client) { | |
echo "Closing connection: " . $client->sockfd . "\n"; | |
}; | |
$ws->onmessage = function($client, $msg) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
onmessage(libwebsock_client_state *state, libwebsock_message *msg) | |
{ | |
//my message is in msg->payload | |
//let's send received message to all clients | |
return libwebsock_send_all_text(state->ctx, msg->payload); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
onmessage(libwebsock_client_state *state, libwebsock_message *msg) | |
{ | |
unsigned int count = 0; | |
unsigned int len = strlen(msg->payload); | |
libwebsock_client_state *current; | |
for (current = state->ctx->clients_HEAD; current != NULL; current = current->next) { | |
libwebsock_send_fragment(current, msg->payload, len, WS_FRAGMENT_FIN | WS_OPCODE_TEXT); | |
count++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct _sapi_module_struct { | |
char *name; | |
char *pretty_name; | |
int (*startup)(struct _sapi_module_struct *sapi_module); | |
int (*shutdown)(struct _sapi_module_struct *sapi_module); | |
int (*activate)(TSRMLS_D); | |
int (*deactivate)(TSRMLS_D); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import libwebsock | |
def ws_onopen(client): | |
print "New connection from {0}".format(client.sock) | |
def ws_onclose(client) | |
print "Connection closed: {0}".format(client.sock) | |
def ws_onmessage(client, msg): | |
print "Received message from client ({0}): {1}".format(client.sock, msg.payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How I want my websocket PHP extension to work: | |
(Something like this) | |
<?php | |
set_time_limit(0); //maybe do this inside extension, if possible? | |
$ws = new WebSocket("3333"); | |
$ws->set_receive_callback(function($state, $msg) { | |
WebSocket::sendText($state->sockfd, $msg->text); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _get_contact_info($contact_id) { | |
//check local process cache first | |
if (!isset($this->_contact_info_cache[$contact_id])) { | |
$memcache_key = "contact_info_cache_" . $contact_id; | |
$memcache_res = $this->cache->get($memcache_key); | |
//then check memcache | |
if ($memcache_res) { | |
$this->_contact_info_cache[$contact_id] = json_decode($memcache_res, true); | |
} else { | |
//fall back to DB retrieval and store in both memcache and local process cache. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _set_item_in_memcache($type, $id, $obj) { | |
$mc_key = "cache_{$type}_{$id}"; | |
$this->cache->set($mc_key, json_encode($obj)); | |
} | |
protected function _populate_item_from_memcache($type, $id) { | |
$mc_key = "cache_{$type}_{$id}"; | |
$rv = $this->cache->get($mc_key); | |
if ($rv === false) return; | |
$this->_caches[$type][$id] = json_decode($rv, true); |
NewerOlder