Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import argparse
import math
import tkinter as tk
import tkinter.messagebox as tk_messagebox
import PIL.ImageTk
import PIL.Image
import numpy as np
[user]
name = Anton Barkovsky
email = anton@swarmer.me
[github]
user = swarmer
[core]
autocrlf = input
editor = vim
[alias]
lg = log --graph --all
@swarmer
swarmer / rfc.md
Last active April 17, 2016 14:25

Chat Prototol

Connection

Clients MUST establish a TCP connection with a server and communicate with text messages.

All text MUST be encoded as UTF-8 for network transmission.

Server MAY use any name for clients that have not specified one.

Clients and servers MAY do anything, including dropping the connection, after recieving a badly formed according to this RFC message.

@swarmer
swarmer / client.c
Created March 7, 2016 00:55
Server example code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
[super viewDidLoad];
// Do any additional setup after loading the view.
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [delegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Record" inManagedObjectContext: context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity: entityDescription];
NSPredicate *pred = [NSPredicate predicateWithFormat: @"cityFrom == %@ AND cityTo == %@", self.fromCity, self.toCity];
void allow_everyone_attrs2(SECURITY_ATTRIBUTES *pattrs)
{
PSECURITY_DESCRIPTOR psd;
SECURITY_ATTRIBUTES &SA = *pattrs;
TCHAR szStringSecurityDis2[512] = TEXT("");
_tcscat(szStringSecurityDis2, TEXT("D:(A;;GA;;;WD)(A;;GA;;;AN)"));
pyplot.plot(*zip(*enumerate(errors_jacobi)), marker='o', label='Jacobi', color='r')
pyplot.plot(*zip(*enumerate(errors_seidel)), marker='o', label='Gauss-Seidel', color='b')
pyplot.legend(loc='upper right')
pyplot.yscale('log')
pyplot.show()
def find_primitive_root(p):
phi = p - 1
factors = km3.rho_find_all_factors(phi)
test_powers = [phi // factor for factor in factors]
for a in itertools.count(2):
for power in test_powers:
if pow(a, power, p) == 1:
break
else:
#include "sync.hpp"
// Lock
Lock::Lock()
{
InitializeCriticalSection(&section);
}
Lock::~Lock()
def devour(path):
with open(path, 'rb') as infile:
return infile.read(LIMIT)
def get_bits(bs):
bits = []
for byte in bs:
for i in range(8):
bits.append(byte & 1)
byte >>= 1