Skip to content

Instantly share code, notes, and snippets.

View tjFogarty's full-sized avatar
🇮🇪

T.J. Fogarty tjFogarty

🇮🇪
View GitHub Profile
@tjFogarty
tjFogarty / reverseString.java
Created November 19, 2012 23:20
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
tjFogarty / slider.js
Created December 4, 2012 23:31
A sort of image slider logic
// replace background image when user clicks on a thumbnail
$projectImages.live( 'click', function(e) {
e.preventDefault();
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
tjFogarty / page.js
Created December 8, 2012 18:47
Do things with the page name
var Page = {
getPageName: function() {
var pageName = document.URL.split( '/' ).pop();
if( !pageName ) {
pageName = $( 'ul.menu li:first-child a' ).attr( 'href' );
}
return pageName;
@tjFogarty
tjFogarty / vimeo-tracking.js
Last active December 13, 2015 23:19
Vimeo tracking object, assuming you're using https://github.com/vimeo/player-api/tree/master/javascript
//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', Vimeo.events.onPlay );
},
//when the play button is clicked
@tjFogarty
tjFogarty / notifications-demo.html
Last active December 14, 2015 10:10
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.
<a href="#" class='notify'>Success!</a>
<a href="#" class='notify error'>Error :(</a>
@tjFogarty
tjFogarty / slider-demo.html
Last active December 14, 2015 18:19
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.
<div class="container">
<div id="slider-container">
<ul class="slider-images clearfix">
<li><img class="scale" src="http://dummyimage.com/500x200/000/fff.gif&text=Slide+1" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/fff/000.gif&text=Slide+2" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/000/fff.gif&text=Slide+3" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/fff/000.gif&text=Slide+4" alt=""></li>
</ul>
</div>
@tjFogarty
tjFogarty / config.php
Created March 19, 2013 15:38
Quick and simple database connection
<?php
include('db.class.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
tjFogarty / youtube-event-tracking.js
Created April 30, 2013 14:38
Tracking for any number of YouTube iframes. Uses a data-title attribute for grabbing a title.
// Any iframes with a class of .yt will be collected for event tracking
var Youtube = {
$players: $( '.yt' ),
playerArray: [],
numPlayers: $( '.yt' ).length - 1,
init: function() {
Youtube.assignID();
Youtube.bindEvents();
},
@tjFogarty
tjFogarty / mobile-nav.js
Created July 9, 2013 15:57
Build mobile navigation from existing list of links
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
MobileNav.buildNav();
@tjFogarty
tjFogarty / js-enabled.js
Created August 26, 2013 11:31
Assuming the HTML element has a class of 'no-js', this will swap it for 'js'. Should be placed in the header.
var el = document.getElementsByTagName('html')[0];
el.className = el.className.replace('no-js', 'js');