Skip to content

Instantly share code, notes, and snippets.

View jswhisperer's full-sized avatar
🕵️
For Sale... I mean open to work.

Gregory The JSWhisperer jswhisperer

🕵️
For Sale... I mean open to work.
View GitHub Profile
@jswhisperer
jswhisperer / PHP.base64
Created May 27, 2013 14:22
PHP: Base64 Images
function data_uri($file, $mime) {
$contents=file_get_contents($file);
$base64=base64_encode($contents);
echo "data:$mime;base64,$base64";
}
@jswhisperer
jswhisperer / JS:getClientIP
Created May 30, 2013 07:02
JS: Get IP clientside
function() {
$.getJSON( "http://smart-ip.net/geoip-json?callback=?",
function(data){
alert( data.host);
}
);
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@jswhisperer
jswhisperer / js_equiv_selectors
Created June 9, 2013 09:57
Native Equivalents of Jquery Selectors
/* jQuery */
$("div")
/* native equivalent */
document.getElementsByTagName("div")
/* jQuery */
@jswhisperer
jswhisperer / requestAnimationFrame
Created June 9, 2013 14:14
requestAnimationFrame usage
var globalID;
function repeatOften() {
$("<div />").appendTo("body");
globalID = requestAnimationFrame(repeatOften);
}
$("#start").on("click", function() {
globalID = requestAnimationFrame(repeatOften);
});
$("#stop").on("click", function() {
cancelAnimationFrame(globalID);
@jswhisperer
jswhisperer / dommanipulation
Created June 9, 2013 14:16
JS native equivilant to DOM Manipulation with jQuery
/* Append HTML elements 8/
/* jQuery */
$(document.body).append("<div id='myDiv'><img src='im.gif'/></div>");
/* CRAPPY native equivalent */
document.body.innerHTML += "<div id='myDiv'><img src='im.gif'/></div>";
/* MUCH BETTER native equivalent */
var frag = document.createDocumentFragment();
@jswhisperer
jswhisperer / cssclasseswithoutjquery
Created June 9, 2013 14:17
CSS classes without jquery
// get reference to DOM element
var el = document.querySelector(".main-content");
//----Adding a class------
/* jQuery */
$(el).addClass("someClass");
/* native equivalent */
el.classList.add("someClass");
@jswhisperer
jswhisperer / editcssnojquery
Created June 9, 2013 14:18
Edit css properties without jQuery
// get reference to a DOM element
var el = document.querySelector(".main-content");
//----Setting multiple CSS properties----
/* jQuery */
$(el).css({
background: "#FF0000",
"box-shadow": "1px 1px 5px 5px red",
width: "100px",
<meta name="twitter:card" value="summary">
<meta name="twitter:site" value="@yoast">
<meta name="twitter:creator" value="@michielheijmans">
@jswhisperer
jswhisperer / Windows 8 Meta to Pin
Created June 16, 2013 17:19
Windows 8 Meta to Pin
<meta name="application-name" content="Greg Benner"/>
<meta name="msapplication-TileColor" content="#cf9910"/>
<meta name="msapplication-TileImage" content="2ded66ee-e5f8-4410-8d0b-9409877f5f64.png"/>