Skip to content

Instantly share code, notes, and snippets.

@tpthn
tpthn / gist:3516777
Created August 29, 2012 18:33
iOS - dismiss keyboard when touch on background
//--Touch to dismiss keyboard
UIButton *dismissKeyboardButtonBg = [UIButton buttonWithType:UIButtonTypeCustom];
dismissKeyboardButtonBg.backgroundColor = [UIColor clearColor];
[dismissKeyboardButtonBg addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventTouchUpInside];
[dismissKeyboardButtonBg setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[dismissKeyboardButtonBg setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:dismissKeyboardButtonBg];
@tpthn
tpthn / iOS general
Created August 10, 2012 20:33
iOS - dim the screen
//dim the screen base on a slider value
[[UIScreen mainScreen] setBrightness:[(UISlider *)sender value]/100];
@tpthn
tpthn / iOS General
Created August 10, 2012 20:31
iOS - Detect iOS version
if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0 )
NSLog (@"iOS version is greater than 5.0");
@tpthn
tpthn / UIView Element - UISlider
Created August 10, 2012 20:27
iOS - Some basic info about UISlider
//setup a UISlider programmatically
mySlider = [[[UISlider alloc] initWithFrame:CGRectMake(174, 12, 120, 23)] autorelease];
mySlider.maximumValue = 100;
mySlider.minimumValue = 30;
mySlider.value = 100;
[mySlider addTarget:self action:@selector(dimScreen:) forControlEvents:UIControlEventValueChanged];
//adding the slider to a table cell
cell.textLabel.text = @"My Slider";
cell.accessoryView = mySlider;
@tpthn
tpthn / gist:3060544
Created July 6, 2012 14:37
CSS - Styling dropdown
//HTML part
<div class="select-wrapper">
<select id="search_filter">
<option value='username'>Username (recommended)</option>
<option value='lastname'>Lastname</option>
</select>
</div>
@tpthn
tpthn / gist:3054424
Created July 5, 2012 15:41
jQuery - trigger enter on button for textbox input
$("#id_of_textbox").keyup(function(event){
if(event.keyCode == 13){
$("#id_of_button").click();
}
});
@tpthn
tpthn / gist:2993371
Created June 26, 2012 04:51
jQuery wordpress wrapper
(function($) {
// $ Works! You can test it with next line if you like
// console.log($);
})( jQuery );
@tpthn
tpthn / gist:2280090
Created April 2, 2012 02:20
javascript - view source of web page
//type this in the url field after page load
javascript:alert(document.documentElement.innerHTML);
@tpthn
tpthn / gist:2251723
Created March 30, 2012 13:58
jQuery - Direct link
//version specific
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
//always up to date
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
//jquery ui
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
@tpthn
tpthn / gist:2251681
Created March 30, 2012 13:50
jQuery - Get multiple selected items from list
<select name="garden" multiple="multiple">
<option>Flowers</option>
<option selected="selected">Shrubs</option>
<option>Trees</option>
<option selected="selected">Bushes</option>
<option>Grass</option>
<option>Dirt</option>
</select>