Skip to content

Instantly share code, notes, and snippets.

View segdeha's full-sized avatar
🏠
Working from home

Andrew Hedges segdeha

🏠
Working from home
View GitHub Profile
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Prototypal inheritence</title>
</head>
<body>
<form>
<div><button onclick="animal.speak();return false;">animal.speak()</button></div>
<div><button onclick="dog.speak();return false;">dog.speak()</button></div>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Prototypal inheritence</title>
<style type="text/css">
form {
width: 300px;
float: left;
var COOLJS = {}
COOLJS = (function (window, document, undefined) {
var private_var = 'Secret!'
function init() {
// magic happens
}
return {
init : init
}
@segdeha
segdeha / Squares.js
Created April 26, 2011 15:46 — forked from mikesusz/Squares.js
squaredesign squares draw
function Squares(id) {
this.sq = document.getElementById(id)
this.$sq = $(this.sq)
this.con = sq.getContext('2d')
this.sqD = 60
this.styles = [
'#e2e5e3',
'#f4f4f4',
'#808ab8',
'#40455c',
@segdeha
segdeha / Squares.js
Created April 26, 2011 16:08 — forked from mikesusz/Squares.js
squaredesign squares draw
function Squares(id) {
this.sq = document.getElementById(id)
this.$sq = $(this.sq)
this.con = sq.getContext('2d')
this.sqD = 60
this.styles = [
'#e2e5e3',
'#f4f4f4',
'#808ab8',
'#40455c',
@segdeha
segdeha / simple-ajax.js
Last active September 26, 2015 23:57
Simplest possible Ajax implementation
function ajax(url, callback) {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (4 === xhr.readyState && 400 > xhr.status) {
callback(xhr);
}
};
xhr.send(null);
@segdeha
segdeha / grandcentral.txt
Created December 12, 2011 22:28
How does Apple do that?
You have @glan to thank for this cool insight into how Apple did their cool 3D view of their new Grand Central Station store.
1. In Safari, go to http://www.apple.com/retail/grandcentral/
2. Click 'View More Photos'
3. Click bottom/left photo (labeled '360°')
4. Open the Web Inspector
5. Copy/paste the following in the console and hit Enter:
document.querySelector('.ac-cube360-container').style.webkitTransform = 'translateZ(-200px)'
@segdeha
segdeha / gist:1808873
Created February 12, 2012 14:40
Bookmarklet for deleting promoted Twitter content
javascript:$('.promoted-tweet').parent().fadeOut(500,function(){$(this).remove()});$('.promoted-account,.promoted-trend').fadeOut(500,function(){$(this).remove()});
@segdeha
segdeha / ajax120.js
Last active June 23, 2020 04:21
Smallest possible Ajax implementation (120 characters)
function a(u,c){var x=new XMLHttpRequest;x.open('GET',u);x.onreadystatechange=function(){3<x.readyState&&c(x)};x.send()}
@segdeha
segdeha / klass.js
Created August 29, 2015 23:02
Simple example of chaining
/**
* Allow chaining of classList methods
* @usage klass( document.querySelector('#my-view') ).remove( 'hidden' ).adds( ['active', 'loading'] );
*/
function klass(el) {
var api = (function () {
return {
add : function (klass) {
el.classList.add(klass);