Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Collington amnuts

View GitHub Profile
@amnuts
amnuts / .bashrc
Last active Mar 17, 2016
Bash prompt stuff
View .bashrc
# change the colour of the base directory depending on whether
# I'm in the live/staging/dev areas. Also show the user and host
# as well as the bash history number of the command.
C_DEV="\[\033[0;32m\]" # green
C_STAGE="\[\033[0;33m\]" # yellow
C_LIVE="\[\033[1;31m\]" # bold red
C_PATH="\[\033[0;37m\]" # white
C_COUNT="\[\033[0;36m\]" # cyan
C_NONE="\[\033[0m\]" # reset
@amnuts
amnuts / phprc
Last active May 10, 2018
Dreamhost PHP 5.6 phprc file
View phprc
date.timezone = "Europe/London"
expose_php = 0
extension = phar.so
extension = fileinfo.so
extension = intl.so
suhosin.executor.include.whitelist = phar
[opcache]
zend_extension=opcache.so
@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 Aug 20, 2020
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.html
Last active Mar 13, 2020
Add a link to read text aloud including the option of swapping to any available voices.
View speechSynthesis.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script
src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
@amnuts
amnuts / osort.php
Last active Jun 8, 2020
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
You can’t perform that action at this time.