Skip to content

Instantly share code, notes, and snippets.

from twisted.internet import reactor
from twisted.internet.protocol import Factory, Protocol
import json
class IOSChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
print "Client list: ", self.factory.clients
def connectionLost(self, reason):
- (void)readDataFromStream:(NSInputStream *)inputStream
{
while ([inputStream hasBytesAvailable]) {
// Read message length
unsigned short length;
NSInteger bytesRead = [inputStream read:(uint8_t *)&length maxLength:sizeof(unsigned short)];
if (bytesRead != sizeof(unsigned short)) {
NSLog(@"Message length bytes not read successfully.");
return;
id observer = [[NSNotificationCenter defaultCenter] addObserverForName:@"blah" object:nil queue:[[NSOperationQueue alloc] init] usingBlock:^(NSNotification *note) {
NSLog(@"%@", note.userInfo);
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}];
@implementation CustomView
@synthesize someLayer;
- (void)awakeFromNib
{
self.someLayer = [CALayer layer];
[self.layer addSublayer:self.someLayer];
self.someLayer.bounds = self.bounds;
self.someLayer.backgroundColor = [UIColor randomColor].CGColor;
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imageView];
imageView.frame = CGRectMake(self.view.frame.size.width/2 - image.size.width/2, self.view.frame.size.height/2 - image.size.height/2, image.size.width, image.size.height);
imageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
imageView.alpha = 0.5;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, imageView.frame.size.width, 100)];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
- (void)textViewDidBeginEditing:(UITextView *)textView
{
BOOL scrollToLast = self.chatTableView.contentOffset.y >= self.chatTableView.contentSize.height - self.chatTableView.frame.size.height;
[UIView animateWithDuration:0.26 animations:^{
CGRect r = self.messageContainerView.frame;
r.origin.y = self.view.frame.size.height - 216 - r.size.height;
self.messageContainerView.frame = r;
r = self.chatTableView.frame;
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[UIView animateWithDuration:0.26 animations:^{
CGRect r = self.messageContainerView.frame;
r.origin.y = self.view.frame.size.height - 216 - r.size.height;
self.messageContainerView.frame = r;
r = self.chatTableView.frame;
r.size.height = kTableViewEditingHeight;
self.chatTableView.frame = r;
error: The following untracked working tree files would be overwritten by merge:
Library/Formula/autojump.rb
Please move or remove them before you can merge.
Aborting
Updating 647eccc..1334683
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
- (void)forceDisplay
{
[self.glkView display];
}
def stringReceived(self, string):
print self.user.name, ":", string
try:
request = json.loads(string)
except BaseException as e:
print "stringReceived exception: ", e
else:
methodName = request['method']
parameters = request['parameters']
method = self.serverMethods[methodName]