Skip to content

Instantly share code, notes, and snippets.

@mattbell87
mattbell87 / typeout.js
Last active August 29, 2015 14:06
jQuery plugin for typing animation - simulates typing the contained text
//Type animation
$.fn.typeout = function(duration, oncomplete)
{
$(this).each(function()
{
//Grab the text
var text = $(this).text();
$(this).data("percent", 0);
//Create the animation
$(this).animate({percent: 100},
@mattbell87
mattbell87 / fadeset.js
Created September 9, 2014 04:53
jQuery plugin to cycle and fade through a set of classes - uses a CSS3 transition
//Fade set looping animation
$.fn.fadeset = function(animlength)
{
$(this).each(function()
{
//Create a fadehandler object
var fadehandler = new (function(obj)
{
this.obj = obj;
this.current = 0;
@mattbell87
mattbell87 / README.md
Last active October 13, 2015 03:12
Convert from base10 to a custom base and back again

Base converter

I was playing around with numbering systems as I wanted some numbers to be represented by letters (or what you'd call Base 26).

A=0, B=1, C=2 etc..

When it gets to 26 it becomes BA, not AA as you might think to begin with. Think of it like the number 10. AA would equal zero just like 00.

I wrote this in plain JavaScript for easy testing, and it should be fairly straight-forward to port this to other languages if needed.

Usage

@mattbell87
mattbell87 / runapp
Last active December 21, 2015 07:12
Start a GUI app on the primary display
#!/bin/bash
export DISPLAY=:0
APP=$1
shift
echo Starting $APP "$@"
nohup $APP "$@" >&/dev/null &
#!/bin/bash
echo Starting dev environment for $1
node-inspector & nodemon --debug "$@"
@mattbell87
mattbell87 / pre-receive
Created February 16, 2016 04:51
Pre-receive hook to validate user and email fields on git commits
#!/bin/bash
AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1
NAME=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p')
EMAIL=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p')
HOSTNAME=$(hostname -f)
if [ "$NAME" != "$USER" ]
then
echo "YOUR COMMIT(S) HAVE NOT BEEN ACCEPTED"
echo ""
@mattbell87
mattbell87 / script.sh
Last active February 23, 2016 23:56
Automatically elevate to administrator for sudo on bash
#!/bin/bash
# Define the sudo override function
function sudo()
{
echo PASSWORDHERE | /usr/bin/sudo -kS \"$@\";
}
# Export for child scripts
export -f sudo
@mattbell87
mattbell87 / script.sh
Created February 24, 2016 23:59
Keep sudo alive until a bash script has finished.
#!/bin/bash
# Ask for password
sudo -v
# Or give the password if you know it
# echo 'PASSWORD' | sudo -vS
while true; do sudo -n true; sleep 60; kill -0 \"$$\" || exit; done 2>/dev/null &
@mattbell87
mattbell87 / Ironkey Fedora.sh
Created July 21, 2016 00:54
Install Ironkey on Fedora
#!/bin/bash
sudo dnf install glibc.i686
sudo dnf install libgcc_s.so.1
@mattbell87
mattbell87 / switchto
Last active January 2, 2017 04:40
Bring an app to the foreground on the primary display. Requires xdotool.
#!/bin/bash
export DISPLAY=:0
APP=$1
echo Switching to $APP
xdotool search --class "$APP" windowactivate