Skip to content

Instantly share code, notes, and snippets.

@miguel12345
miguel12345 / new_gist_file.js
Created December 3, 2013 08:07
Element computed style
var a = getComputedStyle(document.getElementById("navbar"))
@miguel12345
miguel12345 / new_gist_file.js
Created December 3, 2013 07:35
Obtain html markup node contents
var linkHref = link.getAttributeNode('href').nodeValue;
@miguel12345
miguel12345 / new_gist_file
Created December 2, 2013 10:30
Publish to wall flow
if ([[FBSession activeSession]isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self postPhoto];
}];
@miguel12345
miguel12345 / new_gist_file
Created December 2, 2013 10:21
Stretchable button background image
UIImage *originalImage = [UIImage imageNamed:@"categories_button_scalable_bg"];
[self.categoriesButton setBackgroundImage: [originalImage stretchableImageWithLeftCapWidth:6 topCapHeight:6] forState:UIControlStateNormal];
@miguel12345
miguel12345 / new_gist_file.js
Created December 2, 2013 07:54
eval in the global context
// Evalulates a script in a global context
// Evaluates Async. in Safari 2 :-(
globalEval: function( data ) {
data = jQuery.trim( data );
if ( data ) {
if ( window.execScript )
window.execScript( data );
else if ( jQuery.browser.safari )
// safari doesn't provide a synchronous global eval
@miguel12345
miguel12345 / new_gist_file.js
Created December 1, 2013 07:50
Method overloading
function addMethod(object,name,fn){
var old = object[name];
object[name] = function() {
if(fn.length == arguments.length){
return fn.apply(this,arguments);
}
else if(typeof old == "function"){
return old.apply(this,arguments);
}
};
@miguel12345
miguel12345 / new_gist_file.css
Created November 30, 2013 08:08
Data uri, good for inline images (small ones, where the round trip time is bigger that the time it takes to download the image itself)
li {
background:
url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7)
no-repeat
left center;
padding: 5px 0 5px 25px;
}
@miguel12345
miguel12345 / new_gist_file.html
Created November 30, 2013 07:55
Show file information
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Show File Data</title>
<style type='text/css'>
body {
font-family: sans-serif;
}
</style>
@miguel12345
miguel12345 / new_gist_file
Created November 29, 2013 10:55
Facebook flow
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen: {
//open!
}
break;
case FBSessionStateClosed:
@miguel12345
miguel12345 / new_gist_file
Created November 29, 2013 10:06
Verify email
NSString* emailString = @"[email protected]";
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
[emailTest evaluateWithObject:emailString]; //returns BOOL