Skip to content

Instantly share code, notes, and snippets.

View jordanterry's full-sized avatar

Jordan Terry jordanterry

View GitHub Profile
@jordanterry
jordanterry / gist:5107f1267d75b6f6c86e
Last active August 29, 2015 14:02
jQuery plugin format
// Protect the jQuery alias, $, from other Javascript libraries by extending it within a protected scope.
(function($) {
// Extend the jQuery library using the name of you plugin, in this case 'pluginName'
$.fn.pluginName = function(options) {
// Extend the options (a Javascript object) parameter with the default options declared further below
var $opts = $.extend({}, $.fn.pluginName.options, options);
// Public method (see below)
$.fn.pluginName.somePublicMethod();
@jordanterry
jordanterry / breakitright
Created July 12, 2014 09:15
Always break or return your case blocks.
switch(var) {
case 1:
doSomething();
break;
case 2:
doSomethingElse();
break;
default:
@jordanterry
jordanterry / gist:939b99e7ba1c0a5deb98
Created August 10, 2014 20:09
Turn off Mod Pagespeed
<IfModule pagespeed_module>
ModPagespeed off
</IfModule>
public class TapeEquilibrium {
public int solution(int[] A) {
/*
* Declare some initial variables
* min is the maximum value an Integer could possibly be. (each element of array A is an integer within the range [−1,000..1,000].)
* total will represent the total value of each element in A
* upto will be used to represent the left hand side of the Array
*/
int min = 9999,
total = 0,
public class TapeEquilibrium {
public int solution(int[] A) {
/*
* Declare some initial variables
* min is the maximum value an Integer could possibly be. (each element of array A is an integer within the range [−1,000..1,000].)
* total will represent the total value of each element in A
* upto will be used to represent the left hand side of the Array
*/
int min = 9999,
total = 0,
A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].
The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
In other words, it is the absolute difference between the sum of the first part and the sum of the second part.
For example, consider array A such that:
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
public class FrogJump {
public int solution(int Y, int X, int D) {
/*
* jump_distance is the value
* jumps the number of jumps can be calculated by dividing the jump distance by the number of jumps,
* this won't calculate the total number of jumps, this can be calculated by using modulus, if there is a
* remainder 1 is added to the total number of jumps.
*/
int jump_distance = (Y - X),
jumps = (jump_distance / D) + ((jump_distance % D > 0) ? 1 : 0);
A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.
Count the minimal number of jumps that the small frog must perform to reach its target.
Write a function:
class Solution { public int solution(int X, int Y, int D); }
that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.
For example, given:
X = 10
Y = 85
D = 30
the function should return 3, because the frog will be positioned as follows:
A zero-indexed array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.
Your goal is to find that missing element.
Write a function:
class Solution { public int solution(int[] A); }
that, given a zero-indexed array A, returns the value of the missing element.
For example, given array A such that:
A[0] = 2
A[1] = 3
A[2] = 1
A[3] = 5
import java.util.Arrays;
/**
* Created by jordanterry on 26/10/14.
*/
public class PermMissingElem {
public int Solution(int[] A) {
// If it is empty, return one, each permutation must start with 1
if(A.length == 0) return 1;