Skip to content

Instantly share code, notes, and snippets.

View philipmadeley's full-sized avatar

Philip Madeley philipmadeley

View GitHub Profile
@philipmadeley
philipmadeley / _mixins.scss
Last active September 16, 2015 02:00
Favourite Mixins!
//IMAGES
// SVG PNG swap out
$image-path: '../images' !default;
$fallback-extension: 'png' !default;
$retina-suffix: '@2x';
@mixin background-image($name, $size:false, $repeat: no-repeat) {
background-image: url("#{$image-path}/#{$name}.svg");
background-repeat: $repeat;
@if($size) {
@philipmadeley
philipmadeley / keymap
Last active January 17, 2016 14:37
keymap for Atom
# Your keymap
#
# Atom keymaps work similarly to stylesheets. Just as stylesheets use selectors
# to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
@philipmadeley
philipmadeley / save_edit_cancel_form.js
Last active September 16, 2015 02:00
Function for input fields
$(document).ready( function(){
$('.save-button').on('click', save_onclick);
$('.cancel-button').on('click', cancel_onclick);
$('.edit-button').on('click', edit_onclick);
$('.save-button, .cancel-button').hide();
});
function edit_onclick(){
@philipmadeley
philipmadeley / ej_exercises.js
Last active September 15, 2015 09:22
EJ Exercises with explanations
/* 4.4 deep linking
*/
function deepEqual(a, b) {
if (a === b) return true;
if (a == null || typeof a != "object" ||
b == null || typeof b != "object")
return false;
@philipmadeley
philipmadeley / is_checked_toggle.js
Last active September 16, 2015 01:59
Any input is:checked - show/hide
$(document).ready(function() {
var $action = $(".action-btn").hide(),
$anyInput = $('.table-list input').click(function() {
$action.toggle( $anyInput.is(":checked") );
});
});
@philipmadeley
philipmadeley / check_row_hover.js
Last active September 16, 2015 01:59
input_checked_or_row_hover
$(document).ready(function() {
$('.table-list tr').click(function(e){
if(e.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
});
var $action = $(".action-btn").hide(),
@philipmadeley
philipmadeley / disable_enable_checkboxes.js
Last active September 16, 2015 02:00
disable other checkboxes
$(':checkbox').click(function(){
var elems = $(this).parents('tbody').find(':checkbox');
elems.not($(this)).attr('disabled', $(this).is(':checked'));
});
@philipmadeley
philipmadeley / angular_promise_controller.js
Last active September 16, 2015 01:59
Example of using a promise in Angular
var makePromiseWithSon = function() {
// This service's function returns a promise, but we'll deal with that shortly
SonService.getWeather()
// then() called when son gets back
.then(function(data) {
// promise fulfilled
if (data.forecast === 'good') {
@philipmadeley
philipmadeley / angular_service_promise.js
Last active September 16, 2015 01:59
Angular service with promise
app.factory('SonService', function($http, $q) {
return {
getWeather: function() {
// the $http API is based on the deferred/promise APIs exposed by the $q service
// so it returns a promise for us by default
return $http.get('http://fishing-weather-api.com/sunday/afternoon')
.then(function(response) {
if (typeof response.data === 'object') {
return response.data;
} else {
videoLayer = new VideoLayer {video: "images/videos/v0.mp4", size: Screen.size}
videoOverlay = new Layer {size: Screen.size, backgroundColor: "rgba(0,0,0,.7)"}
bg = new Layer {backgroundColor: "#FFF", size: Screen.size}
countdown = new TextLayer {text: "closing in 3s", fontSize: 18, y: Align.bottom(-64), x: Align.center, color:"#FFF", parent: videoOverlay}
replay = new TextLayer {text: "Replay video", fontSize: 24, point: Align.center, color: "#FFF", parent: videoOverlay}
showHideLayers = [videoOverlay, countdown, replay]
for layer in showHideLayers
layer.states =
show: