Skip to content

Instantly share code, notes, and snippets.

@floscr
floscr / gsap-end-loop-after.js
Created May 17, 2016 08:13
GSAP End Loop after X runs
var tl = new TimelineMax()
.from(myObj, 1, { /* ...values... */ }, 0) // Will play in every loop
.call(loopCheck) // End loop after X times
.from(myObj, 1, { /* ...values... */ }, 0) // Will not play on the last loop
.repeat(-1)
var loop = 0;
var loopMax = 3;
function loopCheck() {
loop++;
@floscr
floscr / highscoreMoney.js
Last active May 30, 2016 21:53
Calculate the total amount on highscore.money
[].slice.call(document.querySelectorAll('table tr td:nth-child(2)')).reduce((total, num) => {
let numValue = parseInt(num.innerHTML.replace('$', ''));
return total + numValue;
}, 0) + '$';
@floscr
floscr / deepGet.js
Created July 18, 2016 08:42
Deep Get an Object
// http://adripofjavascript.com/blog/drips/making-deep-property-access-safe-in-javascript.html
function deepGet (obj, props, defaultValue) {
// If we have reached an undefined/null property
// then stop executing and return the default value.
// If no default was provided it will be undefined.
if (obj === undefined || obj === null) {
return defaultValue;
}
// If the path array has no more elements, we've reached
@floscr
floscr / scrolltop.js
Created July 22, 2016 09:22
Window Scroll Top Distance
window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0)
@floscr
floscr / detectMobile.js
Created July 22, 2016 09:42
Detect Mobile
if(!(/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera)) {
};
@floscr
floscr / show_files_greater_than_3_kb.zsh
Created July 26, 2016 08:09
Show files greater than 3 KB
ls -l zsh_demo/**/*(Lk+3)
@floscr
floscr / show-worpdress-admin-menu-id-tree.php
Created July 28, 2016 15:37
Show Worpdress Admin Menu ID Tree
global $submenu;
var_dump($submenu);
@floscr
floscr / filterFileListByExtension.js
Created August 3, 2016 08:30
Filter images from an array of files
// Test file list
let fileList = [
'myFile.js',
'myImage.png',
'./subdir/image.jpg',
];
// Filter images from the changed files list
let imageFiles = fileList.filter(fileName => {
return fileName.match(/\.(jpg|png|gif)$/);
@floscr
floscr / get-a-file-list-of-changed-files-between-two-commits.sh
Created August 3, 2016 08:55
Get a file list of changed files between two commits
git diff-tree -r --name-only 5410a6d 10de24d | tr '\n' ' '
@floscr
floscr / make-all-elements-contenteditable.js
Created August 3, 2016 11:31
Make all elements contenteditable
var a = document.querySelectorAll('*');
for (var i = 0; i < a.length; i++) {
var n = a[i];
n.setAttribute('contenteditable', true);
}