Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Collington amnuts

View GitHub Profile
@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 / 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 / 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 / merge_urls.php
Last active Dec 9, 2019
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 / 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 / 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 / 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 / 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 / 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;
}
You can’t perform that action at this time.