Skip to content

Instantly share code, notes, and snippets.


T.J. Fogarty tjFogarty

View GitHub Profile
tjFogarty /
Created Nov 19, 2012
Reverse a string in java
public class ReverseString {
public static void main(String[] args) {
String reversed = reverseString( "Reverse this string." );
System.out.println( reversed );
public static String reverseString( String newString ) {
// cleans up string if there are any extra spaces
tjFogarty / slider.js
Created Dec 4, 2012
A sort of image slider logic
View slider.js
// replace background image when user clicks on a thumbnail
$ 'click', function(e) {
var $this = $( this ),
$bgImage = $( '.current-section .bg-image' ),
oldSrc = $bgImage.attr( 'src' ),
newSrc = $this.find( 'img' ).attr( 'src' ),
marginValue = $this.width() + 20, // 20 for the 10px margin-left and right
newThumbnail = '<li><a href="#"><img src="' + oldSrc + '" class="scale-with-grid"></a></li>',
newBgImage = '<img src="' + newSrc + '" alt="" class="bg-image">';
tjFogarty / page.js
Created Dec 8, 2012
Do things with the page name
View page.js
var Page = {
getPageName: function() {
var pageName = document.URL.split( '/' ).pop();
if( !pageName ) {
pageName = $( ' li:first-child a' ).attr( 'href' );
return pageName;
View vimeo-tracking.js
//simply use Vimeo.init(); to find the videos and bind the events
var Vimeo = {
// we can add more events when we need to, e.g. onPause
events: {
// when videos are ready, we can attach our events
ready: function( player_id ) {
$f(player_id).addEvent( 'play', );
//when the play button is clicked
tjFogarty / notifications-demo.html
Last active Dec 14, 2015
A CodePen by T.J. Fogarty. Notify - A simple little notification system that will let you define a success or an error, so you can hook in with CSS and style accordingly.
View notifications-demo.html
<a href="#" class='notify'>Success!</a>
<a href="#" class='notify error'>Error :(</a>
tjFogarty / slider-demo.html
Last active Dec 14, 2015
A CodePen by T.J. Fogarty. Touch/keyboard content slider - I wanted to build a simple, reusable content slider just to understand how it works. There's definitely improvements to be made, but it works :) Supports keyboard navigation, and swiping on touch-based devices.
View slider-demo.html
<div class="container">
<div id="slider-container">
<ul class="slider-images clearfix">
<li><img class="scale" src="" alt=""></li>
<li><img class="scale" src="" alt=""></li>
<li><img class="scale" src="" alt=""></li>
<li><img class="scale" src="" alt=""></li>
tjFogarty / config.php
Created Mar 19, 2013
Quick and simple database connection
View config.php
$database = new Database();
$database->dbUrl = 'localhost'; //URL of database
$database->dbUser = 'root'; // Username
$database->dbPass = ''; // Password
$database->dbName = 'test_db'; // Name of database you wish to connect to
tjFogarty / youtube-event-tracking.js
Created Apr 30, 2013
Tracking for any number of YouTube iframes. Uses a data-title attribute for grabbing a title.
View youtube-event-tracking.js
// Any iframes with a class of .yt will be collected for event tracking
var Youtube = {
$players: $( '.yt' ),
playerArray: [],
numPlayers: $( '.yt' ).length - 1,
init: function() {
tjFogarty / mobile-nav.js
Created Jul 9, 2013
Build mobile navigation from existing list of links
View mobile-nav.js
var MobileNav = {
navContainer: $( '.main-nav, .ancillary-nav' ),
navItems: null,
select: null,
navHTML: "<select class=mobile-nav></select>",
optionHTML: null,
init: function() {
// Build navigation then attach event handlers
tjFogarty / js-enabled.js
Created Aug 26, 2013
Assuming the HTML element has a class of 'no-js', this will swap it for 'js'. Should be placed in the header.
View js-enabled.js
var el = document.getElementsByTagName('html')[0];
el.className = el.className.replace('no-js', 'js');