This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); // dgram is UDP | |
// Listen for responses | |
function listen(port) { | |
var server = dgram.createSocket("udp4"); | |
server.on("message", function (msg, rinfo) { | |
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
minissdpdSocket = '/var/run/minissdpd.sock' # The socket for talking to minissdpd | |
# Sends a message to the given socket | |
def sendMessage(message): | |
s = socket.socket(socket.AF_UNIX) | |
s.settimeout(1) # 1 second timeout, after all it should be instant because its local | |
s.connect(minissdpdSocket) | |
s.send(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <netinet/in.h> | |
#include <sys/socket.h> | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
- (void)sendBroadcastPacket { | |
// Open a socket | |
int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | |
if (sd<=0) { | |
NSLog(@"Error: Could not open socket"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)radialGradientImage:(CGSize)size start:(float)start end:(float)end centre:(CGPoint)centre radius:(float)radius { | |
// Render a radial background | |
// http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html | |
// Initialise | |
UIGraphicsBeginImageContextWithOptions(size, YES, 1); | |
// Create the gradient's colours | |
size_t num_locations = 2; | |
CGFloat locations[2] = { 0.0, 1.0 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(NSString*)urlEscape:(NSString *)unencodedString { | |
NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, | |
(CFStringRef)unencodedString, | |
NULL, | |
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", | |
kCFStringEncodingUTF8); | |
return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it | |
} | |
// Put a query string onto the end of a url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface SizableImageCell : UITableViewCell {} | |
@end | |
@implementation SizableImageCell | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
float desiredWidth = 80; | |
float w=self.imageView.frame.size.width; | |
if (w>desiredWidth) { | |
float widthSub = w - desiredWidth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 9999)]; | |
myLabel.lineBreakMode = UILineBreakModeWordWrap; | |
myLabel.numberOfLines = 0; | |
myLabel.text = @"Some \n dynamic \n multiline \n text"; | |
[myLabel sizeToFit]; // This shrinks the 9999 down to the size of the text | |
NSLog(@"Actual height is: %f", myLabel.frame.size.height); // Use this for spacing any further elements | |
[self.view addSubview:title]; // Or add it to a scroll view, or whatever... | |
[myLabel release]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { | |
UILabel *lbl = [[[UILabel alloc] init] autorelease]; | |
lbl.textAlignment = UITextAlignmentCenter; | |
lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:18]; | |
lbl.text = @"My Centered Header"; | |
lbl.textColor = [UIColor whiteColor]; | |
lbl.shadowColor = [UIColor grayColor]; | |
lbl.shadowOffset = CGSizeMake(0,1); | |
lbl.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"my_head_bg"]]; | |
lbl.alpha = 0.9; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)swipeLeft { | |
NSLog(@"Left!"); | |
} | |
- (void)swipeRight { | |
NSLog(@"Right!"); | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using grand central dispatch (GCD) so we don't block the GUI | |
dispatch_async(dispatch_get_global_queue(0, 0), ^{ | |
// Background, long stuff runs here, but doesn't affect the GUI | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// The GUI thread stuff goes here | |
[self.tableView reloadData]; // example | |
OlderNewer