This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here's a method that takes a block | |
- (void)doMathWithBlock:(int (^)(int, int))mathBlock { | |
self.label.text = [NSString stringWithFormat:@"%d", mathBlock(3, 5)]; | |
} | |
// Calling that method with a block | |
- (IBAction)buttonTapped:(id)sender { | |
[self doMathWithBlock:^(int a, int b) { | |
return a + b; | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video id="news" width=640 height=480 controls preload> <!-- WebM format for Firefox and Chrome --> <source src="news.webm" type='video/webm; codecs="vp8, vorbis"'> <!-- H.264 format for IE and Safari --> <source src="news.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> <!-- Fall back on the Flash plugin --> <object width=640 height=480 type="application/x-shockwave-flash" data="flash_movie_player.swf"> <!-- Param elements here configure the Flash movie player you're using --> <!-- Text is the ultimate fallback content --> <div>video element not supported and Flash plugin not installed.</div> </object> </video> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> This is a red square: <canvas id="square" width=10 height=10></canvas>. This is a blue circle: <canvas id="circle" width=10 height=10></canvas>. <script> var canvas = document.getElementById("square"); var context = canvas.getContext("2d"); context.fillStyle = "#f00"; context.fillRect(0,0,10,10); canvas = document.getElementById("circle"); context = canvas.getContext("2d"); context.beginPath(); context.arc(5, 5, 5, 0, 2*Math.PI, true); context.fillStyle = "#00f"; context.fill(); </script> </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return a newly created <img> element that will (once geolocation succeeds) // be set to display a Google map of the current location. Note that the caller // must insert the returned element into the document in order to make it // visible. Throws an error if geolocation is not supported in the browser function getmap() { // Check for geolocation support if (!navigator.geolocation) throw "Geolocation not supported"; // Create a new <img> element, start a geolocation request to make the img // display a map of where we are, and then return the image. var image = document.createElement("img"); navigator.geolocation.getCurrentPosition(setMapURL); return image; // This function will be invoked after we return the image object, when // (and if) the geolocation request succeeds. function setMapURL(pos) { // Get our position information from the argument object var latitude = pos.coords.latitude; // Degrees N of equator var longitude = pos.coords.longitude; // Degrees E of Greenwich var accuracy = pos.coords.accu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Determine my location asynchronously and display it in the specified element. | |
function whereami(elt) { | |
// Pass this object as the 3rd argument to getCurrentPosition() | |
var options = { | |
// Set to true to get a higher accuracy reading (from GPS, for example) // if available. Note, however that this can affect battery life. | |
enableHighAccuracy: false, // Approximate is okay: this is the default | |
// Set this property if a cached location is good enough. | |
// The default is 0, which forces location to be checked anew. | |
maximumAge: 300000, // A fix from the last 5 minutes is okay | |
// How long are you willing to wait to get the location? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (MyClass *)sharedInstance { | |
static MyClass *sharedInstance; | |
@synchronized(self) { | |
if (sharedInstance == nil) { | |
sharedInstance = [[MyClass alloc] init]; | |
} | |
} | |
return sharedInstance; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(Class*) loadFromNib | |
{ | |
NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:@"Class" owner:nil options:nil]; | |
return nibContents[0]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)sessionStateChanged:(FBSession *)session | |
state:(FBSessionState) state | |
error:(NSError *)error | |
{ | |
switch (state) { | |
case FBSessionStateOpen: { | |
//open! | |
} | |
break; | |
case FBSessionStateClosed: |
OlderNewer