Skip to content

Instantly share code, notes, and snippets.

@cute
cute / ws-client.cpp
Created June 25, 2017 23:27 — forked from optman/ws-client.cpp
libevent websocket client test
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/event.h>
#include <event2/dns.h>
#include <arpa/inet.h>
#include <iostream>
using namespace std;
@cute
cute / NSNUll+ InternalNullExtention.m
Created June 20, 2017 10:39 — forked from cyndibaby905/NSNUll+ InternalNullExtention.m
NSNUll+ InternalNullExtention.m
#define NSNullObjects @[@"",@0,@{},@[]]
@interface NSNull (InternalNullExtention)
@end
@implementation NSNull (InternalNullExtention)
@cute
cute / JNWThrottledBlock.h
Created March 8, 2017 14:24 — forked from jwilling/JNWThrottledBlock.h
Simple throttling of blocks using dispatch sources.
#import <Foundation/Foundation.h>
@interface JNWThrottledBlock : NSObject
// Runs the block after the buffer time _only_ if another call with the same identifier is not received
// within the buffer time. If a new call is received within that time period the buffer will be reset.
// The block will be run on the main queue.
//
// Identifier and block must not be nil.
+ (void)runBlock:(void (^)())block withIdentifier:(NSString *)identifier throttle:(CFTimeInterval)bufferTime;
@cute
cute / socket_hack.md
Created December 10, 2016 09:36 — forked from natevw/socket_hack.md
Simple TCP multiplexing protocol

TCP multiplexing protocol

A high-level approach to multiplexing multiple TCP connections over a single socket. Probably ignores a lot of queueing theory.

Background

The CC3000 WiFi chip may be especially unreliable if more than one socket is in use. So the idea is to maintain a single connection with a proxy server, which will handle the actual simultaneous outbound connections on a client's behalf. (Inbound connections are lower implementation priority.)

Terminology

@cute
cute / ssd.c
Created December 8, 2016 10:06 — forked from rodionovd/ssd.c
ssd -- Socket Server demo by Apple
// Copyright (C) 2010 Apple Inc. All Rights Reserved.
#include <launch.h>
#include <libkern/OSAtomic.h>
#include <vproc.h>
#include "shared.h"
static bool g_is_managed = false;
static bool g_accepting_requests = true;
static dispatch_source_t g_timer_source = NULL;
@cute
cute / README.md
Created September 10, 2016 07:46 — forked from bomberstudios/README.md
Loading a Cocoa Framework in a Sketch Plugin

This is what Craft does:

function loadFramework(pluginRoot) {
  if (NSClassFromString('PanelsManager') == null) {
    var mocha = [Mocha sharedRuntime];
    return [mocha loadFrameworkWithName:'Panels' inDirectory:pluginRoot];
  } else {
    return true;
 }
@cute
cute / libevent.podspec
Created August 25, 2016 03:52 — forked from dpassage/libevent.podspec
podspec for libevent
Pod::Spec.new do |s|
s.name = "libevent"
s.version = "2.1.5-beta"
s.summary = "An event notification library."
s.description = <<-DESC
The libevent API provides a mechanism to execute a callback function when a
specific event occurs on a file descriptor or after a timeout has been reached.
@cute
cute / async_dns.c
Created August 21, 2016 08:09 — forked from mopemope/async_dns.c
c-ares example
#include <ares.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@cute
cute / ss-install.md
Created May 3, 2016 08:31 — forked from aa65535/ss-install.md
shadowsocks-libev install at Debian or CentOS

Debian

cd /tmp
# 下载源码
git clone https://github.com/shadowsocks/shadowsocks-libev.git
# 开始编译
cd shadowsocks-libev
./autogen.sh
./configure --prefix=/usr && make
make install