Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Stark jonathanstark

View GitHub Profile
View gist:99fd87f1eeac7e35ddec3ed069c298df
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
View jotform.html
<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 / gzip.htaccess
Created Sep 26, 2015
GZIP stuff for Apache .htaccess file
View gzip.htaccess
####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
@jonathanstark
jonathanstark / caching.htaccess
Created Sep 25, 2015
Caching stuff for Apache .htaccess file
View caching.htaccess
##### CACHING STUFF #####
# 1 YEAR
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
@jonathanstark
jonathanstark / verify-google-recaptcha-with-php
Last active Mar 29, 2021
Verify Google reCAPTCHA with PHP
View 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' =>
View gist:22ee69e86b0f9177fd2f
/* I didn't write this snippet but I can't remeber where I found it. PLMK if you know who the original author is :) */
(function($) {
$.fn.uncomment = function(recurse) {
$(this).contents().each(function() {
if (this.hasChildNodes()) {
$(this).uncomment(recurse);
} else if (this.nodeType == 8) {
// Need to "evaluate" the HTML content,
// otherwise simple text won't replace
@jonathanstark
jonathanstark / mamp_function
Last active Dec 11, 2018
Serve the current directory with MAMP from the command line
View mamp_function
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//\"/}
#
@jonathanstark
jonathanstark / gist:8034686
Created Dec 19, 2013
Modulo bugfix for negative numbers
View gist:8034686
// Modulo bugfix for negative numbers
Number.prototype.mod = function(n) {
return ((this%n)+n)%n;
}
@jonathanstark
jonathanstark / gist:7557847
Last active Dec 28, 2015
TechCrunch blog post: png failover
View gist:7557847
// 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 Dec 28, 2015
TechCrunch blog post: lazy load images
View gist:7557840
// 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');
}
});
});