Skip to content

Instantly share code, notes, and snippets.

NSURL *URL = [NSURL URLWithString:@"http://example.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
op.responseSerializer =[AFHTTPResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSStringEncoding big5 = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5_HKSCS_1999);
NSString *string = [[NSString alloc] initWithData:responseObject encoding:big5];
NSLog(@"HTML: %@", string);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSURL *URL = [NSURL URLWithString:@"http://example.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
op.responseSerializer =[AFHTTPResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSString* newStr = [NSString stringWithUTF8String:[responseObject bytes]];
NSString* newStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"HTML: %@", newStr);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
@j796160836
j796160836 / gist:9450763
Created March 9, 2014 16:58
[iOS] POST取回HTML (UTF-8)
NSURL *URL = [NSURL URLWithString:@"http://example.com/"];
NSString *postString = @"company=Locassa&quality=AWESOME!";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
op.responseSerializer =[AFHTTPResponseSerializer serializer];
#!/bin/bash
#
# (Above line comes out when placing in Xcode scheme)
#
API_TOKEN=<TestFlight API token here>
TEAM_TOKEN=<TestFlight team token here>
SIGNING_IDENTITY="iPhone Distribution: Development Seed"
PROVISIONING_PROFILE="${HOME}/Library/MobileDevice/Provisioning Profiles/MapBox Ad Hoc.mobileprovision"
#LOG="/tmp/testflight.log"
@j796160836
j796160836 / ReInstallAPK.sh
Last active August 29, 2015 14:02
ReInstallAPK.sh
#!/bin/bash
# Parameter check
if [[ "$1" == *'help' ]] || [[ "$1" == '-h' ]] ;then
echo "Usage:"
echo " Method 1:"
echo " \$ $0 <apk_apk_file> [start]"
echo
echo " Method 2:"
@j796160836
j796160836 / BuildAll.sh
Created July 17, 2014 05:37
Build All Android projects
#!/bin/bash
function StopIfFail(){
# http://www.dotkam.com/2008/10/24/getting-return-code-from-ant-in-shell/
if [ $? -ne 0 ];then
echo "BUILD ERROR: see message above."
exit 1;
else
sleep 1
fi
tell application "Google Chrome"
activate
set theUrl to "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
if (count every window) = 0 then
make new window
end if
set found to false
set theTabIndex to -1
<?php
$devices = explode("\n", shell_exec("adb devices"));
$pattern = "/([a-zA-Z0-9]+)\s+device/";
$zip = new ZipArchive;
if ($zip->open($argv[1]) === TRUE) {
$zip->extractTo('.', 'AndroidManifest.xml');
$zip->close();
}
@j796160836
j796160836 / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@j796160836
j796160836 / ConnectDebugWear.sh
Last active August 29, 2015 14:12
Use to connect android wear from android phone via bluetooth. Ref: http://developer.android.com/training/wearables/apps/bt-debugging.html
#!/bin/bash
DEVICE=`adb devices | sed '/List of devices/d' | sed '/:4444/d' | sed '/emulator/d' | sed '/vbox86p/d' | head -n 1 | awk '{print $1}'`
if [ "$DEVICE" == "" ]; then
echo "Please conntect devices!"
exit 0
else
echo "Devices: "$DEVICE
fi
adb -s $DEVICE forward tcp:4444 localabstract:/adb-hub; adb connect localhost:4444