Skip to content

Instantly share code, notes, and snippets.

@jimjam88
jimjam88 / Decimal2Fraction.php
Last active December 23, 2015 00:09
Convert a decimal to a fraction.
/**
* Convert a decimal to a fraction.
*
* @param number $decimal
* @return string
*/
public static function decimal2fraction($decimal)
{
$decimalBase = --$decimal;
$denomenator = 1;
@jimjam88
jimjam88 / Fraction2Decimal.php
Last active December 23, 2015 00:09
Convert a fraction to a decimal.
/**
* Convert a fractinal price to a decimal price.
*
* @param string $fractional
* @return string
*/
public static function fractional2decimal($fractional)
{
list ($numerator, $denomenator) = explode('/', $fractional);
return number_format(($numerator / $denomenator) + 1, 2, '.', '');
@jimjam88
jimjam88 / MaximiseWindow.php
Last active December 23, 2015 06:49
Maximize the window in Mink/WebDriver
$wd = $this->getSession()->getDriver()->getWebDriverSession();
$wd->window($wd->window_handle())->maximize();
@jimjam88
jimjam88 / Regex.php
Last active December 24, 2015 11:39
<?php
/**
* Regex.php
*
* Simple mapping class for frequently used regular expressions.
*
* @author James Morgan <[email protected]>
*/
final class Regex
@jimjam88
jimjam88 / Preferences.sublime-settings
Last active December 28, 2015 05:59
My Sublime Text 3 Preferences Overrides
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_style": "phase",
"font_size": 12,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages": [],
"margin": 0,
"rulers":
@jimjam88
jimjam88 / jenkins.conf
Created November 19, 2013 09:27
Apache virtual host for Jenkins
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName jenkins.localhost
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
@jimjam88
jimjam88 / .profile
Last active December 28, 2015 18:49
Bash profile
# IP alias
alias ip="ifconfig | grep 'inet addr:172' | awk {'print \$2'} | awk -F':' {'print \$2'}"
# Command prompt
source ~/.git-prompt.sh
export PS1='\[\033[01;35m\]$(date +%k:%M:%S)\[\033[00m\] \[\033[01;36m\]$(whoami)\[\033[00m\]\[\033[01;31m\]@\[\033[00m\]\[\033[01;33m\]$(hostname)\[\033[00m\] \[\033[01;32m\]\w\[\033[01;31m\]$(__git_ps1)\[\033[00m\] → '
# Directory size
alias dirsize="du -h | tail -1 | awk '{print \$1}'"
@jimjam88
jimjam88 / sublime-packages.list
Last active January 3, 2016 23:39
Sublime Text Packages
AlignTab.sublime-package
AmpScript Highlighter.sublime-package
Apache Hive.sublime-package
Behat.sublime-package
BlameHighlighter.sublime-package
BracketHighlighter.sublime-package
Emmet.sublime-package
DocBlockr.sublime-package
GitGutter.sublime-package
Highlighter.sublime-package
@jimjam88
jimjam88 / .gitconfig
Last active January 3, 2016 23:48
Git config
[user]
name = James Morgan
email = [email protected]
[alias]
ci = commit
st = status -sb
co = checkout
di = diff
dis = diff --staged
@jimjam88
jimjam88 / ucfirst.java
Created January 22, 2014 14:23
Java mimic of PHP's ucfirst function
/**
* Mimics PHP's ucfirst function.
*
* @param subject The string to be ucfirst'd
* @return The subject string with an uppercased first character
*/
final public static String ucfirst(String subject)
{
return Character.toUpperCase(subject.charAt(0)) + subject.substring(1);
}