Skip to content

Instantly share code, notes, and snippets.

View king1600's full-sized avatar

King1600 king1600

View GitHub Profile
@king1600
king1600 / Frame.java
Created May 25, 2017 02:21
Java websocket parser
public class Frame {
public byte opcode;
public boolean fin;
public boolean masked;
public byte[] payload;
// for generating bitmask
private static final Random random = new Random();
public Frame() {
@king1600
king1600 / WebSocket.cs
Created June 18, 2017 02:52
.NET Core 1.0 Compatible (Incomplete) Implementation of WebSocket
using System;
using System.IO;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;
using System.Threading.Tasks;
namespace Protty
{
@king1600
king1600 / wsframe.c
Last active August 17, 2017 05:11
WebSocket frame parsing and dumping
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct Frame {
unsigned fin : 1; // 0 or 1 (bool) if frame fin
unsigned masked : 1; // 0 or 1 (bool) if frame masked
unsigned char opcode; // 0 - 10 (int) frame opcode
// reserved bit values
@king1600
king1600 / Makefile
Created July 3, 2017 17:29
Mini GET only HTTP Server in C
all:
gcc -g -Wall -fPIC http.c main.c -o app
@king1600
king1600 / qsort.cpp
Last active July 5, 2017 18:55
c++ quick sort algorithm
#include <algorithm>
#include <iostream>
void _QSort(int *array, int begin, int end) {
if (begin >= end) return;
int i, pivot;
pivot = begin;
for (i = begin + 1; i < end + 1; i++) {
if (array[i] <= array[begin]) {
pivot++;
@king1600
king1600 / kasm_v4.0.1.js
Last active August 8, 2017 16:50
KASM (King Assembly). My small implementation of a custom assembly like language
// Command bit flags
const KSM_FREG = 1;
const KSM_SREG = 2;
const KSM_FSYM = 4;
const KSM_SSYM = 8;
// Byte size constants
const KSM_MX_SM = 2;
const KSM_MX_CM = 8;
const KSM_VER_S = 4;
@king1600
king1600 / cbot.js
Created August 7, 2017 03:22
Cleverbot API Wrapper server
const http = require('http');
const crypto = require('crypto');
const XVIS = 'TEI939AFFIAGAYQZ';
const HOST = 'http://www.cleverbot.com';
const BASE = `${HOST}/webservicemin`;
const UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)';
class OrderedParams extends Array {
constructor(...args) {
@king1600
king1600 / cleverbot.py
Created August 17, 2017 20:53
Cleverbot public api wrapper for python3
import asyncio
from hashlib import md5
from collections import deque
from aiohttp import ClientSession
from collections import OrderedDict
from urllib.parse import quote as qs
# try to use uvloop if possible
try:
import uvloop
@king1600
king1600 / pykasm.py
Last active May 26, 2018 03:37
Python kasm v5
import string
from collections import deque
class Token:
__slots__ = ('op','args','lineno','text','next')
def __init__(self, **kwargs):
self.op = self.args = self.lineno = self.text = self.next = None
self.set(**kwargs)
def set(self, **kwargs):
@king1600
king1600 / Buffer.java
Last active October 15, 2017 13:59
Java 8 port of /discordapp/erlpack/
package com.protto.erlpack;
import java.nio.charset.Charset;
import java.util.Arrays;
public class Buffer {
private byte[] buf;
private int length;
private int alloc_size;