Skip to content

Instantly share code, notes, and snippets.

Payden Sutherland payden

Block or report user

Report or block payden

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@payden
payden / thing.php
Created Jul 15, 2014
Yet another thing
View thing.php
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);
@payden
payden / thing.php
Created Jul 15, 2014
2 layer caching.
View thing.php
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.
View learning.m
//
// OBFViewController.m
// Cryptsy Balance
//
// Created by Payden Sutherland on 3/9/14.
// Copyright (c) 2014 Payden Sutherland. All rights reserved.
//
#import "OBFViewController.h"
#import "CommonCrypto/CommonDigest.h"
@payden
payden / validity.c
Created Dec 31, 2013
Validity Sensors 138a:0050 testing code
View validity.c
/*
Hackity hack hack.
Don't judge me for this.
Clearly, this is for testing purposes only.
./gcc test.c -o test -lusb-1.0
*/
View modxhacks.js
/**
* 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 || {};
View onmessage-callback2.c
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++;
}
View onmessage-callback.c
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);
}
View sapi_struct.c
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);
@payden
payden / php-ws.php
Last active Dec 29, 2015
php-ws example
View php-ws.php
<?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) {
@payden
payden / gist:4553917
Created Jan 17, 2013
libwebsock-python gist
View gist:4553917
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)
You can’t perform that action at this time.