Skip to content

Instantly share code, notes, and snippets.

View Kentzo's full-sized avatar
🤖

Ilya Kulakov Kentzo

🤖
  • San Francisco, CA
View GitHub Profile
{
NSString *httpBodyString = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\
<soap:Body>\
<CheckCustomer xmlns=\"http://tempuri.org/\">\
<ABN>%@</ABN>\
</CheckCustomer>\
</soap:Body>\
</soap:Envelope>", _lastScannedCustomer.ABN];
NSData *httpBodyData = [httpBodyString dataUsingEncoding:NSUnicodeStringEncoding];
DDXMLDocument *document = [[DDXMLDocument alloc] initWithData:_connectionData options:0 error:NULL];
DDXMLElement *rootElement = [document rootElement];
[document release];
NSUInteger statusCode = [_response statusCode];
if (statusCode >= 200 && statusCode < 400) {
NSString *xpath = @"/soap:Envelope/soap:Body/myns:CheckCustomerResponse/myns:CheckCustomerResult";
NSArray *elements = [rootElement nodesForXPath:xpath error:&error]; // array of DDXMLElements. See DDXMLElement.h and DDXMLElementAdditions.h
}
@Kentzo
Kentzo / OpenCLInfo.py
Created December 8, 2010 09:31
Print OpenCL info for current machine
import pyopencl as cl
def PrintDeviceInfo(device):
print "Name: %s" % device.name
print "OpenCL version: %s" % device.version
print "Global memory size: %.2f Megabytes" % (device.global_mem_size/1024/1024)
print "Local memory size: %.2f Kilobytes" % (device.local_mem_size/1024)
print "Max constant buffer size: %.2f Kilobytes" % (device.max_constant_buffer_size/1024)
print "Max clock frequency: %i Hz" % device.max_clock_frequency
print "Max compute units: %i" % device.max_compute_units
@Kentzo
Kentzo / Vectorial magic.
Created March 13, 2011 17:26
Right shift for int4
__device__ int4 right_shift_int4(int4 a_value, unsigned int a_num)
{
int x_h = a_value.x >> (a_num % 32);
int x_l = a_value.x << (32 - (a_num %32));
int y_h = a_value.y >> (a_num % 32);
int y_l = a_value.y << (32 - (a_num % 32));
int z_h = a_value.z >> (a_num % 32);
int z_l = a_value.z << (32 - (a_num % 32));
@Kentzo
Kentzo / gist:1064337
Created July 5, 2011 06:19
NSMutableArray isn't thread safe anymore
NSMutableArray *resources = [NSMutableArray new];
[otherObjects enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
id resource = [obj hardToCalcResource];
@synchronized(resources) {
[resources addObject:resource]; // Resources may be corrupted
}
}];
@Kentzo
Kentzo / gist:1116722
Created July 31, 2011 11:39
How to use NSCache right.
NSCache cache = [[NSCache alloc] init];
/*
...
*/
// WRONG
id o = [cache objectForKey:ObjectKey];
if (o == nil)
{
@Kentzo
Kentzo / AppKit.md
Created August 10, 2011 13:39
Hints for a Mac OS X Developer
@Kentzo
Kentzo / gist:1188869
Created September 2, 2011 15:08
-[CATextLayer drawInContext:]
;return address *(long*)$esp
;first parameter $rdi
;second parameter $rsi
;third parameter $rdx
;fourth parameter $rcx
;fifth parameter $r8
;sixth parameter $r9
@Kentzo
Kentzo / gist:1306484
Created October 22, 2011 20:55
Фантастический костыль для мапа между мониторами с разным PPI
- (NSRect)scaleWindowFrame:(NSRect)aFrame toView:(NSView *)aView
{
NSScreen *windowScreen = [self preferredScreen];
NSScreen *viewScreen = [[aView window] screen];
if (windowScreen == nil || viewScreen == nil)
return NSZeroRect;
NSRect screenFrameInViewCoordinates = [windowScreen visibleFrame];
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_6)
@Kentzo
Kentzo / gist:1515314
Created December 23, 2011 20:44
How to create Floppy Disk Image on Mac OS X for MS-DOS in vmware fusion
1. In terminal use "dd if=/dev/zero of=myfloppy.img bs=1024 count=1440" to create file with appropriate size
2. Attach a floppy device in VM setting. Select myfloppy.img
3. Use the "format a:" command to format disk