Skip to content

Instantly share code, notes, and snippets.

#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
- (void)broadCast
{
int socketSD = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (socketSD <= 0) {
NSLog(@"Error: Could not open socket.");
@cbess
cbess / gist:6303604
Last active April 1, 2016 16:59
Fix iOS [sizeWithFont:constrainedToSize:lineBreakMode:] deprecation warning. Adjusts the label height (top align text).
// adjust the label height (top align text)
// old
CGSize labelSize = [model.name sizeWithFont:self.nameLabel.font
constrainedToSize:_maxNameLabelSize
lineBreakMode:self.nameLabel.lineBreakMode];
// new
CGSize labelSize = [model.name boundingRectWithSize:_maxNameLabelSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName: self.nameLabel.font}
context:nil].size;
@kaochenlong
kaochenlong / gist:1889703
Created February 23, 2012 03:05
台灣公司統一編號判斷規則
# encoding: utf-8
def company_serial_no_checker(serial)
# 共八位,全部為數字型態
at_least_8_digits = /^\d{8}$/
return false unless at_least_8_digits.match(serial)
# 各數字分別乘以 1,2,1,2,1,2,4,1
# 例:統一編號為 53212539
@Jaybles
Jaybles / UIDeviceHardware.h
Created October 28, 2011 19:33
UIDeviceHardware - Determine iOS device being used
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
@interface UIDeviceHardware : NSObject
- (NSString *) platform;