Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Collington amnuts

View GitHub Profile
@amnuts
amnuts / crossfade.js
Last active Dec 27, 2015
Quick and easy way to cross-fade between elements in a list. If those elements contained images then you have a very simple slideshow. (Requires jQuery.)
View crossfade.js
if ($('ul.crossfade').length) {
$('ul.crossfade').each(function(){
var ul = $(this);
if ($('li', ul).length > 1) {
$('li:gt(0)', ul).hide();
var fadeSpeed = (ul.attr('data-fadespeed') !== undefined ? ul.attr('data-fadespeed') : 1000);
var nextSpeed = (ul.attr('data-nextspeed') !== undefined ? ul.attr('data-nextspeed') : 5000);
setInterval(function(){
$('li:first', ul)
.fadeOut(fadeSpeed).next('li')
@amnuts
amnuts / jquery.sameheight.js
Created Nov 4, 2013
A jQuery plug-in to make elements the same height (by max height or min height)
View jquery.sameheight.js
/**
* Same Height, jQuery plug-in.
*
* This plug-in allows you to automatically have all of the elements marked
* with a particular class to be the same height, either by smallest or
* largest.
*
* By default, 'samemaxheight' and 'sameminheight' will be used.
*
* Examples of use:
@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
@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 / 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 / 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 / .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 / 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 / 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 / volume.py
Created Jan 11, 2017
Use a rotary controller to adjust volume on a Raspberry Pi
View volume.py
from RPi import GPIO
from time import sleep
import subprocess
clk = 5
dt = 6
btn = 26
# vals from output of amixer cget numid=1
min = 0
You can’t perform that action at this time.