Skip to content

Instantly share code, notes, and snippets.

@cgack
cgack / storeHistory.js
Created August 25, 2011 02:30
store history and local storage ex
// store the canvas image and push to local storage
var storeHistory = function () {
img = canvas.toDataURL("image/png");
history.pushState({ imageData: img }, "", window.location.href);
if (window.localStorage) { localStorage.curImg = img; }
};
//retrieve local storage
var PORT = process.env.PORT;
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type" : "text/plain"});
res.end("hello world");
});
server.listen(PORT);
@cgack
cgack / libpx_snippet.js
Created September 30, 2012 15:54
libpx snippet
if (me.game.STATE.weaponState === "magic_torrentacle") {
if (this.direction === "west") {
magic = new MagicEntity(this.pos.x - 100, this.pos.y + 30 , { image: "magic_torrentacle", spriteheight: 128, spritewidth: 128});
magic.flipX(true);
me.game.add(magic, this.z);
me.game.sort();
} else if (this.direction === "east") {
magic = new MagicEntity(this.pos.x + 42, this.pos.y + 30, { image: "magic_torrentacle", spriteheight: 128, spritewidth: 128 });
me.game.add(magic, this.z);
me.game.sort();
class Greeter {
greeting: string;
constructor (message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
var greeter = new Greeter("world");
@cgack
cgack / gist:4530044
Last active December 11, 2015 02:19
Whitelist a URL in PhoneGap
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ((navigationType == UIWebViewNavigationTypeLinkClicked) &&
([[[request URL] absoluteString] hasPrefix:@"https://www.google.com"]))
{
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
@cgack
cgack / gist:4530483
Created January 14, 2013 14:37
hasSuffix in PhoneGap
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ((navigationType == UIWebViewNavigationTypeLinkClicked) && ([[url absoluteString] hasSuffix:@"?openExternal=1"] ))
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}
return YES;
}
@cgack
cgack / gist:4530512
Created January 14, 2013 14:42
fragment
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ( ([url fragment] != NULL) && ([[url fragment] rangeOfString:@"openExternal=true"].location != NSNotFound) )
{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}
return YES;
@cgack
cgack / gist:4530524
Created January 14, 2013 14:44
onClick
/* turn all target = _blanks into whitelisted urls */
$(document).on("click", function (event) {
if (event.target.target === "_blank" && event.target.href.indexOf("#openExternal=true") === -1) {
event.target.href = event.target.href + "#openExternal=true";
}
});
@cgack
cgack / jsbin.acIRUBo.css
Created May 8, 2014 14:36
change css for navbar
.cg-navbar {
max-width: 100%
}
.cg-navbar__bar {
padding: 0;
display: table; table-layout:fixed; width: 100%;,
}
.cg-navbar__baritem{