Skip to content

Instantly share code, notes, and snippets.

View johnfmorton's full-sized avatar
⌨️
Making stuff

John F Morton johnfmorton

⌨️
Making stuff
View GitHub Profile
var Person = function(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var thomas = new Person("thomas")
var Person = function(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var thomas = new Person("thomas")
@johnfmorton
johnfmorton / extendingNumber.js
Created October 20, 2010 14:32
Extending Number - class exercise
// ah, wrap the function in parentheses!
Number.prototype.times = (function(theString) {
this.theString = theString;
var result = "";
for (var i = 0; i< this; i++){
result += this.theString;
}
//return this + " ; " + this.theString;
return result;
@johnfmorton
johnfmorton / isItCreditCard.js
Created October 20, 2010 15:48
Is it a credit card function for JS class
Number.prototype.isCreditCard = (
function() {
var testCC = this.toString();
var sum =0; mul = 1; l = testCC.length;
if (l < 19) {
for (i = 0; i < l; i++)
{
var digit = testCC.substring(l-i-1,l-i);
var tproduct = parseInt(digit ,10)*mul;
@johnfmorton
johnfmorton / dom_challenge1.html
Created October 20, 2010 17:21
change event capture times 1
<!-- 1. Change the addEventListener calls so that the events occur in the following order.
the_div! the_item! the_list! -->
<div id="the_div">
<ul id="the_list">
<li id="the_item">Click me!</li>
</ul>
</div>
<p id="log"></p>
@johnfmorton
johnfmorton / gmail-htmlemail-gap-fix.css
Created January 31, 2013 14:26
Re: HTML email authoring and getting images in table cells to not cause gaps in Gmail. Making img display as blocks fixed that issue.
img {
display: block;
}
@johnfmorton
johnfmorton / CreateBookmarklet.html
Last active July 29, 2017 09:58
Bookmarklet to auto-refresh any page at some point in the near future.
<!DOCTYPE html>
<html>
<head>
<title>Page Refresher</title>
</head>
<body>
<h1>Page Refresher</h1>
<p>Drag the link below to your toolbar to install the "page refresher" bookmarklet. Press the bookmarklet and you will be prompted for when you'd like the page you're on to be refreshed in your browser.</p>
<a href="javascript: (function () { var jsCode = document.createElement('script'); jsCode.setAttribute('src', 'https://gist.githubusercontent.com/johnfmorton/9238562/raw/b2a65b62c17569d3d275b9f2a755d14658e8d036/pagerefresher.js'); document.body.appendChild(jsCode); }());">Refresher</a>
@johnfmorton
johnfmorton / gist:3c509174abd9dccecb41
Last active August 29, 2015 14:13
Simply way to set background color for a view using RGB color in 0-255
private func setBackgroundColor(redColor: Int, greenColor: Int, blueColor: Int) -> Bool{
// colors should be from 0 to 255, like you get when picking colors in Photoshop
if redColor < 0 || greenColor < 0 || blueColor < 0 {
println("At least one color value not in range. Must be at least 0")
return false
}
if redColor > 255 || greenColor > 255 || blueColor > 255 {
println("At least one color value not in range. Must be at less than 255")
return false
}
@johnfmorton
johnfmorton / gist:3abf28530a7c4ea15b62
Last active November 9, 2018 16:10
Slightly modified version of http://detectmobilebrowsers.com/ JS script to detect mobile. This includes tablets
// returns true is browser is mobile
// added "|android|ipad|playbook|silk" to first regex to detect tablets
// This leaves 2 'android' tests in the first regex. One of the 'android' tests can be eliminated
// but left in so you can remove the "|android|ipad|playbook|silk" string easily.
function isMobile() {
var a = navigator.userAgent||navigator.vendor||window.opera;
if (/(android|bb\d+|meego|android|ipad|playbook|silk).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)
@johnfmorton
johnfmorton / _mixins.scss
Last active July 29, 2017 09:58
These are SASS mixins I reuse. Helpful to me. Helpful to you? Take 'em!
// -- I didn't make this but it's really handy! - John
/// Convert angle
/// @author Chris Eppstein
/// @param {Number} $value - Value to convert
/// @param {String} $unit - Unit to convert to
/// @return {Number} Converted angle
@function convert-angle($value, $unit) {
$convertable-units: deg grad turn rad;
$conversion-factors: 1 (10grad/9deg) (1turn/360deg) (3.1415926rad/180deg);