Skip to content

Instantly share code, notes, and snippets.

@misterbailey
misterbailey / oscillate.js
Created February 6, 2021 09:07
Javascript oscillation function
/**
* Ossilate - Make things go back and forth!
* TODO: Easings
* @param {Number} amplitude The distance from the center of motion to either extreme.
* @param {Number} interval The amount of time it takes for one complete cycle of motion in frames.
* @param {Number} time The current frame count, ideally a deltaTime value.
* @param {String} trigonometricFunction The function to be used to calculate the value. Defaults to 'sin'.
*/
oscillate = (amplitude, interval, time, trigonometricFunction = 'sin') => {
return amplitude * Math[trigonometricFunction]((Math.PI * 2.0) * time / interval);
@misterbailey
misterbailey / array_recursion.js
Created May 7, 2018 22:04
Array Recursion Task
// Task: Write a function that recursively loops through a multidimensional array and counts the instances of an item
// Le data
var arr = [
'apples',
['apples', 'oranges,', 'bananas', ['apples',]]
];
// A quick and dirty nested loop.
// Will only work if nesting is one level deep
@misterbailey
misterbailey / 0_reuse_code.js
Created September 20, 2017 09:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
document.observe("dom:loaded", function() {
console.log('DOM loaded');
// $$('td').invoke('observe', 'click', setColor);
});
var smile = {
0:[0,0,0,0,0,0,0,0,0,0,0,0,0], // Dont use this row
1:[0,0,0,1,1,1,1,1,0,0,0,0,0],
2:[0,0,1,0,0,0,0,0,1,0,0,0,0],
@misterbailey
misterbailey / date_regex.php
Last active January 5, 2017 11:55
Regex: retrieve date from string
$regex = '/(?<date_format_1>(?<day>(?i)\b\s*[0-9]+(?:st|nd|rd|th|)?)
(?<month>(?i)(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sept(?:ember?)|Oct(?:ober)?|Nov(?:ember?)|Dec(?:ember)?))
(?<year>\b\s*20[0-9]{2}))|
(?<date_format_2>(?P>month)(?P>day)(?!\s+-)(?:\s&amp;\s(?P>day))?) |
(?<range_type_1>(?P>month)(?P>day)\s+-\s+(?P>day))
/x';
@misterbailey
misterbailey / shadows.css
Created November 16, 2016 13:41
Material Design shadows
// Shadows
.shadow-1 {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.shadow-2 {
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
@misterbailey
misterbailey / v-align.css
Last active November 16, 2016 13:40
Vertical align class I use often
.v-align-wrapper {
position: absolute;
left: 0;
bottom: 0;
top: 0;
width: 100%;
height: 100%;
display: table;
margin: 0 auto;
@misterbailey
misterbailey / jQueryShyHeader.css
Last active October 13, 2016 22:35
jQuery to show/hide header in a fashion similar to medium.com
.shy-header {
position: fixed;
top: 0;
width: 100%;
left: 0;
height: 91px;
z-index:9999;
}
@misterbailey
misterbailey / HighlightCurrentNav.js
Last active September 15, 2016 14:19
A simple jQuery function to add a class of 'active' to the current navigation. Great for all those one-pagers out there
// Highlight Current Nav
$(document).ready(function() {
// Declare vars
var sections = $('section')
var nav = $('nav')
// When the window scrolls get the position
$(window).on('scroll', function() {
var curPos = $(this).scrollTop();
// An offset value based on window height
@misterbailey
misterbailey / UWE Email Validation
Created September 12, 2016 10:31
Used for forms on the Student Ideas submission form
$( document ).ready(function() {
// Delcare Vars
var email = $('input#email');
var emailWrap = $('.email-wrap');
var emailWrapperAlert = email.parent('.input-wrap > div.alert');
var alertBox = true;
var emailVal = $('input#email').val()
$('#ideas-submit-button').click(function(event){
// Stop the button default