Skip to content

Instantly share code, notes, and snippets.

View chancyWu's full-sized avatar
🎯
Focusing

ChangXi Wu chancyWu

🎯
Focusing
  • thales solutions asia pte ltd
  • Singapore
View GitHub Profile
@chancyWu
chancyWu / HandlerUsage
Created July 3, 2014 03:51
use Handler to execute the function repeatedly & stop in Android
private boolean keepLooping = true;
private static final int DELAY = 1000 * 5;
final Handler printHandler = new Handler();
Runnable printStuff = new Runnable(){
@Override
public void run(){
System.out.println("done");
if(keepLooping)
printHandler.postDelayed(this, DELAY);
@chancyWu
chancyWu / Forward Touches and Gestures to Views from UIScrollView
Last active August 29, 2015 14:02
Forward Touches and Gestures to Views from UIScrollView
// in your subclass of UIScrollView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging) {
[self.nextResponder touchesBegan:touches withEvent:event];
}
else {
[super touchesBegan:touches withEvent:event];
}
@chancyWu
chancyWu / gist:46c0c8fd19550a1e7343
Last active August 29, 2015 14:02
NSLocale usage
NSLocale *lcl = [[NSLocale alloc] initWithLocaleIdentifier:@"en_SG"];
NSNumberFormatter *fmtr = [[NSNumberFormatter alloc] init];
[fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];
[fmtr setLocale:lcl];
NSLog(@"Current Locale: %@", [NSLocale currentLocale]);
NSLog(@"Available Locales: %@",[NSLocale availableLocaleIdentifiers]);
NSLog( @"%@", [lcl displayNameForKey:NSLocaleCurrencySymbol value:@"en_SG"] );
NSLog( @"%@", [fmtr currencySymbol] );
NSLog(@"CurrencyCode: %@", [lcl objectForKey:NSLocaleCurrencyCode]);
iPhone iOS 5,6 Spotlight
iOS 5-7 Settings
1x 2x
29pt 58pt
iOS 7 Spotlight
2x
80pt
iOS 5,6 App
@chancyWu
chancyWu / iOS exit app friendly
Created February 12, 2014 09:07
iOS exit app friendly code snippet
- (IBAction)logOutButton:(id)sender
{
//show confirmation message to user
CustomAlert* alert = [[CustomAlert alloc] initWithTitle:@"Confirmation" message:@"Do you want to exit?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
alert.style = AlertStyleWhite;
[alert setFontName:@"Helvetica" fontColor:[UIColor blackColor] fontShadowColor:[UIColor clearColor]];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 200, 200) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = CGRectMake(0, 0, 200, 200);
maskLayer.path = maskPath.CGPath;
self.imageView.layer.mask = maskLayer;
- (void)showAlert:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:0.5];
}
- (void)dismissAlert:(UIAlertView *)alertView
{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
#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.");