Skip to content

Instantly share code, notes, and snippets.

View networkextension's full-sized avatar
🎯
Focusing

abigt networkextension

🎯
Focusing
View GitHub Profile
@networkextension
networkextension / CCCryptorGCM.c
Created March 16, 2017 06:23
CCCryptorGCM in commoncrypto
CCCryptorStatus CCCryptorGCM(CCOperation op, /* kCCEncrypt, kCCDecrypt */
CCAlgorithm alg,
const void *key, size_t keyLength, /* raw key material */
const void *iv, size_t ivLen,
const void *aData, size_t aDataLen,
const void *dataIn, size_t dataInLength,
void *dataOut,
void *tagOut, size_t *tagLength)
{
@networkextension
networkextension / kqueue.c
Last active March 23, 2017 13:50
kqueue.c
//
// main.c
// kq
#include <stdio.h>
/* echo.c - Simple `echo' server for N clients written using kqueue/kevent. */
@networkextension
networkextension / tcp-non-blocking-echo-server.c
Created March 23, 2017 13:51
tcp-non-blocking-echo-server.c
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/event.h>
protocol ValueType {
init()
}
extension UInt8:ValueType {}
extension Int8:ValueType {}
extension UInt16:ValueType {}
extension Int16:ValueType {}
extension UInt32:ValueType {}
extension Int32:ValueType {}
func testsnappy(){
let st = "sdlfjlsadfjalsdjfalsdfjlasf".data(using: .utf8)!
let count:UnsafeMutablePointer<Int> = UnsafeMutablePointer<Int>.allocate(capacity: 1)
count.pointee = snappy_max_compressed_length(st.count)
let out:UnsafeMutablePointer<Int8> = UnsafeMutablePointer<Int8>.allocate(capacity: count.pointee)
defer {
out.deallocate(capacity: count.pointee)
@networkextension
networkextension / Named Entity Recognition.swift
Created June 8, 2017 06:31
Named Entity Recognition WWDC17
import Foundation
// In this example, we'll use `[.nameType]` as `tagSchemes` to create a `tagger` of Named Entities.
let tagger = NSLinguisticTagger(tagSchemes: [.nameType], options: 0)
var text1 = """
On Monday, June 5, Apple handed out its annual Apple Design Awards, which celebrate the talent, artistry and creativity of developers who set the standard for ideal app design.
Now in its 20th year, the Awards recognize excellence in design, innovation and technology in apps and games across iPhone, iPad, Mac, Apple Watch and Apple TV. This year’s honorees represent eight countries around the world: Austria, Canada, Germany, Israel, Italy, Singapore, Slovenia and the US.
"""
// Set the string the tagger will tag.
@networkextension
networkextension / TextDetection.m
Created June 9, 2017 06:54 — forked from Koze/TextDetection.m
Text Detection with Vision Framework
- (void)detectWithImageURL:(NSURL *)URL
{
VNImageRequestHandler *handler = [[VNImageRequestHandler alloc] initWithURL:URL options:@{}];
VNDetectTextRectanglesRequest *request = [[VNDetectTextRectanglesRequest alloc] initWithCompletionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
}
else {
for (VNTextObservation *textObservation in request.results) {
// NSLog(@"%@", textObservation);
@networkextension
networkextension / HorizonDetection.m
Created June 12, 2017 01:47 — forked from Koze/HorizonDetection.m
Horizon Detection with Vision Framework
- (void)correctAngleWithImage:(UIImage *)image
{
VNImageRequestHandler *handler = [[VNImageRequestHandler alloc] initWithCGImage:image.CGImage options:@{}];
VNDetectHorizonRequest *request = [[VNDetectHorizonRequest alloc] initWithCompletionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
}
else {
NSAssert(request.results.count > 0, @"No Results");
@networkextension
networkextension / wormdump.c
Created August 21, 2017 14:36 — forked from comex/wormdump.c
Some old broken code in case it helps anyone
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/kern_event.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <net/ethernet.h>
*** Panic Report ***
panic(cpu 0 caller 0xffffff80029ff3dd): Kernel trap at 0xffffff800290f4a4, type 13=general protection, registers:
CR0: 0x0000000080010033, CR2: 0x000000010747227d, CR3: 0x0000000a2573c03d, CR4: 0x00000000003627e0
RAX: 0x00000000cce499e4, RBX: 0x000000003b9aca00, RCX: 0x0000000000000000, RDX: 0x00000001087f63e4
RSP: 0xffffff9499083ed0, RBP: 0xffffff9499083ed0, RSI: 0x0000000000000000, RDI: 0xffffff805ede4f20
R8: 0xffffff8002d82aa0, R9: 0x0000000000000000, R10: 0x0000000000000001, R11: 0x0000000000000202
R12: 0x0000000000000000, R13: 0xffffff806127fcc0, R14: 0xffffff8002d82aa0, R15: 0xffffff805ede4f20
RFL: 0x0000000000010246, RIP: 0xffffff800290f4a4, CS: 0x0000000000000008, SS: 0x0000000000000010
Fault CR2: 0x000000010747227d, Error code: 0x0000000000000000, Fault CPU: 0x0, PL: 0, VF: 0