Skip to content

Instantly share code, notes, and snippets.

@floscr
floscr / create-branch-folder.sh
Last active October 13, 2021 00:02
Create folder from git branches
#!/bin/bash
# Git branches to folders
function branch_folders {
# Check if folder is a git repository
if [[ ! -d ".git" ]]; then
echo -e "\n\tThis is not a git repository!\n"
exit
fi
@floscr
floscr / download-vimcast-files.sh
Last active June 22, 2017 07:49
Download Vimcast Video Files
#!/bin/sh
# Downloads all vimcast videos & save a bookmark file in the same name
# Edit the number manually, have not found a way to get this automatically
for (( i = 1; i < 68; i++ )); do
FILE=$(curl -s http://media.vimcasts.org/videos/$i/ | grep m4v | sed 's/.*m4v\">\(.*m4v\)<\/a>.*/\1/g')
URL=http://media.vimcasts.org/videos/$i/$FILE
OUTPUT_VIDEO_FILE="0$i-$FILE"
OUTPUT_BOOKMARK_FILE="$OUTPUT_VIDEO_FILE.webloc"
echo "$URL"
@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)$/);