Skip to content

Instantly share code, notes, and snippets.

View david-pm's full-sized avatar
💭
I may be slow to respond.

David McDonald david-pm

💭
I may be slow to respond.
View GitHub Profile
@david-pm
david-pm / rand
Created February 19, 2015 02:36
Call random number between 0-max (JavaScript ES5)
var randNum = function(max) {
return Math.floor(Math.random() * max);
}
200 OK -
General status code. Most common code used to indicate success.
201 CREATED -
Successful creation occurred (via either POST or PUT).
Set the Location header to contain a link to the newly-created resource (on POST).
Response body content may or may not be present.
204 NO CONTENT -
Indicates success but nothing is in the response body, often used for DELETE and PUT operations.
@david-pm
david-pm / video
Created February 19, 2015 23:04
Responsive Video
.video > .video-wrapper {
position: relative;
width: 100%;
padding-top: 56.25%;
}
.video > .video-wrapper iframe,
.video > .video-wrapper object,
.video > .video-wrapper embed {
position: absolute;
height: 100%;
@david-pm
david-pm / cover-img
Created February 19, 2015 23:07
Background Cover Img
body {
background: url('img.jpg')no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@david-pm
david-pm / respimg
Created February 19, 2015 23:07
Responsive Images
.parent { width: 200px; }
.child { max-width: 100%; height: auto; }
@david-pm
david-pm / windowSize
Created February 19, 2015 23:09
Set Browser Window Size (320x480)
javascript:(function(){window.open(document.URL, '','width=320,height=480');})();
@david-pm
david-pm / style
Created February 19, 2015 23:12
Get Computed Style of Element
window.getComputedStyle(element, null).getPropertyValue(“css-selector”);
@david-pm
david-pm / fluid
Created March 4, 2015 01:20
fluid iframe
<iframe src="index.html" style="display:block; width:100%!important; height:100%!important;" />
@david-pm
david-pm / question
Created May 27, 2015 22:01
Interview Question
Question 1
Write a JavaScript snippet that uses console.log to print all the numbers from 1 to 100, with two exceptions. For numbers divisible by 3, print "Fizz" instead of the number, and for numbers divisible by 5 (and not 3), print "Buzz" instead.
When you have that working, modify your program to print "FizzBuzz", for numbers that are divisible by both 3 and 5 (and still print "Fizz" or "Buzz" for numbers divisible by only one of those).
Question 2
Listen for an event on the unordered list in the provided html that uses event propagation correctly. On click, each button should log its inner html to the console.
Use the following html:
<!DOCTYPE html>
<html>
@david-pm
david-pm / FileInput
Last active August 29, 2015 14:25
Cross-Browser File Input
<!DOCTYPE html>
<html>
<head>
<meta name="author" content="DAVIDPM 2015, davidpm.io">
<title>Custom Cross-Browser File Input</title>
<style type="text/css">
.wrapper {
margin: 5%;
padding: 5%;
border: 1px solid #aaa;