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
static NSString* getIPAddress() { | |
id myhost =[NSClassFromString(@"NSHost") performSelector:@selector(currentHost)]; | |
if (myhost) { | |
for (NSString* address in [myhost performSelector:@selector(addresses)]) { | |
if ([address rangeOfString:@"::"].location == NSNotFound) { | |
return address; | |
} | |
} | |
} | |
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
NSPredicate *predicate = [NSPredicate predicateWithBlock:^(id evaluatedObject, NSDictionary *bindings) { | |
return ([[NSDate dateWithTimeIntervalSince1970:[[evaluatedObject timestamp] doubleValue] timeIntervalSinceDate:oldDate] < 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
function bytesToSize(bytes) | |
{ | |
if (bytes == 0) | |
{ | |
return "0 Byte"; | |
} | |
local k = 1000; | |
local sizes = ["Bytes", "KB", "MB", "GB", "TB"]; | |
local i = math.floor(math.log(bytes) / math.log(k)); | |
return math.abs(bytes / math.pow(k, i)) + "" + sizes[i]; |
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
// create an ImpLcd instance. Our LCD is connected to I2C on ports 8,9 with a base address of 0x27 | |
lcd <- ImpLcd(hardware.i2c89, 0x27, 2, 0); | |
function updateClock() | |
{ | |
local t = date(); | |
// move to the first row, first column | |
lcd.setCursor(0, 0); | |
lcd.writeString(format("%02d:%02d:%02d", t.hour, t.min, t.sec)); |
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 <ifaddrs.h> | |
#include <arpa/inet.h> | |
- (NSString *)getIPAddress { | |
NSString *address = @"error"; | |
struct ifaddrs *interfaces = NULL; | |
struct ifaddrs *temp_addr = NULL; | |
int success = 0; | |
// retrieve the current interfaces - returns 0 on success |
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
private function renderTimeOfDay($user){ | |
$now = DateTime::now(); | |
$now->timezone($user['timezone']); // convert to user's timezone | |
$hour = $now->time()->hour(); | |
$result = 'night'; | |
if($hour > 3 && $hour < 12){ | |
$result = 'morning'; | |
}elseif($hour < 17){ | |
$result = 'afternoon'; | |
}elseif($hour < 22){ |
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
- (UIDeviceFamily) deviceFamily | |
{ | |
NSString *platform = [self platform]; | |
if ([platform hasPrefix:@"iPhone"]) return UIDeviceFamilyiPhone; | |
if ([platform hasPrefix:@"iPod"]) return UIDeviceFamilyiPod; | |
if ([platform hasPrefix:@"iPad"]) return UIDeviceFamilyiPad; | |
if ([platform hasPrefix:@"AppleTV"]) return UIDeviceFamilyAppleTV; | |
return UIDeviceFamilyUnknown; | |
} |
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 *)getTimeOfDay | |
{ | |
// By: Eddie Espinal | |
// morning 5AM-11:59AM | |
// Noon 12PM-1PM | |
// afternoon 1PM-5:59PM | |
// evening 6PM-8:30PM | |
// Night 8:30PM-11:59PM | |
// Midnight 12AM | |
// late night 12AM-4AM |
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
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] |
OlderNewer