Skip to content

Instantly share code, notes, and snippets.

// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet weak private var contentView:UIView!
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
<?php
$target_path = "uploads/";
$uploadedFiles = array();
/*** check if a file has been submitted ***/
if(isset($_FILES['userfile']['tmp_name']))
{
/** loop through the array of files ***/
for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++)
{
#import "AFHTTPRequestOperationManager.h"
#import "AFURLSessionManager.h"
- (void)uploadImage
{
NSError *error;
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"$2y$1UW3CKMNTe",@"TOKEN_KEY",
@"1",@"userId",
@"lovely dog",@"animalName",
@"2",@"categoryId",
+ (NSDictionary*)getParamFromURL:(NSString*)str
{
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
NSString *url=str;
NSArray *comp1 = [url componentsSeparatedByString:@"?"];
NSString *query = [comp1 lastObject];
NSArray *queryElements = [query componentsSeparatedByString:@"&"];
for (NSString *element in queryElements) {
NSArray *keyVal = [element componentsSeparatedByString:@"="];
if (keyVal.count > 0) {
<html>
<head>
<meta name = "viewport" content = "user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width">
</head>
<body>
<script>
var TimerInterval = 3000;
var isMobile = {
@paingpyi
paingpyi / smartImageScaling
Created June 26, 2013 06:12
Display Image In Fixed-Height ScrollView. If Image width is out of bound, user can scroll horizontally. If image width is less than bound, will sit in center. Display Image In Fixed-Height UIView. If image width is less than bound, will sit in center.
#pragma mark - UIImage
/*
* ScrollView must use only TopLeft AutoResizing Option
*/
+ (void)displayImageInFixedHeightScrollView:(UIScrollView*)imgScrollView imageView:(UIImageView*)imageView image:(UIImage*)image
{
CGSize finalSize = image.size;
// Adjust ImageVieww Size
@paingpyi
paingpyi / Synchronous UIWebView
Created May 29, 2013 14:17
How to Synchronously get the Height of UIWebView
- (UIWebView*)createWebViewContent:(NSString*)content frame:(CGRect)frame
{
NSString * webContent = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no\"><style type='text/css'> body {color:black; margin:0 0 0 7pt; font-family: %@ !important; font-size:13; background-color: transparent;} .label{color:red} </style></head><body face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\"><div>%@</div></body></html>",WEBVIEW_FONT,content];
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
webView.delegate = self;
webView.tag = 444;
webView.backgroundColor = [UIColor clearColor];
[webView loadHTMLString:webContent baseURL:nil];
@paingpyi
paingpyi / gist:5440841
Created April 23, 2013 04:25
Maintaining images in a grid view with uniform width and height without forcing/stretching each images with fixed width and height. The main ingredients are "picasa-image" should be "block" with fixed width/height and overflow 'hidden'. Then child images should have min-width & min-height so images are not stretched even though they may have lon…
<li class="picasa-image">
<a class="picasa-image-large" href="http://lh6.ggpht.com/-f_ywI3XJxmg/SxqjI5ZAWBI/AAAAAAAAD18/ByMLDXTzxVA/DSC_5180.JPG">
<img class="picasa-image-thumb lazy" src="http://lh6.ggpht.com/-f_ywI3XJxmg/SxqjI5ZAWBI/AAAAAAAAD18/ByMLDXTzxVA/s144/DSC_5180.JPG">
</a>
</li>
<style>
.picasa-image{
border: 3px solid white;
<!-- @Reference : http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/ -->
<html>
<head>
<!-- For Syntax Highlighting -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css"></link>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
<script>
function styleCode() {
if (typeof disableStyleCode != 'undefined') { return; }