Skip to content

Instantly share code, notes, and snippets.

Andrew Collington amnuts

Block or report user

Report or block amnuts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@amnuts
amnuts / toner.js
Created Jan 12, 2016
jquery plugin for toning an image
View toner.js
/**
* Usage:
*
* <img src="pic.jpg" data-colour="blue" />
* <img src="pic.jpg" data-colour="green" data-contrast="40" />
* <img src="pic.jpg" data-colour="pink" data-brightness="30" />
* <img src="pic.jpg" data-colour="#ddc258" data-contrast="40" data-brightness="30" />
* <script>$(function(){ $(img['data-colour']).toner(); });</script>
*/
;(function ($, window, document, undefined) {
@amnuts
amnuts / char-word-count.js
Last active Sep 30, 2016
word/char count w/ jquery
View char-word-count.js
$(function(){
var txt = $('.content')[0].text(),
charCount = txt.length,
wordCount = txt.replace(/[^\w ]/g, "").split(/\s+/).length;
$('#somwhereInYourDocument').text("The text had " + charCount + " characters and " + wordCount +" words");
});
@amnuts
amnuts / aspect-ratio.php
Last active Sep 30, 2016
Aspect ratio from width/height
View aspect-ratio.php
<?php
function ratio($a, $b)
{
$gcd = function($a, $b) use (&$gcd) {
return ($a % $b) ? $gcd($b, $a % $b) : $b;
};
$g = $gcd($a, $b);
return $a/$g . ':' . $b/$g;
}
@amnuts
amnuts / phpstorm.bat
Last active Jul 19, 2019
Add context menu to Windows 7 to open file/folder in PhpStorm
View phpstorm.bat
@echo off
SET PhpStormPath=C:\Program Files (x86)\JetBrains\PhpStorm 8.0.2\bin\PhpStorm64.exe
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_SZ /v "" /d "Open in PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
echo Adding folder entries
@amnuts
amnuts / speechSynthesis.js
Created Nov 17, 2014
Add a link to read text aloud including the option of swapping to any available voices.
View speechSynthesis.js
if ('speechSynthesis' in window) {
$(function(){
var createdVoiceList = false;
$('#content').append(
$('<div/>', {'class':'speechUI'}).append('<a href="#" class="speakContent">read text aloud</a>&nbsp;')
);
var addVoices = function() {
var select = '';
@amnuts
amnuts / osort.php
Last active Jul 24, 2018
Sort array of objects by one or more properties of the object.
View osort.php
<?php
/**
* Sort an array of objects.
*
* Requires PHP 5.3+ to be installed.
*
* Will use the Intl extension to normalize characters if it's
* available.
*
@amnuts
amnuts / greeting.zep
Last active Jan 4, 2016
Zephir not incrementing correctly?
View greeting.zep
namespace Utils;
class Greeting
{
protected counter1 = 0;
protected counter2 = 0;
protected counter3 = 0;
protected revcounter1 = 5;
protected revcounter2 = 5;
protected revcounter3 = 5;
@amnuts
amnuts / example.py
Last active Dec 29, 2015
An example of making a motor spin (by ramping up and then down the speed) and sending a tweet when a button connected to the Raspberry Pi is pushed.
View example.py
import RPi.GPIO as GPIO
from time import sleep
import os
from twitter import *
from random import choice
from datetime import datetime
op1 = 11
op2 = 13
@amnuts
amnuts / merge_urls.php
Last active Dec 29, 2015
Merge two urls using PHP
View merge_urls.php
<?php
/**
* Combine two urls.
*
* The urls can be either a string or url parts that consist of:
*
* scheme, host, port, user, pass, path, query, fragment
*
* If passed in as parts in an array, the query parameter can be either
@amnuts
amnuts / scraping.php
Last active Dec 28, 2015
Example of how to scrape multiple pages using Zend\Dom from Zend Framework 2.
View scraping.php
<?php
use \Zend\Dom\Query;
use \Zend\Debug\Debug;
/**
* Fetch the page source and cache it, ensuring it's saved as UTF-8
*
* @param string $url
* @return string
You can’t perform that action at this time.