Skip to content

Instantly share code, notes, and snippets.

View jonathanstark's full-sized avatar

Jonathan Stark jonathanstark

View GitHub Profile
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
<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 September 26, 2015 18:03
GZIP stuff for Apache .htaccess file
####################
# 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 September 25, 2015 18:10
Caching stuff for Apache .htaccess file
##### 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 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' =>
/* 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 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//\"/}
#
@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');
}
});
});