Skip to content

Instantly share code, notes, and snippets.

View AndyMBridges's full-sized avatar
🎯
Focusing

Andy Bridges AndyMBridges

🎯
Focusing
View GitHub Profile
@AndyMBridges
AndyMBridges / Canvas_Viewport.html
Created September 19, 2017 15:55 — forked from Checksum/Canvas_Viewport.html
Fit canvas to viewport size for mobile devices
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fit canvas to viewport for mobile devices</title>
<style>
* {
margin: 0;
padding: 0;
}
@AndyMBridges
AndyMBridges / gist:d498ad5c2795091dc3f432fe40f76410
Created August 16, 2017 16:01 — forked from millermedeiros/gist:891886
iPad HTML5 video quirks and hacks
/*
* Example how to preload HTML5 video on the iPad (iOS 3.2+)
* @author Miller Medeiros
* Released under WTFPL
*/
var vid = document.createElement('video');
vid.src = 'lol_catz.mp4';
document.getElementById('video-holder').appendChild(vid);
// Check element for class function
function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
var gridItem = document.getElementsByClassName('grid-item');
// Open the lightbox
function lightbox(e) {
e.preventDefault();
@AndyMBridges
AndyMBridges / gist:e900aa627e07e1bc1eb8117f4fb4afaa
Created June 30, 2017 14:54
Remove node_modules from already created repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@AndyMBridges
AndyMBridges / index.php
Last active March 30, 2017 15:08
Check for Facebook/Twitter useragent
<?php
if ((
strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/") !== false ||
strpos($_SERVER["HTTP_USER_AGENT"], "Facebot") !== false ||
strpos($_SERVER["HTTP_USER_AGENT"], "Twitterbot") !== false
) || (
// If hash has been set
!isset($_GET['f'])
@AndyMBridges
AndyMBridges / script.js
Created March 30, 2017 15:03
Check if device is iOS
// Check if device is iOS
var _iOSDevice = !!navigator.platform.match(/iPhone|iPod|iPad/);
@AndyMBridges
AndyMBridges / save.js
Created March 30, 2017 15:01
Save canvas as PNG
// Save the canvas on facebook share click
$('.button').on('click', function(e) {
// e.preventDefault();
// console.log(canvas);
var dataURL = canvas.toDataURL();
// window.open(canvas.toDataURL('image/png'), '_blank');
$.ajax({
type: "POST",
url: "save.php",
data: {
@AndyMBridges
AndyMBridges / GeoIP.DAT
Created March 30, 2017 14:55
Check for geolocation with PHP
This file has been truncated, but you can view the full file.
�����I�Ist
��
=�����~���ophiKLH0��>0��6g��.0�� ���'���!o��"0��#o��$0��%��&0����0��(o��)0��*0��+0��,0��-0��0����/���00��10��20��30��40��0��50�����7o��8���90��:0��;0��<0��=0��&0��?@0�����Aw��B���C0��D0��E0��0��FG0��0��&w��IJg�����o��MNg0��OP��fQReg��So��U������T���^��V���W���X���Y���Z���[���\���]���^���_���`���a���b���c���d���0�����^�����&���0�����j0��w��mko��l0��^��o��n��o��0����qyw�����rstu0��x0��w��v��w�����0��g��zw��0��{|0��}0�����w�����/0��'(��l��$�J���M���J���J���J���J���J���J���J���J���J���J���J���J���J���J���J���J���J���J�����J���������������������������������������8���
@AndyMBridges
AndyMBridges / Canvas text fragment
Created March 30, 2017 14:30
Split text onto multiple lines in canvas
// Fragment text function to calculate line breaks in dynamic text
// https://itsahappymedium.com/create/blog/canvas-text-wrapping/
function fragmentText(canvas, text, padding) {
// return text;
var maxWidth = canvas.width - (padding*2),
context = canvas.getContext('2d'),
lines = [],
words = text.split(' '),
@AndyMBridges
AndyMBridges / Random Shuffle
Last active March 30, 2017 14:50
Shuffle array in JS
/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {