Skip to content

Instantly share code, notes, and snippets.

View jonathanstark's full-sized avatar

Jonathan Stark jonathanstark

View GitHub Profile
@jonathanstark
jonathanstark / verify-google-recaptcha-with-php
Last active March 8, 2024 18:24
Verify Google reCAPTCHA with PHP
#
# Verify captcha
$post_data = http_build_query(
array(
'secret' => CAPTCHA_SECRET,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
@jonathanstark
jonathanstark / adding-js-programmatically.html
Last active September 29, 2021 06:48
Snippet of javascript code that will append external script files programmatically, and in order. Intended for responsive web sites where maximum progressive enhancement is desired. Don't want to make needless http requests or load external javascript on devices that can't (or shouldn't) execute javascript. Any questions/comments/suggestions gre…
<html>
<head></head>
<body>
<!-- All your kewl content goes here -->
<!-- Append javascript programatically so we don't make needless http requests -->
<script>
(function(doc){
var appendScripts = function(srcs) {
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
@jonathanstark
jonathanstark / mamp_function
Last active December 11, 2018 17:19
Serve the current directory with MAMP from the command line
function mamp() {
#
# Default location of the apache conf file for MAMP
CONF_FILE="/Applications/MAMP/conf/apache/httpd.conf"
#
# Fish existing doc root out of conf file
LINE=$(cat $CONF_FILE | grep ^DocumentRoot)
QUOTED_STRING=${LINE/DocumentRoot /}
OLD_DOC_ROOT=${QUOTED_STRING//\"/}
#
<iframe id="JotFormIFrame-71245263674155" onload="window.parent.scrollTo(0,0)" allowtransparency="true" src="https://form.jotform.us/71245263674155" frameborder="0" style="width:100%; height:0px; border:none;" scrolling="no"> </iframe> <script type="text/javascript"> var ifr = document.getElementById("JotFormIFrame-71245263674155"); if(window.location.href && window.location.href.indexOf("?") > -1) { var get = window.location.href.substr(window.location.href.indexOf("?") + 1); if(ifr && get.length > 0) { var src = ifr.src; src = src.indexOf("?") > -1 ? src + "&" + get : src + "?" + get; ifr.src = src; } } window.handleIFrameMessage = function(e) { var args = e.data.split(":"); if (args.length > 2) { iframe = document.getElementById("JotFormIFrame-" + args[2]); } else { iframe = document.getElementById("JotFormIFrame"); } if (!iframe) return; switch (args[0]) { case "scrollIntoView": iframe.scrollIntoView(); break; case "setHeight": iframe.style.height = args[1] + "px"; break; case "collapseErrorPage": if (ifr
@jonathanstark
jonathanstark / gist:8034686
Created December 19, 2013 05:07
Modulo bugfix for negative numbers
// Modulo bugfix for negative numbers
Number.prototype.mod = function(n) {
return ((this%n)+n)%n;
}
@jonathanstark
jonathanstark / gist:7557847
Last active December 28, 2015 20:29
TechCrunch blog post: png failover
// Failover to PNG if browser can’t hack SVG
if(!Modernizr.svg) {
$('img').each(function(){
this.src = this.src.replace('svg', 'png');
});
}
@jonathanstark
jonathanstark / gist:7557840
Last active December 28, 2015 20:29
TechCrunch blog post: lazy load images
// Lazy load "below the fold" images
$(window).on('load', function(){
$('img').each(function(){
if(this.src.match('1x1.png')) {
this.src = $(this).attr('data-src');
}
});
});
@jonathanstark
jonathanstark / gist:7557837
Last active December 28, 2015 20:29
TechCrunch blog post: toasterize
// Initialize any toasters
$('.toaster').toasterize({
attractor: $('.article-entry p:last'),
minWindowWidth: 960,
viewportSpacing: 44
});
@jonathanstark
jonathanstark / gist:7557823
Last active December 28, 2015 20:29
TechCrunchblog post: readmorify
// Initialize any "read more" elements
$('.press-release').readmorify({
buttons: {
more: '<p class="align-center text-btn read-more"><a href="#">Read more</a></p>',
less: '<p class="align-center text-btn read-less"><a href="#">Read less</a></p>'
},
threshold: 280,
duration: 1000 // milliseconds
});